Skip to content

Commit 3e634cc

Browse files
committed
Get close to the look of the existing form. MultiEmailField might
belong in a project infrastructure file, not here. - Legacy-Id: 180
1 parent 0eb450c commit 3e634cc

3 files changed

Lines changed: 92 additions & 17 deletions

File tree

ietf/mailinglists/forms.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,51 @@ def clean_authorized(self):
146146
# subclass pickapprover here too?
147147
class ListReqClose(forms.Form):
148148
pass
149+
150+
class AdminRequestor(forms.MultiWidget):
151+
def decompress(self, value):
152+
# This implementation moves the requestor to the listbox
153+
# if there are any validation errors.
154+
# If we could find the requestor, we could instead
155+
# check the checkbox, but for now let's try this.
156+
return ['', '', value]
157+
def __init__(self, attrs=None):
158+
widgets = (forms.CheckboxInput(), forms.TextInput(attrs={'size': 55, 'disabled': True}), forms.Textarea(attrs=attrs))
159+
super(AdminRequestor, self).__init__(widgets, attrs)
160+
def format_output(self, rendered_widgets):
161+
return u'<br/>\n'.join(["<label>%s Same as requestor</label>" % rendered_widgets[0]] + rendered_widgets[1:])
162+
def value_from_datadict(self, data, name):
163+
try:
164+
radio = data.get(name + '_0', "off")
165+
rest = data[name + '_2']
166+
print "radio is %s, rest is %s" % (radio, rest)
167+
if radio == 'on':
168+
# This has some deep assumptions about how
169+
# this is used.
170+
key = name.replace('admins', 'requestor_email')
171+
try:
172+
return data[key] + "\n" + rest
173+
except KeyError:
174+
return rest
175+
else:
176+
return rest
177+
except KeyError:
178+
try:
179+
return data[name]
180+
except KeyError:
181+
return ''
182+
183+
class MultiEmailField(forms.CharField):
184+
'''Ensure that each of a carraige-return-separated
185+
list of e-mail addresses is valid.'''
186+
def clean(self, value):
187+
value = super(MultiEmailField, self).clean(value)
188+
bad = list()
189+
for addr in value.split("\n"):
190+
addr = addr.strip()
191+
if addr != '' and not(forms.fields.email_re.search(addr)):
192+
bad.append(addr)
193+
if len(bad) > 0:
194+
raise forms.ValidationError, "The following email addresses seem to be invalid: %s" % ", ".join(["'" + addr + "'" for addr in bad])
195+
return value
196+

ietf/mailinglists/models.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from django.db import models
22
from ietf.idtracker.models import Acronym, Area, PersonOrOrgInfo
33
import random
4+
from datetime import datetime
45

56
class ImportedMailingList(models.Model):
67
group_acronym = models.ForeignKey(Acronym, null=True)
@@ -45,26 +46,26 @@ class MailingList(models.Model):
4546
('3', 'Close Non-WG Mailing List'),
4647
)
4748
mailing_list_id = models.CharField('Unique ID', primary_key=True, maxlength=25, editable=False)
48-
request_date = models.DateField()
49-
mlist_name = models.CharField('Mailing list name', maxlength=250)
50-
short_desc = models.CharField(maxlength=250)
51-
long_desc = models.TextField(blank=True)
52-
requestor = models.CharField(maxlength=250)
53-
requestor_email = models.CharField(maxlength=250)
54-
# admins is a VARCHAR but can have multiple lines
55-
admins = models.TextField(blank=True, maxlength=250)
56-
archive_remote = models.TextField(blank=True)
57-
archive_private = models.BooleanField()
58-
initial = models.TextField('Initial members',blank=True)
59-
welcome_message = models.TextField(blank=True)
60-
subscription = models.IntegerField(choices=SUBSCRIPTION_CHOICES)
49+
request_date = models.DateField(default=datetime.now, editable=False)
50+
requestor = models.CharField("Requestor's full name", maxlength=250)
51+
requestor_email = models.EmailField("Requestor's email address", maxlength=250)
52+
mlist_name = models.CharField('Email list name', maxlength=250)
53+
short_desc = models.CharField('Short description of the email list', maxlength=250)
54+
long_desc = models.TextField('Long description of the email list')
55+
# admins is a VARCHAR but can have multiple lines.
56+
admins = models.TextField('Mailing list administrators (one address per line)', maxlength=250)
57+
initial = models.TextField('Enter email address(es) of initial subscriber(s) (one address per line) (optional)', blank=True)
58+
welcome_message = models.TextField('Provide a welcome message for initial subscriber(s)(optional)', blank=True)
59+
welcome_new = models.TextField('Provide a welcome message for new subscriber(s)(optional)', blank=True)
60+
subscription = models.IntegerField('What steps are required for subscription?', choices=SUBSCRIPTION_CHOICES)
6161
post_who = models.BooleanField('Only members can post')
62-
post_admin = models.BooleanField('Administrator approval required for posts')
62+
post_admin = models.BooleanField('Do postings need to be approved by an administrator?')
63+
archive_private = models.BooleanField('Are the archives private?')
64+
archive_remote = models.TextField('Provide specific information about how to access and move the existing archive (optional)', blank=True)
6365
add_comment = models.TextField(blank=True)
6466
mail_type = models.IntegerField(choices=MAILTYPE_CHOICES)
6567
mail_cat = models.IntegerField(choices=MAILCAT_CHOICES)
6668
auth_person = models.ForeignKey(PersonOrOrgInfo, db_column='auth_person_or_org_tag', raw_id_admin=True)
67-
welcome_new = models.TextField(blank=True)
6869
approved = models.BooleanField()
6970
approved_date = models.DateField(null=True, blank=True)
7071
reason_to_delete = models.TextField(blank=True)

