class PublicBodyForm(forms.Form): name = forms.CharField(label=_("Name of Public Body")) description = forms.CharField(label=_("Short description"), widget=forms.Textarea, required=False) email = forms.EmailField( widget=forms.EmailInput, label=_("Email Address for Freedom of Information Requests")) url = forms.URLField(label=_("Homepage URL of Public Body"))
class AllFieldsForm(forms.Form): boolean = forms.BooleanField() char = forms.CharField(max_length=50) choices = forms.ChoiceField(choices=ALPHA_CHOICES) date = forms.DateField() datetime = forms.DateTimeField() decimal = forms.DecimalField(decimal_places=2, max_digits=4) email = forms.EmailField() file_field = forms.FileField() file_path = forms.FilePathField(path='uploads/') float_field = forms.FloatField() generic_ip_address = forms.GenericIPAddressField() image = forms.ImageField() integer = forms.IntegerField() ip_address = forms.IPAddressField() multiple_choices = forms.MultipleChoiceField(choices=ALPHA_CHOICES) null_boolean = forms.NullBooleanField() regex_field = forms.RegexField(regex='^\w+$', js_regex='^[a-zA-Z]+$') slug = forms.SlugField() split_datetime = forms.SplitDateTimeField() time = forms.TimeField() typed_choices = forms.TypedChoiceField(choices=NUMERIC_CHOICES, coerce=int) typed_multiple_choices = forms.TypedMultipleChoiceField( choices=NUMERIC_CHOICES, coerce=int) url = forms.URLField() # GIS fields. if gis_forms: osm_point = gis.PointField( widget=mixin(gis.PointWidget, gis.BaseOsmWidget)) osm_multipoint = gis.MultiPointField( widget=mixin(gis.MultiPointWidget, gis.BaseOsmWidget)) osm_linestring = gis.LineStringField( widget=mixin(gis.LineStringWidget, gis.BaseOsmWidget)) osm_multilinestring = gis.MultiLineStringField( widget=mixin(gis.MultiLineStringWidget, gis.BaseOsmWidget)) osm_polygon = gis.PolygonField( widget=mixin(gis.PolygonWidget, gis.BaseOsmWidget)) osm_multipolygon = gis.MultiPolygonField( widget=mixin(gis.MultiPolygonWidget, gis.BaseOsmWidget)) gmap_point = gis.PointField( widget=mixin(gis.PointWidget, BaseGMapWidget)) gmap_multipoint = gis.MultiPointField( widget=mixin(gis.MultiPointWidget, BaseGMapWidget)) gmap_linestring = gis.LineStringField( widget=mixin(gis.LineStringWidget, BaseGMapWidget)) gmap_multilinestring = gis.MultiLineStringField( widget=mixin(gis.MultiLineStringWidget, BaseGMapWidget)) gmap_polygon = gis.PolygonField( widget=mixin(gis.PolygonWidget, BaseGMapWidget)) gmap_multipolygon = gis.MultiPolygonField( widget=mixin(gis.MultiPolygonWidget, BaseGMapWidget))
class NewDiscussionForm(forms.Form): title = forms.CharField(label=_("title"), max_length=200, widget=forms.Textarea(attrs={ 'rows': '1', 'cols': '100' })) description = forms.CharField(label=_("description"), max_length=MAX_MESSAGE_INPUT_CHARS, widget=forms.Textarea(attrs={ 'rows': '6', 'cols': '100' })) location_desc = forms.CharField(label=u'כתובת', required=False, max_length=MAX_MESSAGE_INPUT_CHARS, widget=forms.Textarea(attrs={ 'rows': '1', 'cols': '100' })) tags = forms.CharField(required=False, label=u'תגיות מופרדות בפסיקים', widget=TagWidgetBig(attrs={ 'rows': 3, 'cols': 40 })) # parent_url = forms.URLInput(label=u"דף קשור", max_length=200, # widget=forms.Textarea( # attrs={'rows': '1', 'cols': '100'})) parent_url = forms.URLField( label=u'קישור לדף רלוונטי. לדוגמה http://hp.com', required=False, max_length=MAX_TEXT) parent_url_text = forms.CharField(label=u"שם הדף הקשור", required=False, max_length=MAX_TEXT, widget=forms.Textarea(attrs={ 'rows': '1', 'cols': '100' })) picture = forms.ImageField(required=False)
class SubscriptionForm(forms.Form): subscribe = forms.BooleanField(label=_('Subscribe?'), required=False) name = forms.CharField(label=_('Name'), required=False) url = forms.URLField(label=_('URL')) category = forms.ChoiceField(label=_('Category'), required=False) def clean_url(self): url = self.cleaned_data['url'] if (self.cleaned_data.get('subscribe', False) and self.user.feeds.filter(url=url).exists()): raise forms.ValidationError( _("You are already subscribed to this feed.")) return url def clean_name(self): if (self.cleaned_data.get('subscribe', False) and not self.cleaned_data['name']): raise forms.ValidationError(_('This field is required.')) return self.cleaned_data['name']
class URLForm(forms.Form): url = forms.URLField()
class RedirectForm(Form, CleanAttrsMixin): parent = False perms = False name = forms.CharField( max_length=255, validators=[ validate_sluggable( _("Redirect name must contain alphanumeric characters."), _("Redirect name is too long.")) ]) description = forms.CharField(widget=forms.Textarea, required=False) redirect = forms.URLField(max_length=255) style = forms.CharField(max_length=255, required=False) layout = ( ( _("Basic Options"), ( ('parent', { 'label': _("Redirect Parent") }), ('perms', { 'label': _("Copy Permissions from") }), ('name', { 'label': _("Redirect Name") }), ('redirect', { 'label': _("Redirect URL") }), ('description', { 'label': _("Redirect Description") }), ), ), ( _("Display Options"), ( ('attrs', { 'label': _("Forum Attributes"), 'help_text': _('Custom templates can check forums for predefined attributes that will change way subforums lists are rendered.' ) }), ('style', { 'label': _("Redirect Style"), 'help_text': _('You can add custom CSS classess to this redirect to change way it looks on forums lists.' ) }), ), ), ) def finalize_form(self): self.add_field( 'perms', TreeNodeChoiceField( label=_("Copy Permissions from"), widget=forms.Select, queryset=Forum.objects.get(special='root').get_descendants(), level_indicator=u'- - ', required=False, empty_label=_("Don't copy permissions")))
class NewNodeForm(Form, CleanAttrsMixin): parent = False perms = False role = forms.ChoiceField( label=_("Node Type"), help_text= _("Each Node has specific role in forums tree. This role cannot be changed after node is created." ), choices=( ('category', _("Category")), ('forum', _("Forum")), ('redirect', _("Redirection")), )) name = forms.CharField( label=_("Node Name"), max_length=255, validators=[ validate_sluggable( _("Category name must contain alphanumeric characters."), _("Category name is too long.")) ]) redirect = forms.URLField( label=_("Redirect URL"), help_text= _("Redirection nodes require you to specify URL they will redirect users to upon click." ), max_length=255, required=False) description = forms.CharField(label=_("Node Description"), widget=forms.Textarea, required=False) closed = forms.BooleanField(label=_("Closed Node"), widget=YesNoSwitch, required=False) attrs = forms.CharField( label=_("Node Style"), help_text= _('You can add custom CSS classess to this node, to change way it looks on board index.' ), max_length=255, required=False) show_details = forms.BooleanField( label=_("Node Style"), help_text= _('You can add custom CSS classess to this node, to change way it looks on board index.' ), widget=YesNoSwitch, required=False, initial=True) style = forms.CharField( label=_("Node Style"), help_text= _('You can add custom CSS classess to this node, to change way it looks on board index.' ), max_length=255, required=False) layout = ( ( _("Basic Options"), ( ('parent', { 'label': _("Node Parent") }), ('perms', { 'label': _("Copy Permissions from") }), ('role', { 'label': _("Node Type"), 'help_text': _("Each Node has specific role in forums tree. This role cannot be changed after node is created." ) }), ('name', { 'label': _("Node Name") }), ('description', { 'label': _("Node Description") }), ('redirect', { 'label': _("Redirect URL"), 'help_text': _("Redirection nodes require you to specify URL they will redirect users to upon click." ) }), ('closed', { 'label': _("Closed Node") }), ), ), ( _("Display Options"), ( ('attrs', { 'label': _("Node Attributes"), 'help_text': _('Custom templates can check nodes for predefined attributes that will change way they are rendered.' ) }), ('show_details', { 'label': _("Show Subforums Details"), 'help_text': _('Allows you to prevent this node subforums from displaying statistics, last post data, etc. ect. on forums lists.' ) }), ('style', { 'label': _("Node Style"), 'help_text': _('You can add custom CSS classess to this node, to change way it looks on board index.' ) }), ), ), ) def finalize_form(self): self.add_field( 'parent', TreeNodeChoiceField( label=_("Node Parent"), widget=forms.Select, queryset=Forum.objects.get(special='root').get_descendants( include_self=True), level_indicator=u'- - ')) self.add_field( 'perms', TreeNodeChoiceField( label=_("Copy Permissions from"), widget=forms.Select, queryset=Forum.objects.get(special='root').get_descendants(), level_indicator=u'- - ', required=False, empty_label=_("Don't copy permissions"))) def clean(self): cleaned_data = super(NewNodeForm, self).clean() node_role = cleaned_data['role'] if node_role != 'category' and cleaned_data['parent'].special == 'root': raise forms.ValidationError( _("Only categories can use Root Category as their parent.")) if node_role == 'redirect' and not cleaned_data['redirect']: raise forms.ValidationError( _("You have to define redirection URL")) return cleaned_data