Rearrange nwg model to get the fields in the right order.

Allow nwg wizard to have a per-step template.

Write templates for step 0 and add/edit step 1.
 - Legacy-Id: 149
This commit is contained in:
Bill Fenner 2007-05-22 19:56:20 +00:00
parent 5c1254f2df
commit 41b788ad30
7 changed files with 123 additions and 23 deletions

View file

@ -67,7 +67,6 @@ class ListReqStep1(forms.Form):
return self.clean_data['list_to_close']
# multiwidget for separate scheme and rest for urls
# todo: can the clean return the "smart" value?
class UrlMultiWidget(forms.MultiWidget):
def decompress(self, value):
if value:
@ -88,6 +87,17 @@ class UrlMultiWidget(forms.MultiWidget):
def format_output(self, rendered_widgets):
return u'%s\n%s\n<br/>' % ( u'<br/>\n'.join(["%s" % w for w in rendered_widgets[0]]), rendered_widgets[1] )
# If we have two widgets, return the concatenation of the values
# (Except, if _0 is "n/a" then return an empty string)
# Otherwise, just return the value.
def value_from_datadict(self, data, name):
try:
scheme = data[name + '_0']
if scheme == 'n/a':
return ''
return scheme + data[name + '_1']
except KeyError:
return data[name]
class PickApprover(forms.Form):
"""

View file

@ -77,20 +77,20 @@ class MailingList(models.Model):
class NonWgMailingList(models.Model):
id = models.CharField(primary_key=True, maxlength=35)
s_name = models.CharField("Submitter's Name", blank=True, maxlength=255)
s_email = models.EmailField("Submitter's Email Address", blank=True, maxlength=255)
list_name = models.CharField("Mailing List Name", unique=True, maxlength=255)
list_url = models.CharField("List URL", maxlength=255)
admin = models.TextField("Administrator(s)' Email Address(es)", blank=True)
purpose = models.TextField(blank=True)
area = models.ForeignKey(Areas, db_column='area_acronym_id')
admin = models.TextField("Administrator(s)' Email Address(es)", blank=True)
list_url = models.CharField("List URL", maxlength=255)
s_name = models.CharField("Submitter's Name", blank=True, maxlength=255)
s_email = models.CharField("Submitter's Email Address", blank=True, maxlength=255)
subscribe_url = models.CharField("Subscribe URL", blank=True, maxlength=255)
subscribe_other = models.TextField("Subscribe Other", blank=True)
# Can be 0, 1, -1, or what looks like a person_or_org_tag, positive or neg.
# The values less than 1 don't get displayed on the list of lists.
status = models.IntegerField()
list_name = models.CharField("Mailing List Name", unique=True, maxlength=255)
subscribe_url = models.CharField("Subscribe URL", blank=True, maxlength=255)
subscribe_other = models.TextField("Subscribe Other", blank=True)
ds_name = models.CharField(blank=True, maxlength=255)
ds_email = models.CharField(blank=True, maxlength=255)
ds_email = models.EmailField(blank=True, maxlength=255)
msg_to_ad = models.TextField(blank=True)
def __str__(self):
return self.list_name

View file

@ -13,12 +13,25 @@ nonwg_fields = {
'msg_to_ad': None,
}
nonwg_widgets = {
'list_url': UrlMultiWidget(choices=(('http://', 'http://'), ('https://', 'https://'), ('mailto:', 'mailto:'))),
'subscribe_url': UrlMultiWidget(choices=(('n/a', 'Not Applicable'), ('http://', 'http://'), ('https://', 'https://'))),
nonwg_attrs = {
's_name': {'size': 50},
's_email': {'size': 50},
'list_name': {'size': 80},
}
nonwg_callback = form_decorator(fields=nonwg_fields, widgets=nonwg_widgets)
nonwg_widgets = {
'list_url': UrlMultiWidget(choices=(('http://', 'http://'), ('https://', 'https://'), ('mailto:', 'mailto:'))),
'admin': forms.Textarea(attrs = {'rows': 3, 'cols': 50}),
'purpose': forms.Textarea(attrs = {'rows': 4, 'cols': 70}),
'subscribe_url': UrlMultiWidget(choices=(('n/a', 'Not Applicable'), ('http://', 'http://'), ('https://', 'https://'))),
'subscribe_other': forms.Textarea(attrs = {'rows': 3, 'cols': 50}),
}
nonwg_querysets = {
'area': Areas.objects.filter(status=1)
}
nonwg_callback = form_decorator(fields=nonwg_fields, widgets=nonwg_widgets, attrs=nonwg_attrs, querysets=nonwg_querysets)
def gen_approval(approvers, parent):
class BoundApproval(parent):
@ -28,13 +41,22 @@ def gen_approval(approvers, parent):
return BoundApproval
class NonWgWizard(wizard.Wizard):
form0 = None
def get_template(self):
return "mailinglists/nwg_wizard.html"
def hash_failed(self, step):
templates = []
if self.form0:
action = {'add': 'addedit', 'edit': 'addedit', 'delete': 'delete'}[self.form0.clean_data['add_edit']]
templates.append("mailinglists/nwg_wizard_%s_step%d.html" % (action, self.step))
templates.append("mailinglists/nwg_wizard_%s.html" % (action))
templates.append("mailinglists/nwg_wizard_step%d.html" % (self.step))
templates.append("mailinglists/nwg_wizard.html")
return templates
def failed_hash(self, step):
raise NotImplementedError("step %d hash failed" % step)
def process_step(self, request, form, step):
form.full_clean()
if step == 0:
self.form0 = form
if form.clean_data['add_edit'] == 'add':
self.form_list.append(forms.form_for_model(NonWgMailingList, formfield_callback=nonwg_callback))
elif form.clean_data['add_edit'] == 'edit':
@ -45,6 +67,7 @@ class NonWgWizard(wizard.Wizard):
if step == 1:
form0 = self.get_form(0, request.POST)
form0.full_clean()
self.form0 = form0
add_edit = form0.clean_data['add_edit']
if add_edit == 'add' or add_edit == 'edit':
self.form_list.append(gen_approval([ad.person_id for ad in Areas.objects.get(area_acronym=form.clean_data['area']).areadirectors_set.all()], PickApprover))
@ -57,8 +80,7 @@ def non_wg_wizard(request):
class ListReqWizard(wizard.Wizard):
def get_template(self):
return "mailinglists/nwg_wizard.html"
def hash_failed(self, step):
raise NotImplementedError("step %d hash failed" % step)
# want to implement parse_params to get domain for list
def process_step(self, request, form, step):
form.full_clean()
super(ListReqWizard, self).process_step(request, form, step)

View file

@ -1,10 +1,6 @@
{% extends "base.html" %}
{% extends "mailinglists/nwg_wizard_base.html" %}
{% block css %}
ul.errorlist { color: red; border: 1px solid red; }
{% endblock %}
{% block content %}
{% block nwgcontent %}
<form action="." method="POST">
FORM( {{ step }} ):<table> {{ form }} </table>

View file

@ -0,0 +1,28 @@
{% extends "mailinglists/nwg_wizard_base.html" %}
{% block nwgcss %}
tr > th { text-align: left; vertical-align: top; }
{% endblock %}
{% block nwgcontent %}
<h2>Step 2</h2>
<h4>Please provide the following information:</h4>
<form action="." method="POST">
<table bgcolor="#88AED2" cellspacing="1" border="0" width="714">
<tr valign="top"><td>
<table bgcolor="#f3f8fd" cellpadding="3" cellspacing="0" border="0">
{{ form }}
<tr>
<td></td>
<td>
<input type="submit" value=" SUBMIT ">
</td>
</tr>
</table>
</td></tr>
</table>
{{ previous_fields }}
<input type="hidden" name="{{ step_field }}" value="{{ step }}" />
</form>
{% endblock %}

View file

@ -0,0 +1,25 @@
{% extends "base.html" %}
{% block title %}IETF Non WG Mailing List Submit Form{% endblock %}
{% block css %}
ul.errorlist { color: red; border: 1px solid red; }
{% block nwgcss %}{% endblock %}
{% endblock %}
{% block head %}
<link rel="stylesheet" type="text/css" href="http://www.ietf.org/css/base.css" />
{% endblock %}
{% block content %}
<blockquote>
<img src="/images/nwg/mail_title_submission.gif" border="0"><br>
<img src="/images/nwg/t_un1.gif" border="0">
<!-- form step {{ step }} -->
<br>
{% block nwgcontent %}
form goes here
{% endblock %}
</blockquote>
{% endblock %}

View file

@ -0,0 +1,19 @@
{% extends "mailinglists/nwg_wizard_base.html" %}
{% block nwgcontent %}
<h4>Please use this Web tool to add a new entry to the <a href="/mailinglists/nonwg_lists/">IETF Non-WG Mailing Lists</a> Web page, to update the information on an existing entry, or to delete an existing entry.</h4>
<a href="/mailinglists/nonwg_lists/"><b>View Current list</b></a><br>
</p><p>
<h2>Step 1</h2>
<h3>Please select one:</h3>
<form action="." method="POST">
{{ form.add_edit_fields.0 }}<br>
{{ form.add_edit_fields.1 }}{{ form.list_id }}<br>
{{ form.add_edit_fields.2 }}{{ form.list_id_delete }}<br>
<input type="submit" value=" Proceed ">
<!--
onClick="if (document.form_get.add_edit[0].checked == false && document.form_get.add_edit[1].checked == false && document.form_get.add_edit[2].checked == false) {alert('Please select one of three options');return false;}">
-->
</form>
{% endblock %}