Added a new famfam graphics radioselect widget and applied it to the webform and stagingform edit and create forms
This commit is contained in:
@@ -5,6 +5,7 @@ from django.utils.translation import ugettext
|
||||
from documents.forms import DocumentForm
|
||||
|
||||
from sources.models import WebForm, StagingFolder
|
||||
from sources.widgets import FamFamRadioSelect
|
||||
|
||||
|
||||
class StagingDocumentForm(DocumentForm):
|
||||
@@ -53,10 +54,24 @@ class WebFormForm(DocumentForm):
|
||||
|
||||
|
||||
class WebFormSetupForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(WebFormSetupForm, self).__init__(*args, **kwargs)
|
||||
self.fields['icon'].widget = FamFamRadioSelect(
|
||||
attrs=self.fields['icon'].widget.attrs,
|
||||
choices=self.fields['icon'].widget.choices,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = WebForm
|
||||
|
||||
|
||||
class StagingFolderSetupForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(StagingFolderSetupForm, self).__init__(*args, **kwargs)
|
||||
self.fields['icon'].widget = FamFamRadioSelect(
|
||||
attrs=self.fields['icon'].widget.attrs,
|
||||
choices=self.fields['icon'].widget.choices,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = StagingFolder
|
||||
|
||||
22
apps/sources/widgets.py
Normal file
22
apps/sources/widgets.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from django import forms
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.encoding import force_unicode
|
||||
|
||||
|
||||
class FamFamRadioFieldRenderer(forms.widgets.RadioFieldRenderer):
|
||||
def render(self):
|
||||
results = []
|
||||
results.append(u'<ul>\n')
|
||||
for w in self:
|
||||
if w.choice_value:
|
||||
famfam_template = u'<span class="famfam active famfam-%s" style="vertical-align: bottom;"></span>' % w.choice_value
|
||||
else:
|
||||
famfam_template = u'<span class="famfam active famfam-cross" style="vertical-align: bottom;"></span>'
|
||||
results.append(u'<li class="undecorated_list">%s%s</li>' % (famfam_template, force_unicode(w)))
|
||||
|
||||
results.append(u'\n</ul>')
|
||||
return mark_safe(u'\n'.join(results))
|
||||
|
||||
|
||||
class FamFamRadioSelect(forms.widgets.RadioSelect):
|
||||
renderer = FamFamRadioFieldRenderer
|
||||
Reference in New Issue
Block a user