ietf/mailinglists/views.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from forms import NonWgStep1, ListReqStep1, PickApprover, DeletionPickApprover, UrlMultiWidget, Preview, ListReqAuthorized, ListReqClose
1+
from forms import NonWgStep1, ListReqStep1, PickApprover, DeletionPickApprover, UrlMultiWidget, Preview, ListReqAuthorized, ListReqClose, MultiEmailField, AdminRequestor
22
from models import NonWgMailingList, MailingList
33
from ietf.idtracker.models import Area, PersonOrOrgInfo
44
from django import newforms as forms
@@ -140,12 +140,38 @@ def non_wg_wizard(request):
140140
'approved': None,
141141
'approved_date': None,
142142
'reason_to_delete': None,
143+
'add_comment': None,
144+
'mail_type': None,
145+
'mail_cat': None,
146+
'domain_name': None,
147+
'admins': MultiEmailField(label='List Administrator(s)', widget=AdminRequestor(attrs={'cols': 41, 'rows': 4})),
148+
'initial': MultiEmailField(label='Initial list member(s)', widget=forms.Textarea(attrs={'cols': 41, 'rows': 4}), required=False),
143149
}
144150

151+
list_labels = {
152+
'post_who': 'Who is allowed to post to this list?',
153+
}
154+
155+
# can I do a multiwidget for the mailing list admins?
156+
# and something to display @domain after the email list name?
145157
list_widgets = {
158+
'subscription': forms.Select(choices=MailingList.SUBSCRIPTION_CHOICES),
159+
'post_who': forms.Select(choices=(('1', 'List members only'), ('0', 'Open'))),
160+
'post_admin': forms.Select(choices=(('0', 'No'), ('1', 'Yes'))),
161+
'archive_private': forms.Select(choices=(('0', 'No'), ('1', 'Yes'))),
146162
}
147163

148164
list_attrs = {
165+
'requestor': { 'size': 55 },
166+
'requestor_email': { 'size': 55 },
167+
'mlist_name': { 'size': 10 },
168+
'short_desc': { 'size': 55 },
169+
'long_desc': { 'cols': 41, 'rows': 4, 'wrap': 'virtual' },
170+
'admins': { 'cols': 41, 'rows': 4 },
171+
'initial': { 'cols': 41, 'rows': 4 },
172+
'welcome_message': { 'cols': 41, 'rows': 4 },
173+
'welcome_new': { 'cols': 41, 'rows': 4 },
174+
'archive_remote': { 'cols': 41, 'rows': 4 },
149175
}
150176

151177
list_callback = form_decorator(fields=list_fields, widgets=list_widgets, attrs=list_attrs)
@@ -175,7 +201,7 @@ def process_step(self, request, form, step):
175201
if form.clean_data['mail_type'].startswith('close'):
176202
self.form_list.append(ListReqClose)
177203
else:
178-
self.form_list.append(forms.form_for_model(MailingList))
204+
self.form_list.append(forms.form_for_model(MailingList, formfield_callback=list_callback))
179205
#XXX not quite
180206
super(ListReqWizard, self).process_step(request, form, step)
181207

0 commit comments

Comments
 (0)