Skip to content

Commit b8aa94d

Browse files
committed
Add preview and done to NonWgWizard.
- Legacy-Id: 161
1 parent 0ceb9e2 commit b8aa94d

6 files changed

Lines changed: 120 additions & 10 deletions

File tree

ietf/mailinglists/forms.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ def format_output(self, rendered_widgets):
8989

9090
# If we have two widgets, return the concatenation of the values
9191
# (Except, if _0 is "n/a" then return an empty string)
92+
# _0 might not exist if no radio button is selected (i.e., an
93+
# empty form), so return empty string.
9294
# Otherwise, just return the value.
9395
def value_from_datadict(self, data, name):
9496
try:
@@ -97,7 +99,10 @@ def value_from_datadict(self, data, name):
9799
return ''
98100
return scheme + data[name + '_1']
99101
except KeyError:
100-
return data[name]
102+
try:
103+
return data[name]
104+
except KeyError:
105+
return ''
101106

102107
class PickApprover(forms.Form):
103108
"""
@@ -114,3 +119,7 @@ class DeletionPickApprover(PickApprover):
114119
ds_name = forms.CharField(label = 'Enter your name', widget = forms.TextInput(attrs = {'size': 45}))
115120
ds_email = forms.EmailField(label = 'Enter your email', widget = forms.TextInput(attrs = {'size': 45}))
116121
msg_to_ad = forms.CharField(label = 'Message to the Area Director', widget = forms.Textarea(attrs = {'rows': 5, 'cols': 50}))
122+
123+
# A form with no required fields, to allow a preview action
124+
class Preview(forms.Form):
125+
preview = forms.BooleanField(required=False)

ietf/mailinglists/views.py

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1-
from forms import NonWgStep1, ListReqStep1, PickApprover, DeletionPickApprover, UrlMultiWidget
1+
from forms import NonWgStep1, ListReqStep1, PickApprover, DeletionPickApprover, UrlMultiWidget, Preview
22
from models import NonWgMailingList
3-
from ietf.idtracker.models import Areas
3+
from ietf.idtracker.models import Areas, PersonOrOrgInfo
44
from django import newforms as forms
55
from django.shortcuts import render_to_response
6+
from django.template import RequestContext
67
from ietf.contrib import wizard, form_decorator
8+
from ietf.utils.mail import send_mail
9+
10+
def formchoice(form, field):
11+
if not(form.is_valid()):
12+
return None
13+
d = str(form.clean_data[field])
14+
for k, v in form.fields[field].choices:
15+
if str(k) == d:
16+
return v
17+
# oddly, one of the forms stores the translated value
18+
# in clean_data; the other stores the key. This second
19+
# if wouldn't be needed if both stored the key.
20+
# This whole function wouldn't be needed if both stored
21+
# the value.
22+
if str(v) == d:
23+
return v
24+
return None
725

826
nonwg_fields = {
927
'id': None,
@@ -41,37 +59,64 @@ def __init__(self, *args, **kwargs):
4159
return BoundApproval
4260

4361
class NonWgWizard(wizard.Wizard):
44-
form0 = None
62+
clean_forms = []
4563
def get_template(self):
4664
templates = []
47-
if self.form0:
48-
action = {'add': 'addedit', 'edit': 'addedit', 'delete': 'delete'}[self.form0.clean_data['add_edit']]
65+
if self.step > 0:
66+
action = {'add': 'addedit', 'edit': 'addedit', 'delete': 'delete'}[self.clean_forms[0].clean_data['add_edit']]
4967
templates.append("mailinglists/nwg_wizard_%s_step%d.html" % (action, self.step))
5068
templates.append("mailinglists/nwg_wizard_%s.html" % (action))
5169
templates.append("mailinglists/nwg_wizard_step%d.html" % (self.step))
5270
templates.append("mailinglists/nwg_wizard.html")
5371
return templates
72+
def render_template(self, *args, **kwargs):
73+
self.extra_context['clean_forms'] = self.clean_forms
74+
if self.step == 3:
75+
form0 = self.clean_forms[0]
76+
add_edit = form0.clean_data['add_edit']
77+
if add_edit == 'add' or add_edit == 'edit':
78+
# Can't get the choice mapping directly from the form
79+
self.extra_context['area'] = formchoice(self.clean_forms[1], 'area')
80+
self.extra_context['approver'] = formchoice(self.clean_forms[2], 'approver')
81+
print "formchoice for area = %s" % formchoice(self.clean_forms[1], 'area')
82+
else:
83+
print "add_edit = %s" % add_edit
84+
return super(NonWgWizard, self).render_template(*args, **kwargs)
5485
def failed_hash(self, step):
5586
raise NotImplementedError("step %d hash failed" % step)
5687
def process_step(self, request, form, step):
5788
form.full_clean()
5889
if step == 0:
59-
self.form0 = form
90+
self.clean_forms = [ form ]
6091
if form.clean_data['add_edit'] == 'add':
6192
self.form_list.append(forms.form_for_model(NonWgMailingList, formfield_callback=nonwg_callback))
6293
elif form.clean_data['add_edit'] == 'edit':
6394
self.form_list.append(forms.form_for_instance(NonWgMailingList.objects.get(pk=form.clean_data['list_id']), formfield_callback=nonwg_callback))
6495
elif form.clean_data['add_edit'] == 'delete':
6596
list = NonWgMailingList.objects.get(pk=form.clean_data['list_id_delete'])
6697
self.form_list.append(gen_approval([ad.person_id for ad in list.area.areadirectors_set.all()], DeletionPickApprover))
98+
self.form_list.append(Preview)
99+
else:
100+
self.clean_forms.append(form)
67101
if step == 1:
68-
form0 = self.get_form(0, request.POST)
69-
form0.full_clean()
70-
self.form0 = form0
102+
form0 = self.clean_forms[0]
71103
add_edit = form0.clean_data['add_edit']
72104
if add_edit == 'add' or add_edit == 'edit':
73105
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))
106+
self.form_list.append(Preview)
74107
super(NonWgWizard, self).process_step(request, form, step)
108+
def done(self, request, form_list):
109+
add_edit = self.clean_forms[0].clean_data['add_edit']
110+
# save row to database properly
111+
if add_edit == 'add' or add_edit == 'edit':
112+
template = 'mailinglists/nwg_addedit_email.txt'
113+
approver = self.clean_forms[2].clean_data['approver']
114+
else:
115+
template = 'mailinglists/nwg_delete_email.txt'
116+
approver = self.clean_forms[1].clean_data['approver']
117+
approver_email = PersonOrOrgInfo.objects.get(pk=approver).email()
118+
send_mail(request, [ approver_email ], None, 'Request to %s on the Non-WG Mailing List Web Page' % add_edit, template, {'forms': self.clean_forms})
119+
return render_to_response( 'mailinglists/nwg_wizard_done.html', {'forms': self.clean_forms}, context_instance=RequestContext(request) )
75120

76121
def non_wg_wizard(request):
77122
wiz = NonWgWizard([ NonWgStep1 ])
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This is a request to add or edit a non-wg list.
2+
3+
I got {{ forms }}
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This is a request to delete a non-wg list.
2+
3+
I got {{ forms }}
4+

ietf/templates/mailinglists/nwg_wizard.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@
1111
<input type="submit">
1212
</form>
1313

14+
clean_forms: {{ clean_forms|escape }}
15+
1416
{% endblock %}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{% extends "mailinglists/nwg_wizard_base.html" %}
2+
3+
{% block nwgcontent %}
4+
<h2>Step 4</h2>
5+
<h4>Please verify the following information:</h4>
6+
<form action="." method="POST">
7+
<table bgcolor="#88AED2" cellspacing="1" border="0">
8+
<tr valign="top"><td>
9+
<table bgcolor="#f3f8fd" cellpadding="3" cellspacing="0" border="0">
10+
<tr valign="top">
11+
<td colspan=2>
12+
<h3>Request Submit Confirmation</h3>
13+
Please review the following information that you are about to submit.<br>
14+
Once you click the 'Submit' button below, this request will be sent to
15+
the selected Area Director for approval.<br>
16+
<br>
17+
</td>
18+
</tr>
19+
<tr valign="top"><td>Request Type:</td><td>
20+
{% ifequal clean_forms.0.add_edit "add" %}
21+
Adding a new entry
22+
{% else %}
23+
Editing an existing entry
24+
{% endifequal %}</td></tr>
25+
<tr valign="top"><td>Submitter's Name:</td><td>{{ clean_forms.1.s_name.data|escape }}</td></tr>
26+
<tr valign="top"><td>Submitter's Email Address:</td><td>{{ clean_forms.1.s_email.data|escape }}</td></tr>
27+
<tr valign="top"><td>Mailing List Name:</td><td>{{ clean_forms.1.list_name.data|escape }}</td></tr>
28+
<tr valign="top"><td>URL or Email Address of Mailing List: </td><td><pre>{{ clean_forms.1.list_url.data|escape }}</pre></td></tr>
29+
<tr valign="top"><td>URL to Subscribe: </td><td><pre>{% firstof clean_forms.1.subscribe_url.data "Not Applicable" %}</pre></td></tr>
30+
<tr valign="top"><td>Other Info. to Subscribe: </td><td><pre>{{ clean_forms.1.subscribe_other.data|escape }}</pre></td></tr>
31+
<tr valign="top"><td>Administrator(s)' Email Address(es): </td><td><pre>{{ clean_forms.1.admin.data|escape|linebreaks }}</pre></td></tr>
32+
<tr valign="top"><td>Purpose: </td><td>{{ clean_forms.1.purpose.data|escape }}</td></tr>
33+
<tr valign="top"><td>Area: </td><td><pre>{{ area }}</pre></td></tr>
34+
<tr valign="top"><td>Approving Area Director: </td><td><pre>{{ approver|escape }}</pre></td></tr>
35+
<tr valign="top">
36+
<td></td>
37+
<td>
38+
<input type="submit" value=" Submit ">
39+
</td>
40+
</tr>
41+
</table>
42+
</table>
43+
{{ previous_fields }}
44+
<input type="hidden" name="{{ step_field }}" value="{{ step }}" />
45+
</form>
46+
{% endblock %}

0 commit comments

Comments
 (0)