Changeset 2054
- Timestamp:
- 06/19/09 20:28:21 (9 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
branches/0.9/pylucid_project/apps/pylucid/fields.py
r2052 r2054 46 46 raise exceptions.ValidationError(_("Error: %r is not a CSS hex color value") % value) 47 47 48 class ColorInputWidget(forms.TextInput): 49 """ 50 Add background-color into input tag 51 TODO: Change text color, if background is to dark ;) 52 TODO2: Use jQuery to change the <td> background color ;) 53 """ 54 def render(self, name, value, attrs=None): 55 if not attrs: 56 attrs = {} 57 attrs["style"] = "background-color:#%s;" % value 58 return super(ColorInputWidget, self).render(name, value, attrs) 59 48 60 49 61 class ColorFormField(forms.CharField): 50 62 """ form field for a CSS color value """ 51 # widget = DictFormWidget63 widget = ColorInputWidget 52 64 def clean(self, value): 53 65 """ validate the form data """ 54 66 value = super(ColorFormField, self).clean(value) 55 67 validate_css_color_value(value) 68 self.value = value 56 69 return value 57 70 … … 76 89 # Always use own form field and widget: 77 90 kwargs['form_class'] = ColorFormField 91 kwargs['widget'] = ColorInputWidget 78 92 return super(ColorField, self).formfield(**kwargs) 79 93