Changeset 2505
- Timestamp:
- 01/27/10 16:36:36 (7 weeks ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
branches/0.9/pylucid_project/pylucid_plugins/internals/admin_views.py
r2400 r2505 121 121 #----------------------------------------------------------------------------- 122 122 123 def textform_for_model(model):123 def _textform_for_model(model, request, debug=False): 124 124 """ 125 125 based on http://www.djangosnippets.org/snippets/458/ 126 126 """ 127 defaults = {"required": True, "initial": None, "min_length": None} 128 127 129 opts = model._meta 128 130 field_list = [] … … 133 135 if formfield: 134 136 kw = [] 135 for a in ('queryset', 'maxlength', 'label', 'initial', 'help_text', 'required'): 137 if debug: 138 request.page_msg(dir(formfield)) 139 for a in ('queryset', 'max_length', 'min_length', 'label', 'initial', 'help_text', 'required'): 136 140 if hasattr(formfield, a): 137 141 attr = getattr(formfield, a) 142 143 if a in defaults and attr == defaults[a]: 144 # Don't add default key/value combinations into form 145 continue 146 138 147 if a in ("label", "help_text"): # "translate" lazy text 139 148 attr = unicode(attr) 140 149 141 if attr in [True, False, None]: 142 if a == 'required' and attr == True: # Don't add default 143 continue 144 if a == 'initial' and attr == None: # Don't add default 145 continue 150 if a == 'queryset': 151 kw.append("%s=%s" % (a, "%s.objects.all()" % attr.model.__name__)) 152 elif attr in [True, False, None]: 146 153 kw.append("%s=%s" % (a, attr)) 147 elif a == 'queryset':148 kw.append("%s=%s" % (a, "%s.objects.all()" % attr.model.__name__))149 154 elif attr: 150 155 kw.append("%s=_('%s')" % (a, attr)) … … 169 174 if model_no: 170 175 model = models_dict[int(model_no)] 171 sourcecode = textform_for_model(model)176 sourcecode = _textform_for_model(model, request, debug=True) 172 177 173 178 output = hightlighter.make_html(sourcecode, source_type="py")