2 from django import forms
3 from django.utils.translation import ugettext as _
4 from qanda import TitleField, EditorField
5 from forum import settings
7 class IPListField(forms.CharField):
8 def clean(self, value):
9 ips = [ip.strip() for ip in value.strip().strip(',').split(',')]
13 raise forms.ValidationError(_('Please input at least one ip address'))
19 raise forms.ValidationError(_('Invalid ip address: %s' % ip))
21 if not len(ip.split('.')) == 4:
22 raise forms.ValidationError(_('Please use the dotted quad notation for the ip addresses'))
28 class MaintenanceModeForm(forms.Form):
29 ips = IPListField(label=_('Allow ips'),
30 help_text=_('Comma separated list of ips allowed to access the site while in maintenance'),
32 widget=forms.TextInput(attrs={'class': 'longstring'}))
34 message = forms.CharField(label=_('Message'),
35 help_text=_('A message to display to your site visitors while in maintainance mode'),
36 widget=forms.Textarea)
40 ('default', _('Default')),
41 ('sidebar', _('Default with sidebar')),
46 ('markdown', _('Markdown')),
48 ('escape', _('Escaped'))
51 class UrlFieldWidget(forms.TextInput):
52 def render(self, name, value, attrs=None):
57 <input class="url_field" type="text" name="%(name)s" value="%(value)s" />
58 <a class="url_field_anchor" target="_blank" href="%(app_url)s%(script_alias)s"></a>
59 """ % {'name': name, 'value': value, 'app_url': settings.APP_URL,
60 'script_alias': settings.FORUM_SCRIPT_ALIAS}
63 class PageForm(forms.Form):
64 def __init__(self, page, *args, **kwargs):
67 initial.update(dict(title=page.title, content=page.body))
68 super(PageForm, self).__init__(initial=initial, *args, **kwargs)
70 super(PageForm, self).__init__(*args, **kwargs)
73 title = forms.CharField(label=_('Title'), max_length=255, widget=forms.TextInput(attrs={'class': 'longstring'}),
75 path = forms.CharField(label=_('Page URL'), widget=UrlFieldWidget, initial='pages/new/')
77 content = forms.CharField(label=_('Page Content'), widget=forms.Textarea(attrs={'rows': 30}))
78 mimetype = forms.CharField(label=_('Mime Type'), initial='text/html')
80 render = forms.ChoiceField(widget=forms.RadioSelect, choices=RENDER_CHOICES, initial='markdown',
81 label=_('Render Mode'))
83 template = forms.ChoiceField(widget=forms.RadioSelect, choices=TEMPLATE_CHOICES, initial='default',
85 sidebar = forms.CharField(label=_('Sidebar Content'), widget=forms.Textarea(attrs={'rows': 20}), required=False)
86 sidebar_wrap = forms.BooleanField(label=_("Wrap sidebar block"), initial=True, required=False)
87 sidebar_render = forms.ChoiceField(widget=forms.RadioSelect, choices=RENDER_CHOICES, initial='markdown',
88 label=_('Sidebar Render Mode'))
90 comments = forms.BooleanField(label=_("Allow comments"), initial=False, required=False)