From 9b70aad32235645cb0801786ef581a6452272ba7 Mon Sep 17 00:00:00 2001 From: Pawel Solyga Date: Sun, 19 Oct 2008 21:12:08 +0000 Subject: [PATCH] Add BaseForm class to soc.views.helper.forms module (work in progress). This changes the way as_table function displays the form (for more information have a look into doc string). BaseForm is going to be used for all forms in Melange in future. Right now it's still missing custom form errors labels and "required" text in 3rd column, but that's added as TODO and I'm working on it. Patch by: Pawel Solyga Review by: to-be-reviewed --- app/soc/views/helper/forms.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/app/soc/views/helper/forms.py b/app/soc/views/helper/forms.py index 96925e55..fa14dfd0 100644 --- a/app/soc/views/helper/forms.py +++ b/app/soc/views/helper/forms.py @@ -74,6 +74,38 @@ class DbModelForm(djangoforms.ModelForm): self.fields[field_name].help_text = model_prop.help_text +class BaseForm(DbModelForm): + """Subclass of DbModelForm that extends as_table HTML output. + + BaseForm has additional class names in HTML tags for label and help text + and those can be used in CSS files for look customization. The way the Form + prints itself also has changed. Help text is displayed in the same row as + label and input. + """ + # TODO(pawel.solyga): Add class names for form errors and required fields. + + DEF_NORMAL_ROW = u'%(label)s' \ + '%(errors)s%(field)s%(help_text)s' + DEF_ERROR_ROW = u'%s' + DEF_ROW_ENDER = '' + DEF_HELP_TEXT_HTML = u'%s' + + def __init__(self, *args, **kwargs): + """Parent class initialization. + + Args: + *args, **kwargs: passed through to parent __init__() constructor + """ + super(BaseForm, self).__init__(*args, **kwargs) + + def as_table(self): + """Returns form rendered as HTML rows -- with no
.""" + return self._html_output(self.DEF_NORMAL_ROW, + self.DEF_ERROR_ROW, + self.DEF_ROW_ENDER, + self.DEF_HELP_TEXT_HTML, False) + + class SelectQueryArgForm(forms.Form): """URL query argument change control implemented as a Django form. """ -- 2.11.4.GIT