Ejemplo n.º 1
0
 def layout_view(self, request):
     layout_id = request.POST['layout_id']
     layout = get_object_or_404(Layout, pk=layout_id)
     inits = {}
     if request.POST.get('page_id'):
         try:
             page = Page.objects.get(pk=request.POST['page_id'])
             for field in page.xfields():
                 for name, value in model_to_dict(field, exclude=('input','page')).iteritems():
                     inits['%s-%s' %(make_safe_input_name(field.input.name), name)] = value
         except (Page.DoesNotExist, Layout.DoesNotExist):
             pass
     ModelForm = self.get_form(request)
     inputs = []
     for input in layout.inputs.all():
         fields = []
         prefix = make_safe_input_name(input.name)
         data = get_data_with_prefix(inits, prefix)
         form = ModelForm(initial=data, prefix=prefix)
         for field in input.field_model._meta.fields:
             if field.editable:
                 formfield = self.formfield_for_dbfield(field, request=request)
                 if formfield is not None:
                     fields.append(BoundField(form, formfield, field.name))
         inputs.append(InputFieldset(input, fields))
     return render_to_response('admin/editsite/page/layout_inputs.html', {'inputs': inputs, 'layout': layout})
Ejemplo n.º 2
0
 def clean(self):
     self.cleaned_data = ModelForm.clean(self)
     self.instance.clear_fields()
     for input in self.cleaned_data['layout'].inputs.all():
         all_data = self.data.copy()
         all_data.update(self.files)
         data = get_data_with_prefix(all_data, make_safe_input_name(input.name))
         field = input.field_model(input=input, **data)
         # field.page = self.instance
         try:
             field.full_clean()
         except ValidationError, e:
             # we should handle this
             raise e
         #field.save()
         self.layout_fields.setdefault('%s_%s' %(input.field_model._meta.app_label, input.field_model.__name__.lower()),[]).append(field)