70 |
70 |
71 # Check if the Model property added help_text, and copy that verbatim |
71 # Check if the Model property added help_text, and copy that verbatim |
72 # to the corresponding field help_text. |
72 # to the corresponding field help_text. |
73 if hasattr(model_prop, 'help_text'): |
73 if hasattr(model_prop, 'help_text'): |
74 self.fields[field_name].help_text = model_prop.help_text |
74 self.fields[field_name].help_text = model_prop.help_text |
|
75 |
|
76 |
|
77 class BaseForm(DbModelForm): |
|
78 """Subclass of DbModelForm that extends as_table HTML output. |
|
79 |
|
80 BaseForm has additional class names in HTML tags for label and help text |
|
81 and those can be used in CSS files for look customization. The way the Form |
|
82 prints itself also has changed. Help text is displayed in the same row as |
|
83 label and input. |
|
84 """ |
|
85 # TODO(pawel.solyga): Add class names for form errors and required fields. |
|
86 |
|
87 DEF_NORMAL_ROW = u'<tr><td class="formfieldlabel">%(label)s</td>' \ |
|
88 '<td>%(errors)s%(field)s%(help_text)s</td></tr>' |
|
89 DEF_ERROR_ROW = u'<tr><td colspan="2">%s</td></tr>' |
|
90 DEF_ROW_ENDER = '</td></tr>' |
|
91 DEF_HELP_TEXT_HTML = u'<td class="formfieldhelptext">%s</td>' |
|
92 |
|
93 def __init__(self, *args, **kwargs): |
|
94 """Parent class initialization. |
|
95 |
|
96 Args: |
|
97 *args, **kwargs: passed through to parent __init__() constructor |
|
98 """ |
|
99 super(BaseForm, self).__init__(*args, **kwargs) |
|
100 |
|
101 def as_table(self): |
|
102 """Returns form rendered as HTML <tr> rows -- with no <table></table>.""" |
|
103 return self._html_output(self.DEF_NORMAL_ROW, |
|
104 self.DEF_ERROR_ROW, |
|
105 self.DEF_ROW_ENDER, |
|
106 self.DEF_HELP_TEXT_HTML, False) |
75 |
107 |
76 |
108 |
77 class SelectQueryArgForm(forms.Form): |
109 class SelectQueryArgForm(forms.Form): |
78 """URL query argument change control implemented as a Django form. |
110 """URL query argument change control implemented as a Django form. |
79 """ |
111 """ |