Skip to content
This repository
Browse code

code cleanup

  • Loading branch information...
commit c37676870755be0c028fd8b955d48c6859005b5f 1 parent aaea02c
Jason Kraus authored July 03, 2012
30  dockit/admin/documentadmin.py
@@ -10,7 +10,7 @@
10 10
 
11 11
 from dockit.paginator import Paginator
12 12
 from dockit.forms import DocumentForm
13  
-from dockit.forms.fields import PrimitiveListField, HiddenListField, HiddenJSONField
  13
+from dockit.forms.fields import PrimitiveListField, HiddenJSONField
14 14
 from dockit.models import DockitPermission
15 15
 
16 16
 import views
@@ -237,8 +237,6 @@ def get_fieldsets(self, request, obj=None):
237 237
     
238 238
     def formfield_for_field(self, prop, field, view, **kwargs):
239 239
         from dockit import schema
240  
-        from fields import DotPathField
241  
-        
242 240
         if isinstance(prop, schema.ModelReferenceField):
243 241
             return self.formfield_for_foreignkey(prop, field, view, **kwargs)
244 242
         if isinstance(prop, schema.ModelSetField):
@@ -271,20 +269,8 @@ def formfield_for_field(self, prop, field, view, **kwargs):
271 269
             if view.next_dotpath():
272 270
                 kwargs['required'] = False
273 271
             return field(**kwargs)
274  
-        if issubclass(field, HiddenListField):
275  
-            field = DotPathField
276  
-            kwargs['dotpath'] = view.dotpath()
277  
-            kwargs['params'] = request.GET.copy()
278  
-            if view.next_dotpath():
279  
-                kwargs['required'] = False
280  
-            return field(**kwargs)
281  
-        elif issubclass(field, HiddenJSONField):
282  
-            field = DotPathField
283  
-            kwargs['dotpath'] = view.dotpath()
284  
-            kwargs['params'] = request.GET.copy()
285  
-            if view.next_dotpath():
286  
-                kwargs['required'] = False
287  
-            return field(**kwargs)
  272
+        if issubclass(field, HiddenJSONField):
  273
+            return self.formfield_for_jsonfield(prop, field, view, request=request, **kwargs)
288 274
         if issubclass(field, PrimitiveListField) and 'subfield' in kwargs:
289 275
             subfield_kwargs = prop.subfield.formfield_kwargs()
290 276
             subfield_kwargs.pop('initial', None)
@@ -297,6 +283,16 @@ def formfield_for_field(self, prop, field, view, **kwargs):
297 283
             kwargs = dict(opts, **kwargs)
298 284
         return field(**kwargs)
299 285
     
  286
+    def formfield_for_jsonfield(self, prop, field, view, **kwargs):
  287
+        request = kwargs.pop('request', None)
  288
+        from fields import DotPathField
  289
+        field = DotPathField
  290
+        kwargs['dotpath'] = view.dotpath()
  291
+        kwargs['params'] = request.GET.copy()
  292
+        if view.next_dotpath():
  293
+            kwargs['required'] = False
  294
+        return field(**kwargs)
  295
+    
300 296
     def formfield_for_foreignkey(self, prop, field, view, **kwargs):
301 297
         """
302 298
         Get a form Field for a ForeignKey.
10  dockit/admin/inlines.py
@@ -87,6 +87,16 @@ def get_formset(self, request, view, obj=None, **kwargs):
87 87
     
88 88
     def get_excludes(self):
89 89
         return list(self.exclude)
  90
+    
  91
+    def formfield_for_jsonfield(self, prop, field, view, **kwargs):
  92
+        request = kwargs.pop('request', None)
  93
+        from fields import DotPathField
  94
+        field = DotPathField
  95
+        kwargs['dotpath'] = self.dotpath
  96
+        kwargs['params'] = request.GET.copy()
  97
+        if view.next_dotpath(): #???
  98
+            kwargs['required'] = False
  99
+        return field(**kwargs)
90 100
 
91 101
 class StackedInline(InlineSchemaAdmin):
92 102
     template = 'admin/edit_inline/stacked.html'
5  dockit/tests/admin/documentadmin.py
@@ -49,6 +49,7 @@ def test_inline_form_field_for_field_with_complex_list_field(self):
49 49
         kwargs['request'] = request
50 50
         view = MockView(request)
51 51
         admin_field = inline_admin.formfield_for_field(prop, field, view, **kwargs)
  52
+        assert admin_field.dotpath, str(admin_field.dotpath)
52 53
         field_html = admin_field.widget.render('complex_list', [])
53 54
         self.assertTrue('value="add"' in field_html)
54 55
         
@@ -65,5 +66,7 @@ def test_inline_get_formset(self):
65 66
             assert form._meta.formfield_callback
66 67
             html.append(form.as_table())
67 68
         html = '\n'.join(html)
68  
-        self.assertTrue('value="add"' in html)
  69
+        self.assertTrue('value="add"' in html, html)
  70
+        #TODO inlines muck this up, we need a UX review
  71
+        #self.assertTrue('complex_list.*.gallery.0' in html, html)
69 72
 

0 notes on commit c376768

Please sign in to comment.
Something went wrong with that request. Please try again.