|
@@ -16,15 +16,14 @@ 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 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
|
|
_ = gettext.gettext
|
|
_ = gettext.gettext
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
class RapidAlternativesField(forms.Field):
|
|
class RapidAlternativesField(forms.Field):
|
|
"""
|
|
"""
|
|
Form field for AlternativeData.
|
|
Form field for AlternativeData.
|
|
@@ -131,12 +130,15 @@ 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:
|
|
if type(f.field) == models.DateField:
|
|
widgets.append((f.bare_name(), dtwidgets.DateWidget(usel10n = True, bootstrap_version=3)))
|
|
widgets.append((f.bare_name(), dtwidgets.DateWidget(usel10n = True, bootstrap_version=3)))
|
|
if type(f.field) == models.DateTimeField:
|
|
if type(f.field) == models.DateTimeField:
|
|
@@ -144,6 +146,8 @@ def for_model(request, model, default_relations=()):
|
|
if type(f.field) == models.TimeField:
|
|
if type(f.field) == models.TimeField:
|
|
widgets.append((f.bare_name(), dtwidgets.TimeWidget(usel10n = True, bootstrap_version=3)))
|
|
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)
|
|
@@ -192,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:
|