diff --git a/forms.py b/forms.py index 41c9c35..cb410cf 100644 --- a/forms.py +++ b/forms.py @@ -732,7 +732,7 @@ label = _('Posting Address'), required = False, ) - def __init__(self,settings,visible_section,visible_option, *args, **kwargs): + def __init__(self,visible_section,visible_option, *args, **kwargs): super(ListSettings, self).__init__(*args, **kwargs) #if settings:raise Exception(settings) #debug if visible_option: @@ -749,10 +749,13 @@ for section in self.layout: if section[0] == visible_section: self.layout = [section] - if settings: - for section in self.layout: - for option in section[1:]: - self.fields[option].initial = settings[option] + try: + if data: + for section in self.layout: + for option in section[1:]: + self.fields[option].initial = settings[option] + except: + pass #empty form def truncate(self): """ truncates the form to have only those fields which are in self.layout diff --git a/views.py b/views.py index b7f8d3e..73619c4 100644 --- a/views.py +++ b/views.py @@ -320,30 +320,27 @@ return HttpResponse(e) #Save a Form Processed by POST if request.method == 'POST': - form = ListSettings(request.POST,visible_section,visible_option) + form = ListSettings(visible_section,visible_option,data=request.POST) form.truncate() if form.is_valid(): - the_list.update_config(request.POST)#TODO + settings = the_list.settings + for key in form.fields.keys(): + settings[key] = form.cleaned_data[key] + settings.save() 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 and process layout into form.layout - form = ListSettings(None,visible_section,visible_option) + form = ListSettings(visible_section,visible_option,data=None) #create a Dict of all settings which are used in the form used_settings={} for section in form.layout: for option in section[1:]: used_settings[option] = the_list.settings[option] #recreate the form using the settings - form = ListSettings(used_settings,visible_section,visible_option) + form = ListSettings(visible_section,visible_option,data=used_settings) form.truncate()