2014-05-08 16:59:35 +00:00
|
|
|
from django import forms
|
|
|
|
|
2015-04-26 13:53:00 +00:00
|
|
|
from .widgets import SpanWidget
|
|
|
|
|
2014-05-08 16:59:35 +00:00
|
|
|
|
|
|
|
class MultiSelectFormField(forms.MultipleChoiceField):
|
|
|
|
""" http://djangosnippets.org/snippets/1200/ """
|
|
|
|
widget = forms.CheckboxSelectMultiple
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
self.max_choices = kwargs.pop('max_choices', 0)
|
|
|
|
super(MultiSelectFormField, self).__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
def clean(self, value):
|
|
|
|
if not value and self.required:
|
|
|
|
raise forms.ValidationError(self.error_messages['required'])
|
|
|
|
return value
|
2015-04-26 13:53:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SpanField(forms.Field):
|
|
|
|
"""
|
|
|
|
A field which renders a value wrapped in a <span> tag.
|
|
|
|
|
|
|
|
Requires use of specific form support. (see ReadonlyForm or ReadonlyModelForm)
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
kwargs['widget'] = kwargs.get('widget', SpanWidget)
|
|
|
|
super(SpanField, self).__init__(*args, **kwargs)
|