diff --git a/forms.py b/forms.py index 328b4f9..41c9c35 100644 --- a/forms.py +++ b/forms.py @@ -753,7 +753,18 @@ for section in self.layout: for option in section[1:]: self.fields[option].initial = settings[option] - + def truncate(self): + """ + truncates the form to have only those fields which are in self.layout + """ + #delete form.fields which are not in the layout + used_options=[] + for section in self.layout: + used_options += section[1:] + + for key in self.fields.keys(): + if not(key in used_options): + del self.fields[key] class Meta: """Class to handle the automatic insertion of fieldsets and divs. diff --git a/views.py b/views.py index 97d3081..b7f8d3e 100644 --- a/views.py +++ b/views.py @@ -321,14 +321,21 @@ #Save a Form Processed by POST if request.method == 'POST': form = ListSettings(request.POST,visible_section,visible_option) + form.truncate() if form.is_valid(): the_list.update_config(request.POST)#TODO message = _("The list has been updated.") else: + for key,item in form.fields.items(): + #raise Exception(item.value) + #item.validate(False)#debug + #item.run_validators() + #item.clean() + raise Exception(item._errors) message = _("Validation Error - The list has not been updated.") else:#Provide a form with existing values - #create form to get layout + #create form and process layout into form.layout form = ListSettings(None,visible_section,visible_option) #create a Dict of all settings which are used in the form used_settings={} @@ -337,6 +344,8 @@ used_settings[option] = the_list.settings[option] #recreate the form using the settings form = ListSettings(used_settings,visible_section,visible_option) + form.truncate() + return render_to_response(template, {'form': form, 'message': message,