|
@@ -8,12 +8,16 @@ from __future__ import unicode_literals
|
|
import collections
|
|
import collections
|
|
|
|
|
|
from django import forms
|
|
from django import forms
|
|
|
|
+from django.db import models
|
|
|
|
+from django.conf import settings
|
|
from django.contrib.contenttypes.models import ContentType
|
|
from django.contrib.contenttypes.models import ContentType
|
|
from django.core.exceptions import ValidationError
|
|
from django.core.exceptions import ValidationError
|
|
from django.db import transaction
|
|
from django.db import transaction
|
|
from django.utils.encoding import force_text
|
|
from django.utils.encoding import force_text
|
|
|
|
+from datetimewidget import widgets as dtwidgets
|
|
|
|
|
|
-from rapid.widgets import RapidSelector, RapidRelationReadOnly, rapid_alternatives_widget, rapid_dependent_widget
|
|
|
|
|
|
+from rapid.widgets import RapidSelector, rapid_alternatives_widget, rapid_dependent_widget, \
|
|
|
|
+ getRapidReadonlyRelation
|
|
from rapid.wrappers import FieldData, ModelData
|
|
from rapid.wrappers import FieldData, ModelData
|
|
|
|
|
|
import gettext
|
|
import gettext
|
|
@@ -114,6 +118,8 @@ class RapidDependentField(forms.Field):
|
|
|
|
|
|
|
|
|
|
def for_model(request, model, default_relations=()):
|
|
def for_model(request, model, default_relations=()):
|
|
|
|
+ hasDtWidgets = 'datetimewidget' in settings.INSTALLED_APPS
|
|
|
|
+
|
|
default_relations = list(default_relations)
|
|
default_relations = list(default_relations)
|
|
default_relations_request = request.GET.get('default')
|
|
default_relations_request = request.GET.get('default')
|
|
widgets = []
|
|
widgets = []
|
|
@@ -124,12 +130,24 @@ def for_model(request, model, default_relations=()):
|
|
default_relations_fields = [x for x, y in default_relations]
|
|
default_relations_fields = [x for x, y in default_relations]
|
|
for (x, y) in default_relations:
|
|
for (x, y) in default_relations:
|
|
f = FieldData(getattr(model, x).field, request)
|
|
f = FieldData(getattr(model, x).field, request)
|
|
- widgets.append((x, RapidRelationReadOnly(f.related_model().model)))
|
|
|
|
|
|
+ widgets.append((x, getRapidReadonlyRelation(f.related_model().model, y)))
|
|
default_relations_fields.append(x)
|
|
default_relations_fields.append(x)
|
|
for f in ModelData(model).local_fields():
|
|
for f in ModelData(model).local_fields():
|
|
- if f.is_relation() and force_text(f.bare_name()) not in default_relations_fields:
|
|
|
|
- if f.related_model().has_permission(request, 'select'):
|
|
|
|
|
|
+ if f.is_relation():
|
|
|
|
+ if force_text(f.bare_name()) not in default_relations_fields and \
|
|
|
|
+ f.related_model().has_permission(request, 'select'):
|
|
widgets.append((f.bare_name(), RapidSelector(f)))
|
|
widgets.append((f.bare_name(), RapidSelector(f)))
|
|
|
|
+ elif force_text(f.bare_name()) in default_relations_fields:
|
|
|
|
+ pass
|
|
|
|
+ if type(f.field) == models.DateField:
|
|
|
|
+ widgets.append((f.bare_name(), dtwidgets.DateWidget(usel10n = True, bootstrap_version=3)))
|
|
|
|
+ if type(f.field) == models.DateTimeField:
|
|
|
|
+ widgets.append((f.bare_name(), dtwidgets.DateTimeWidget(usel10n = True, bootstrap_version=3)))
|
|
|
|
+ if type(f.field) == models.TimeField:
|
|
|
|
+ widgets.append((f.bare_name(), dtwidgets.TimeWidget(usel10n = True, bootstrap_version=3)))
|
|
|
|
+
|
|
|
|
+ #if force_text(model._meta.db_table) == 'testproject_singledepontest1':
|
|
|
|
+ # import pdb; pdb.set_trace()
|
|
# ModelForm.Meta has attributes with the same names, thus I'll rename them
|
|
# ModelForm.Meta has attributes with the same names, thus I'll rename them
|
|
form_model = model
|
|
form_model = model
|
|
form_widgets = dict(widgets)
|
|
form_widgets = dict(widgets)
|
|
@@ -178,6 +196,7 @@ def for_model(request, model, default_relations=()):
|
|
|
|
|
|
@transaction.atomic
|
|
@transaction.atomic
|
|
def save(self, commit=True):
|
|
def save(self, commit=True):
|
|
|
|
+
|
|
if not commit:
|
|
if not commit:
|
|
return super(CForm, self).save(commit)
|
|
return super(CForm, self).save(commit)
|
|
else:
|
|
else:
|