2 from django import forms
3 from django.utils.translation import ugettext as _
4 from django.contrib.admin.widgets import FilteredSelectMultiple, AdminDateWidget
5 from qanda import TitleField, EditorField
6 from forum import settings
7 from forum.models.node import NodeMetaClass
8 from forum.models import User
10 class IPListField(forms.CharField):
11 def clean(self, value):
12 ips = [ip.strip() for ip in value.strip().strip(',').split(',')]
16 raise forms.ValidationError(_('Please input at least one ip address'))
22 raise forms.ValidationError(_('Invalid ip address: %s' % ip))
24 if not len(ip.split('.')) == 4:
25 raise forms.ValidationError(_('Please use the dotted quad notation for the ip addresses'))
31 class MaintenanceModeForm(forms.Form):
32 ips = IPListField(label=_('Allow ips'),
33 help_text=_('Comma separated list of ips allowed to access the site while in maintenance'),
35 widget=forms.TextInput(attrs={'class': 'longstring'}))
37 message = forms.CharField(label=_('Message'),
38 help_text=_('A message to display to your site visitors while in maintainance mode'),
39 widget=forms.Textarea)
43 ('default', _('Default')),
44 ('sidebar', _('Default with sidebar')),
49 ('markdown', _('Markdown')),
51 ('escape', _('Escaped'))
54 class UrlFieldWidget(forms.TextInput):
55 def render(self, name, value, attrs=None):
60 <input class="url_field" type="text" name="%(name)s" value="%(value)s" />
61 <a class="url_field_anchor" target="_blank" href="%(app_url)s"></a>
62 """ % {'name': name, 'value': value, 'app_url': settings.APP_URL}
65 class PageForm(forms.Form):
66 def __init__(self, page, *args, **kwargs):
69 initial.update(dict(title=page.title, content=page.body))
70 super(PageForm, self).__init__(initial=initial, *args, **kwargs)
72 super(PageForm, self).__init__(*args, **kwargs)
75 title = forms.CharField(label=_('Title'), max_length=255, widget=forms.TextInput(attrs={'class': 'longstring'}),
77 path = forms.CharField(label=_('Page URL'), widget=UrlFieldWidget, initial='pages/new/')
79 content = forms.CharField(label=_('Page Content'), widget=forms.Textarea(attrs={'rows': 30}))
80 mimetype = forms.CharField(label=_('Mime Type'), initial='text/html')
82 render = forms.ChoiceField(widget=forms.RadioSelect, choices=RENDER_CHOICES, initial='markdown',
83 label=_('Render Mode'))
85 template = forms.ChoiceField(widget=forms.RadioSelect, choices=TEMPLATE_CHOICES, initial='default',
87 sidebar = forms.CharField(label=_('Sidebar Content'), widget=forms.Textarea(attrs={'rows': 20}), required=False)
88 sidebar_wrap = forms.BooleanField(label=_("Wrap sidebar block"), initial=True, required=False)
89 sidebar_render = forms.ChoiceField(widget=forms.RadioSelect, choices=RENDER_CHOICES, initial='markdown',
90 label=_('Sidebar Render Mode'))
92 comments = forms.BooleanField(label=_("Allow comments"), initial=False, required=False)
94 from forum.forms.auth import SimpleRegistrationForm
95 from forum.forms.general import SetPasswordForm
98 class CreateUserForm(SimpleRegistrationForm, SetPasswordForm):
99 validate_email = forms.BooleanField(required=False, label=_('send validation email'))
101 def __init__(self, *args, **kwargs):
102 super(CreateUserForm, self).__init__(*args, **kwargs)
103 self.fields.keyOrder = ['username', 'email', 'validate_email', 'password1', 'password2']
104 self.fields['email'].label = _('email address')