Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

code cleanup

  • Loading branch information...
commit c37676870755be0c028fd8b955d48c6859005b5f 1 parent aaea02c
Jason Kraus authored
30 dockit/admin/documentadmin.py
View
@@ -10,7 +10,7 @@
from dockit.paginator import Paginator
from dockit.forms import DocumentForm
-from dockit.forms.fields import PrimitiveListField, HiddenListField, HiddenJSONField
+from dockit.forms.fields import PrimitiveListField, HiddenJSONField
from dockit.models import DockitPermission
import views
@@ -237,8 +237,6 @@ def get_fieldsets(self, request, obj=None):
def formfield_for_field(self, prop, field, view, **kwargs):
from dockit import schema
- from fields import DotPathField
-
if isinstance(prop, schema.ModelReferenceField):
return self.formfield_for_foreignkey(prop, field, view, **kwargs)
if isinstance(prop, schema.ModelSetField):
@@ -271,20 +269,8 @@ def formfield_for_field(self, prop, field, view, **kwargs):
if view.next_dotpath():
kwargs['required'] = False
return field(**kwargs)
- if issubclass(field, HiddenListField):
- field = DotPathField
- kwargs['dotpath'] = view.dotpath()
- kwargs['params'] = request.GET.copy()
- if view.next_dotpath():
- kwargs['required'] = False
- return field(**kwargs)
- elif issubclass(field, HiddenJSONField):
- field = DotPathField
- kwargs['dotpath'] = view.dotpath()
- kwargs['params'] = request.GET.copy()
- if view.next_dotpath():
- kwargs['required'] = False
- return field(**kwargs)
+ if issubclass(field, HiddenJSONField):
+ return self.formfield_for_jsonfield(prop, field, view, request=request, **kwargs)
if issubclass(field, PrimitiveListField) and 'subfield' in kwargs:
subfield_kwargs = prop.subfield.formfield_kwargs()
subfield_kwargs.pop('initial', None)
@@ -297,6 +283,16 @@ def formfield_for_field(self, prop, field, view, **kwargs):
kwargs = dict(opts, **kwargs)
return field(**kwargs)
+ def formfield_for_jsonfield(self, prop, field, view, **kwargs):
+ request = kwargs.pop('request', None)
+ from fields import DotPathField
+ field = DotPathField
+ kwargs['dotpath'] = view.dotpath()
+ kwargs['params'] = request.GET.copy()
+ if view.next_dotpath():
+ kwargs['required'] = False
+ return field(**kwargs)
+
def formfield_for_foreignkey(self, prop, field, view, **kwargs):
"""
Get a form Field for a ForeignKey.
10 dockit/admin/inlines.py
View
@@ -87,6 +87,16 @@ def get_formset(self, request, view, obj=None, **kwargs):
def get_excludes(self):
return list(self.exclude)
+
+ def formfield_for_jsonfield(self, prop, field, view, **kwargs):
+ request = kwargs.pop('request', None)
+ from fields import DotPathField
+ field = DotPathField
+ kwargs['dotpath'] = self.dotpath
+ kwargs['params'] = request.GET.copy()
+ if view.next_dotpath(): #???
+ kwargs['required'] = False
+ return field(**kwargs)
class StackedInline(InlineSchemaAdmin):
template = 'admin/edit_inline/stacked.html'
5 dockit/tests/admin/documentadmin.py
View
@@ -49,6 +49,7 @@ def test_inline_form_field_for_field_with_complex_list_field(self):
kwargs['request'] = request
view = MockView(request)
admin_field = inline_admin.formfield_for_field(prop, field, view, **kwargs)
+ assert admin_field.dotpath, str(admin_field.dotpath)
field_html = admin_field.widget.render('complex_list', [])
self.assertTrue('value="add"' in field_html)
@@ -65,5 +66,7 @@ def test_inline_get_formset(self):
assert form._meta.formfield_callback
html.append(form.as_table())
html = '\n'.join(html)
- self.assertTrue('value="add"' in html)
+ self.assertTrue('value="add"' in html, html)
+ #TODO inlines muck this up, we need a UX review
+ #self.assertTrue('complex_list.*.gallery.0' in html, html)
Please sign in to comment.
Something went wrong with that request. Please try again.