Get close to the look of the existing form. MultiEmailField might
belong in a project infrastructure file, not here. - Legacy-Id: 180
This commit is contained in:
parent
0eb450cab7
commit
3e634ccadd
|
@ -146,3 +146,51 @@ class ListReqAuthorized(forms.Form):
|
||||||
# subclass pickapprover here too?
|
# subclass pickapprover here too?
|
||||||
class ListReqClose(forms.Form):
|
class ListReqClose(forms.Form):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class AdminRequestor(forms.MultiWidget):
|
||||||
|
def decompress(self, value):
|
||||||
|
# This implementation moves the requestor to the listbox
|
||||||
|
# if there are any validation errors.
|
||||||
|
# If we could find the requestor, we could instead
|
||||||
|
# check the checkbox, but for now let's try this.
|
||||||
|
return ['', '', value]
|
||||||
|
def __init__(self, attrs=None):
|
||||||
|
widgets = (forms.CheckboxInput(), forms.TextInput(attrs={'size': 55, 'disabled': True}), forms.Textarea(attrs=attrs))
|
||||||
|
super(AdminRequestor, self).__init__(widgets, attrs)
|
||||||
|
def format_output(self, rendered_widgets):
|
||||||
|
return u'<br/>\n'.join(["<label>%s Same as requestor</label>" % rendered_widgets[0]] + rendered_widgets[1:])
|
||||||
|
def value_from_datadict(self, data, name):
|
||||||
|
try:
|
||||||
|
radio = data.get(name + '_0', "off")
|
||||||
|
rest = data[name + '_2']
|
||||||
|
print "radio is %s, rest is %s" % (radio, rest)
|
||||||
|
if radio == 'on':
|
||||||
|
# This has some deep assumptions about how
|
||||||
|
# this is used.
|
||||||
|
key = name.replace('admins', 'requestor_email')
|
||||||
|
try:
|
||||||
|
return data[key] + "\n" + rest
|
||||||
|
except KeyError:
|
||||||
|
return rest
|
||||||
|
else:
|
||||||
|
return rest
|
||||||
|
except KeyError:
|
||||||
|
try:
|
||||||
|
return data[name]
|
||||||
|
except KeyError:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
class MultiEmailField(forms.CharField):
|
||||||
|
'''Ensure that each of a carraige-return-separated
|
||||||
|
list of e-mail addresses is valid.'''
|
||||||
|
def clean(self, value):
|
||||||
|
value = super(MultiEmailField, self).clean(value)
|
||||||
|
bad = list()
|
||||||
|
for addr in value.split("\n"):
|
||||||
|
addr = addr.strip()
|
||||||
|
if addr != '' and not(forms.fields.email_re.search(addr)):
|
||||||
|
bad.append(addr)
|
||||||
|
if len(bad) > 0:
|
||||||
|
raise forms.ValidationError, "The following email addresses seem to be invalid: %s" % ", ".join(["'" + addr + "'" for addr in bad])
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from ietf.idtracker.models import Acronym, Area, PersonOrOrgInfo
|
from ietf.idtracker.models import Acronym, Area, PersonOrOrgInfo
|
||||||
import random
|
import random
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
class ImportedMailingList(models.Model):
|
class ImportedMailingList(models.Model):
|
||||||
group_acronym = models.ForeignKey(Acronym, null=True)
|
group_acronym = models.ForeignKey(Acronym, null=True)
|
||||||
|
@ -45,26 +46,26 @@ class MailingList(models.Model):
|
||||||
('3', 'Close Non-WG Mailing List'),
|
('3', 'Close Non-WG Mailing List'),
|
||||||
)
|
)
|
||||||
mailing_list_id = models.CharField('Unique ID', primary_key=True, maxlength=25, editable=False)
|
mailing_list_id = models.CharField('Unique ID', primary_key=True, maxlength=25, editable=False)
|
||||||
request_date = models.DateField()
|
request_date = models.DateField(default=datetime.now, editable=False)
|
||||||
mlist_name = models.CharField('Mailing list name', maxlength=250)
|
requestor = models.CharField("Requestor's full name", maxlength=250)
|
||||||
short_desc = models.CharField(maxlength=250)
|
requestor_email = models.EmailField("Requestor's email address", maxlength=250)
|
||||||
long_desc = models.TextField(blank=True)
|
mlist_name = models.CharField('Email list name', maxlength=250)
|
||||||
requestor = models.CharField(maxlength=250)
|
short_desc = models.CharField('Short description of the email list', maxlength=250)
|
||||||
requestor_email = models.CharField(maxlength=250)
|
long_desc = models.TextField('Long description of the email list')
|
||||||
# admins is a VARCHAR but can have multiple lines
|
# admins is a VARCHAR but can have multiple lines.
|
||||||
admins = models.TextField(blank=True, maxlength=250)
|
admins = models.TextField('Mailing list administrators (one address per line)', maxlength=250)
|
||||||
archive_remote = models.TextField(blank=True)
|
initial = models.TextField('Enter email address(es) of initial subscriber(s) (one address per line) (optional)', blank=True)
|
||||||
archive_private = models.BooleanField()
|
welcome_message = models.TextField('Provide a welcome message for initial subscriber(s)(optional)', blank=True)
|
||||||
initial = models.TextField('Initial members',blank=True)
|
welcome_new = models.TextField('Provide a welcome message for new subscriber(s)(optional)', blank=True)
|
||||||
welcome_message = models.TextField(blank=True)
|
subscription = models.IntegerField('What steps are required for subscription?', choices=SUBSCRIPTION_CHOICES)
|
||||||
subscription = models.IntegerField(choices=SUBSCRIPTION_CHOICES)
|
|
||||||
post_who = models.BooleanField('Only members can post')
|
post_who = models.BooleanField('Only members can post')
|
||||||
post_admin = models.BooleanField('Administrator approval required for posts')
|
post_admin = models.BooleanField('Do postings need to be approved by an administrator?')
|
||||||
|
archive_private = models.BooleanField('Are the archives private?')
|
||||||
|
archive_remote = models.TextField('Provide specific information about how to access and move the existing archive (optional)', blank=True)
|
||||||
add_comment = models.TextField(blank=True)
|
add_comment = models.TextField(blank=True)
|
||||||
mail_type = models.IntegerField(choices=MAILTYPE_CHOICES)
|
mail_type = models.IntegerField(choices=MAILTYPE_CHOICES)
|
||||||
mail_cat = models.IntegerField(choices=MAILCAT_CHOICES)
|
mail_cat = models.IntegerField(choices=MAILCAT_CHOICES)
|
||||||
auth_person = models.ForeignKey(PersonOrOrgInfo, db_column='auth_person_or_org_tag', raw_id_admin=True)
|
auth_person = models.ForeignKey(PersonOrOrgInfo, db_column='auth_person_or_org_tag', raw_id_admin=True)
|
||||||
welcome_new = models.TextField(blank=True)
|
|
||||||
approved = models.BooleanField()
|
approved = models.BooleanField()
|
||||||
approved_date = models.DateField(null=True, blank=True)
|
approved_date = models.DateField(null=True, blank=True)
|
||||||
reason_to_delete = models.TextField(blank=True)
|
reason_to_delete = models.TextField(blank=True)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from forms import NonWgStep1, ListReqStep1, PickApprover, DeletionPickApprover, UrlMultiWidget, Preview, ListReqAuthorized, ListReqClose
|
from forms import NonWgStep1, ListReqStep1, PickApprover, DeletionPickApprover, UrlMultiWidget, Preview, ListReqAuthorized, ListReqClose, MultiEmailField, AdminRequestor
|
||||||
from models import NonWgMailingList, MailingList
|
from models import NonWgMailingList, MailingList
|
||||||
from ietf.idtracker.models import Area, PersonOrOrgInfo
|
from ietf.idtracker.models import Area, PersonOrOrgInfo
|
||||||
from django import newforms as forms
|
from django import newforms as forms
|
||||||
|
@ -140,12 +140,38 @@ list_fields = {
|
||||||
'approved': None,
|
'approved': None,
|
||||||
'approved_date': None,
|
'approved_date': None,
|
||||||
'reason_to_delete': None,
|
'reason_to_delete': None,
|
||||||
|
'add_comment': None,
|
||||||
|
'mail_type': None,
|
||||||
|
'mail_cat': None,
|
||||||
|
'domain_name': None,
|
||||||
|
'admins': MultiEmailField(label='List Administrator(s)', widget=AdminRequestor(attrs={'cols': 41, 'rows': 4})),
|
||||||
|
'initial': MultiEmailField(label='Initial list member(s)', widget=forms.Textarea(attrs={'cols': 41, 'rows': 4}), required=False),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list_labels = {
|
||||||
|
'post_who': 'Who is allowed to post to this list?',
|
||||||
|
}
|
||||||
|
|
||||||
|
# can I do a multiwidget for the mailing list admins?
|
||||||
|
# and something to display @domain after the email list name?
|
||||||
list_widgets = {
|
list_widgets = {
|
||||||
|
'subscription': forms.Select(choices=MailingList.SUBSCRIPTION_CHOICES),
|
||||||
|
'post_who': forms.Select(choices=(('1', 'List members only'), ('0', 'Open'))),
|
||||||
|
'post_admin': forms.Select(choices=(('0', 'No'), ('1', 'Yes'))),
|
||||||
|
'archive_private': forms.Select(choices=(('0', 'No'), ('1', 'Yes'))),
|
||||||
}
|
}
|
||||||
|
|
||||||
list_attrs = {
|
list_attrs = {
|
||||||
|
'requestor': { 'size': 55 },
|
||||||
|
'requestor_email': { 'size': 55 },
|
||||||
|
'mlist_name': { 'size': 10 },
|
||||||
|
'short_desc': { 'size': 55 },
|
||||||
|
'long_desc': { 'cols': 41, 'rows': 4, 'wrap': 'virtual' },
|
||||||
|
'admins': { 'cols': 41, 'rows': 4 },
|
||||||
|
'initial': { 'cols': 41, 'rows': 4 },
|
||||||
|
'welcome_message': { 'cols': 41, 'rows': 4 },
|
||||||
|
'welcome_new': { 'cols': 41, 'rows': 4 },
|
||||||
|
'archive_remote': { 'cols': 41, 'rows': 4 },
|
||||||
}
|
}
|
||||||
|
|
||||||
list_callback = form_decorator(fields=list_fields, widgets=list_widgets, attrs=list_attrs)
|
list_callback = form_decorator(fields=list_fields, widgets=list_widgets, attrs=list_attrs)
|
||||||
|
@ -175,7 +201,7 @@ class ListReqWizard(wizard.Wizard):
|
||||||
if form.clean_data['mail_type'].startswith('close'):
|
if form.clean_data['mail_type'].startswith('close'):
|
||||||
self.form_list.append(ListReqClose)
|
self.form_list.append(ListReqClose)
|
||||||
else:
|
else:
|
||||||
self.form_list.append(forms.form_for_model(MailingList))
|
self.form_list.append(forms.form_for_model(MailingList, formfield_callback=list_callback))
|
||||||
#XXX not quite
|
#XXX not quite
|
||||||
super(ListReqWizard, self).process_step(request, form, step)
|
super(ListReqWizard, self).process_step(request, form, step)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue