diff -r 44223e50e1fc -r f3525c1288ed app/soc/views/settings.py --- a/app/soc/views/settings.py Wed Oct 22 06:20:02 2008 +0000 +++ b/app/soc/views/settings.py Wed Oct 22 16:21:50 2008 +0000 @@ -48,19 +48,12 @@ import soc.views.out_of_band -class SettingsForm(helper.forms.DbModelForm): +class SettingsValidationForm(helper.forms.DbModelForm): """Django form displayed when creating or editing Settings. + + This form includes validation functions for Settings fields. """ - class Meta: - """Inner Meta class that defines some behavior for the form. - """ - #: db.Model subclass for which the form will gather information - model = soc.models.home_settings.HomeSettings - - #: list of model fields which will *not* be gathered by the form - exclude = ['inheritance_line', 'home'] - def clean_feed_url(self): feed_url = self.cleaned_data.get('feed_url') @@ -74,6 +67,20 @@ return feed_url +class SettingsForm(SettingsValidationForm): + """Django form displayed when creating or editing Settings. + """ + + class Meta: + """Inner Meta class that defines some behavior for the form. + """ + #: db.Model subclass for which the form will gather information + model = soc.models.home_settings.HomeSettings + + #: list of model fields which will *not* be gathered by the form + exclude = ['inheritance_line', 'home'] + + class DocSelectForm(helper.forms.DbModelForm): """Django form displayed to select a Document. """ @@ -99,6 +106,7 @@ @decorators.view def edit(request, page=None, path=None, logic=models.home_settings.logic, + settings_form_class=SettingsForm, template=DEF_HOME_EDIT_TMPL): """View for authorized User to edit contents of a home page. @@ -106,6 +114,9 @@ request: the standard django request object. page: a soc.logic.site.page.Page object which is abstraction that combines a Django view with sidebar menu info + path: path that is used to uniquely identify settings + logic: settings logic object + settings_form_class: template: the template path to use for rendering the template. Returns: @@ -128,11 +139,17 @@ home_doc = None if request.method == 'POST': - settings_form = SettingsForm(request.POST) + settings_form = settings_form_class(request.POST) doc_select_form = DocSelectForm(request.POST) if doc_select_form.is_valid() and settings_form.is_valid(): - fields = {'feed_url': settings_form.cleaned_data.get('feed_url')} + fields = {} + + # Ask for all the fields and pull them out + for field in settings_form.cleaned_data: + value = settings_form.cleaned_data.get(field) + fields[field] = value + partial_path = doc_select_form.cleaned_data.get('partial_path') link_name = doc_select_form.cleaned_data.get('link_name') @@ -157,7 +174,7 @@ if settings: # populate form with the existing HomeSettings entity - settings_form = SettingsForm(instance=settings) + settings_form = settings_form_class(instance=settings) # check if ReferenceProperty to home Document is valid try: @@ -173,7 +190,7 @@ doc_select_form = DocSelectForm() else: # no SiteSettings entity exists for this key_name, so show a blank form - settings_form = SettingsForm() + settings_form = settings_form_class() doc_select_form = DocSelectForm() context.update({'settings_form': settings_form,