Skip to content

Commit 41b788a

Browse files
committed
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
1 parent 5c1254f commit 41b788a

7 files changed

Lines changed: 120 additions & 20 deletions

File tree

ietf/mailinglists/forms.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ def clean_list_to_close(self):
6767
return self.clean_data['list_to_close']
6868

6969
# multiwidget for separate scheme and rest for urls
70-
# todo: can the clean return the "smart" value?
7170
class UrlMultiWidget(forms.MultiWidget):
7271
def decompress(self, value):
7372
if value:
@@ -88,6 +87,17 @@ def __init__(self, choices=(('http://', 'http://'), ('https://', 'https://')), a
8887
def format_output(self, rendered_widgets):
8988
return u'%s\n%s\n<br/>' % ( u'<br/>\n'.join(["%s" % w for w in rendered_widgets[0]]), rendered_widgets[1] )
9089

90+
# If we have two widgets, return the concatenation of the values
91+
# (Except, if _0 is "n/a" then return an empty string)
92+
# Otherwise, just return the value.
93+
def value_from_datadict(self, data, name):
94+
try:
95+
scheme = data[name + '_0']
96+
if scheme == 'n/a':
97+
return ''
98+
return scheme + data[name + '_1']
99+
except KeyError:
100+
return data[name]
91101

92102
class PickApprover(forms.Form):
93103
"""

ietf/mailinglists/models.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,20 @@ class Admin:
7777

7878
class NonWgMailingList(models.Model):
7979
id = models.CharField(primary_key=True, maxlength=35)
80+
s_name = models.CharField("Submitter's Name", blank=True, maxlength=255)
81+
s_email = models.EmailField("Submitter's Email Address", blank=True, maxlength=255)
82+
list_name = models.CharField("Mailing List Name", unique=True, maxlength=255)
83+
list_url = models.CharField("List URL", maxlength=255)
84+
admin = models.TextField("Administrator(s)' Email Address(es)", blank=True)
8085
purpose = models.TextField(blank=True)
8186
area = models.ForeignKey(Areas, db_column='area_acronym_id')
82-
admin = models.TextField("Administrator(s)' Email Address(es)", blank=True)
83-
list_url = models.CharField("List URL", maxlength=255)
84-
s_name = models.CharField("Submitter's Name", blank=True, maxlength=255)
85-
s_email = models.CharField("Submitter's Email Address", blank=True, maxlength=255)
87+
subscribe_url = models.CharField("Subscribe URL", blank=True, maxlength=255)
88+
subscribe_other = models.TextField("Subscribe Other", blank=True)
8689
# Can be 0, 1, -1, or what looks like a person_or_org_tag, positive or neg.
8790
# The values less than 1 don't get displayed on the list of lists.
8891
status = models.IntegerField()
89-
list_name = models.CharField("Mailing List Name", unique=True, maxlength=255)
90-
subscribe_url = models.CharField("Subscribe URL", blank=True, maxlength=255)
91-
subscribe_other = models.TextField("Subscribe Other", blank=True)
9292
ds_name = models.CharField(blank=True, maxlength=255)
93-
ds_email = models.CharField(blank=True, maxlength=255)
93+
ds_email = models.EmailField(blank=True, maxlength=255)
9494
msg_to_ad = models.TextField(blank=True)
9595
def __str__(self):
9696
return self.list_name

ietf/mailinglists/views.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,25 @@
1313
'msg_to_ad': None,
1414
}
1515

16+
nonwg_attrs = {
17+
's_name': {'size': 50},
18+
's_email': {'size': 50},
19+
'list_name': {'size': 80},
20+
}
21+
1622
nonwg_widgets = {
1723
'list_url': UrlMultiWidget(choices=(('http://', 'http://'), ('https://', 'https://'), ('mailto:', 'mailto:'))),
24+
'admin': forms.Textarea(attrs = {'rows': 3, 'cols': 50}),
25+
'purpose': forms.Textarea(attrs = {'rows': 4, 'cols': 70}),
1826
'subscribe_url': UrlMultiWidget(choices=(('n/a', 'Not Applicable'), ('http://', 'http://'), ('https://', 'https://'))),
27+
'subscribe_other': forms.Textarea(attrs = {'rows': 3, 'cols': 50}),
28+
}
29+
30+
nonwg_querysets = {
31+
'area': Areas.objects.filter(status=1)
1932
}
2033

21-
nonwg_callback = form_decorator(fields=nonwg_fields, widgets=nonwg_widgets)
34+
nonwg_callback = form_decorator(fields=nonwg_fields, widgets=nonwg_widgets, attrs=nonwg_attrs, querysets=nonwg_querysets)
2235

2336
def gen_approval(approvers, parent):
2437
class BoundApproval(parent):
@@ -28,13 +41,22 @@ def __init__(self, *args, **kwargs):
2841
return BoundApproval
2942

3043
class NonWgWizard(wizard.Wizard):
44+
form0 = None
3145
def get_template(self):
32-
return "mailinglists/nwg_wizard.html"
33-
def hash_failed(self, step):
46+
templates = []
47+
if self.form0:
48+
action = {'add': 'addedit', 'edit': 'addedit', 'delete': 'delete'}[self.form0.clean_data['add_edit']]
49+
templates.append("mailinglists/nwg_wizard_%s_step%d.html" % (action, self.step))
50+
templates.append("mailinglists/nwg_wizard_%s.html" % (action))
51+
templates.append("mailinglists/nwg_wizard_step%d.html" % (self.step))
52+
templates.append("mailinglists/nwg_wizard.html")
53+
return templates
54+
def failed_hash(self, step):
3455
raise NotImplementedError("step %d hash failed" % step)
3556
def process_step(self, request, form, step):
3657
form.full_clean()
3758
if step == 0:
59+
self.form0 = form
3860
if form.clean_data['add_edit'] == 'add':
3961
self.form_list.append(forms.form_for_model(NonWgMailingList, formfield_callback=nonwg_callback))
4062
elif form.clean_data['add_edit'] == 'edit':
@@ -45,6 +67,7 @@ def process_step(self, request, form, step):
4567
if step == 1:
4668
form0 = self.get_form(0, request.POST)
4769
form0.full_clean()
70+
self.form0 = form0
4871
add_edit = form0.clean_data['add_edit']
4972
if add_edit == 'add' or add_edit == 'edit':
5073
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):
5780
class ListReqWizard(wizard.Wizard):
5881
def get_template(self):
5982
return "mailinglists/nwg_wizard.html"
60-
def hash_failed(self, step):
61-
raise NotImplementedError("step %d hash failed" % step)
83+
# want to implement parse_params to get domain for list
6284
def process_step(self, request, form, step):
6385
form.full_clean()
6486
super(ListReqWizard, self).process_step(request, form, step)

ietf/templates/mailinglists/nwg_wizard.html

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
{% extends "base.html" %}
1+
{% extends "mailinglists/nwg_wizard_base.html" %}
22

3-
{% block css %}
4-
ul.errorlist { color: red; border: 1px solid red; }
5-
{% endblock %}
6-
7-
{% block content %}
3+
{% block nwgcontent %}
84
<form action="." method="POST">
95
FORM( {{ step }} ):<table> {{ form }} </table>
106

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{% extends "mailinglists/nwg_wizard_base.html" %}
2+
3+
{% block nwgcss %}
4+
tr > th { text-align: left; vertical-align: top; }
5+
{% endblock %}
6+
7+
{% block nwgcontent %}
8+
<h2>Step 2</h2>
9+
<h4>Please provide the following information:</h4>
10+
11+
<form action="." method="POST">
12+
<table bgcolor="#88AED2" cellspacing="1" border="0" width="714">
13+
<tr valign="top"><td>
14+
<table bgcolor="#f3f8fd" cellpadding="3" cellspacing="0" border="0">
15+
{{ form }}
16+
<tr>
17+
<td></td>
18+
<td>
19+
<input type="submit" value=" SUBMIT ">
20+
</td>
21+
</tr>
22+
</table>
23+
</td></tr>
24+
</table>
25+
{{ previous_fields }}
26+
<input type="hidden" name="{{ step_field }}" value="{{ step }}" />
27+
</form>
28+
{% endblock %}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{% extends "base.html" %}
2+
3+
{% block title %}IETF Non WG Mailing List Submit Form{% endblock %}
4+
5+
{% block css %}
6+
ul.errorlist { color: red; border: 1px solid red; }
7+
{% block nwgcss %}{% endblock %}
8+
{% endblock %}
9+
10+
{% block head %}
11+
<link rel="stylesheet" type="text/css" href="http://www.ietf.org/css/base.css" />
12+
{% endblock %}
13+
14+
{% block content %}
15+
<blockquote>
16+
<img src="/images/nwg/mail_title_submission.gif" border="0"><br>
17+
<img src="/images/nwg/t_un1.gif" border="0">
18+
<!-- form step {{ step }} -->
19+
<br>
20+
{% block nwgcontent %}
21+
form goes here
22+
{% endblock %}
23+
</blockquote>
24+
25+
{% endblock %}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{% extends "mailinglists/nwg_wizard_base.html" %}
2+
3+
{% block nwgcontent %}
4+
<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>
5+
<a href="/mailinglists/nonwg_lists/"><b>View Current list</b></a><br>
6+
7+
</p><p>
8+
<h2>Step 1</h2>
9+
<h3>Please select one:</h3>
10+
<form action="." method="POST">
11+
{{ form.add_edit_fields.0 }}<br>
12+
{{ form.add_edit_fields.1 }}{{ form.list_id }}<br>
13+
{{ form.add_edit_fields.2 }}{{ form.list_id_delete }}<br>
14+
<input type="submit" value=" Proceed ">
15+
<!--
16+
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;}">
17+
-->
18+
</form>
19+
{% endblock %}

0 commit comments

Comments
 (0)