|
@@ -8,10 +8,13 @@ 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, RapidRelationReadOnly, rapid_alternatives_widget, rapid_dependent_widget
|
|
from rapid.wrappers import FieldData, ModelData
|
|
from rapid.wrappers import FieldData, ModelData
|
|
@@ -20,6 +23,8 @@ import gettext
|
|
_ = gettext.gettext
|
|
_ = gettext.gettext
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
class RapidAlternativesField(forms.Field):
|
|
class RapidAlternativesField(forms.Field):
|
|
"""
|
|
"""
|
|
Form field for AlternativeData.
|
|
Form field for AlternativeData.
|
|
@@ -114,6 +119,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 = []
|
|
@@ -130,6 +137,13 @@ def for_model(request, model, default_relations=()):
|
|
if f.is_relation() and force_text(f.bare_name()) not in default_relations_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.related_model().has_permission(request, 'select'):
|
|
widgets.append((f.bare_name(), RapidSelector(f)))
|
|
widgets.append((f.bare_name(), RapidSelector(f)))
|
|
|
|
+ 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)))
|
|
|
|
+
|
|
# 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)
|