Add preview and done to NonWgWizard.

- Legacy-Id: 161
This commit is contained in:
Bill Fenner 2007-05-24 17:29:05 +00:00
parent 0ceb9e2b0c
commit b8aa94d007
6 changed files with 120 additions and 10 deletions

View file

@ -89,6 +89,8 @@ class UrlMultiWidget(forms.MultiWidget):
# If we have two widgets, return the concatenation of the values
# (Except, if _0 is "n/a" then return an empty string)
# _0 might not exist if no radio button is selected (i.e., an
# empty form), so return empty string.
# Otherwise, just return the value.
def value_from_datadict(self, data, name):
try:
@ -97,7 +99,10 @@ class UrlMultiWidget(forms.MultiWidget):
return ''
return scheme + data[name + '_1']
except KeyError:
return data[name]
try:
return data[name]
except KeyError:
return ''
class PickApprover(forms.Form):
"""
@ -114,3 +119,7 @@ class DeletionPickApprover(PickApprover):
ds_name = forms.CharField(label = 'Enter your name', widget = forms.TextInput(attrs = {'size': 45}))
ds_email = forms.EmailField(label = 'Enter your email', widget = forms.TextInput(attrs = {'size': 45}))
msg_to_ad = forms.CharField(label = 'Message to the Area Director', widget = forms.Textarea(attrs = {'rows': 5, 'cols': 50}))
# A form with no required fields, to allow a preview action
class Preview(forms.Form):
preview = forms.BooleanField(required=False)

View file

@ -1,9 +1,27 @@
from forms import NonWgStep1, ListReqStep1, PickApprover, DeletionPickApprover, UrlMultiWidget
from forms import NonWgStep1, ListReqStep1, PickApprover, DeletionPickApprover, UrlMultiWidget, Preview
from models import NonWgMailingList
from ietf.idtracker.models import Areas
from ietf.idtracker.models import Areas, PersonOrOrgInfo
from django import newforms as forms
from django.shortcuts import render_to_response
from django.template import RequestContext
from ietf.contrib import wizard, form_decorator
from ietf.utils.mail import send_mail
def formchoice(form, field):
if not(form.is_valid()):
return None
d = str(form.clean_data[field])
for k, v in form.fields[field].choices:
if str(k) == d:
return v
# oddly, one of the forms stores the translated value
# in clean_data; the other stores the key. This second
# if wouldn't be needed if both stored the key.
# This whole function wouldn't be needed if both stored
# the value.
if str(v) == d:
return v
return None
nonwg_fields = {
'id': None,
@ -41,22 +59,35 @@ def gen_approval(approvers, parent):
return BoundApproval
class NonWgWizard(wizard.Wizard):
form0 = None
clean_forms = []
def get_template(self):
templates = []
if self.form0:
action = {'add': 'addedit', 'edit': 'addedit', 'delete': 'delete'}[self.form0.clean_data['add_edit']]
if self.step > 0:
action = {'add': 'addedit', 'edit': 'addedit', 'delete': 'delete'}[self.clean_forms[0].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 render_template(self, *args, **kwargs):
self.extra_context['clean_forms'] = self.clean_forms
if self.step == 3:
form0 = self.clean_forms[0]
add_edit = form0.clean_data['add_edit']
if add_edit == 'add' or add_edit == 'edit':
# Can't get the choice mapping directly from the form
self.extra_context['area'] = formchoice(self.clean_forms[1], 'area')
self.extra_context['approver'] = formchoice(self.clean_forms[2], 'approver')
print "formchoice for area = %s" % formchoice(self.clean_forms[1], 'area')
else:
print "add_edit = %s" % add_edit
return super(NonWgWizard, self).render_template(*args, **kwargs)
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
self.clean_forms = [ 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':
@ -64,14 +95,28 @@ class NonWgWizard(wizard.Wizard):
elif form.clean_data['add_edit'] == 'delete':
list = NonWgMailingList.objects.get(pk=form.clean_data['list_id_delete'])
self.form_list.append(gen_approval([ad.person_id for ad in list.area.areadirectors_set.all()], DeletionPickApprover))
self.form_list.append(Preview)
else:
self.clean_forms.append(form)
if step == 1:
form0 = self.get_form(0, request.POST)
form0.full_clean()
self.form0 = form0
form0 = self.clean_forms[0]
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))
self.form_list.append(Preview)
super(NonWgWizard, self).process_step(request, form, step)
def done(self, request, form_list):
add_edit = self.clean_forms[0].clean_data['add_edit']
# save row to database properly
if add_edit == 'add' or add_edit == 'edit':
template = 'mailinglists/nwg_addedit_email.txt'
approver = self.clean_forms[2].clean_data['approver']
else:
template = 'mailinglists/nwg_delete_email.txt'
approver = self.clean_forms[1].clean_data['approver']
approver_email = PersonOrOrgInfo.objects.get(pk=approver).email()
send_mail(request, [ approver_email ], None, 'Request to %s on the Non-WG Mailing List Web Page' % add_edit, template, {'forms': self.clean_forms})
return render_to_response( 'mailinglists/nwg_wizard_done.html', {'forms': self.clean_forms}, context_instance=RequestContext(request) )
def non_wg_wizard(request):
wiz = NonWgWizard([ NonWgStep1 ])

View file

@ -0,0 +1,4 @@
This is a request to add or edit a non-wg list.
I got {{ forms }}

View file

@ -0,0 +1,4 @@
This is a request to delete a non-wg list.
I got {{ forms }}

View file

@ -11,4 +11,6 @@
<input type="submit">
</form>
clean_forms: {{ clean_forms|escape }}
{% endblock %}

View file

@ -0,0 +1,46 @@
{% extends "mailinglists/nwg_wizard_base.html" %}
{% block nwgcontent %}
<h2>Step 4</h2>
<h4>Please verify the following information:</h4>
<form action="." method="POST">
<table bgcolor="#88AED2" cellspacing="1" border="0">
<tr valign="top"><td>
<table bgcolor="#f3f8fd" cellpadding="3" cellspacing="0" border="0">
<tr valign="top">
<td colspan=2>
<h3>Request Submit Confirmation</h3>
Please review the following information that you are about to submit.<br>
Once you click the 'Submit' button below, this request will be sent to
the selected Area Director for approval.<br>
<br>
</td>
</tr>
<tr valign="top"><td>Request Type:</td><td>
{% ifequal clean_forms.0.add_edit "add" %}
Adding a new entry
{% else %}
Editing an existing entry
{% endifequal %}</td></tr>
<tr valign="top"><td>Submitter's Name:</td><td>{{ clean_forms.1.s_name.data|escape }}</td></tr>
<tr valign="top"><td>Submitter's Email Address:</td><td>{{ clean_forms.1.s_email.data|escape }}</td></tr>
<tr valign="top"><td>Mailing List Name:</td><td>{{ clean_forms.1.list_name.data|escape }}</td></tr>
<tr valign="top"><td>URL or Email Address of Mailing List: </td><td><pre>{{ clean_forms.1.list_url.data|escape }}</pre></td></tr>
<tr valign="top"><td>URL to Subscribe: </td><td><pre>{% firstof clean_forms.1.subscribe_url.data "Not Applicable" %}</pre></td></tr>
<tr valign="top"><td>Other Info. to Subscribe: </td><td><pre>{{ clean_forms.1.subscribe_other.data|escape }}</pre></td></tr>
<tr valign="top"><td>Administrator(s)' Email Address(es): </td><td><pre>{{ clean_forms.1.admin.data|escape|linebreaks }}</pre></td></tr>
<tr valign="top"><td>Purpose: </td><td>{{ clean_forms.1.purpose.data|escape }}</td></tr>
<tr valign="top"><td>Area: </td><td><pre>{{ area }}</pre></td></tr>
<tr valign="top"><td>Approving Area Director: </td><td><pre>{{ approver|escape }}</pre></td></tr>
<tr valign="top">
<td></td>
<td>
<input type="submit" value=" Submit ">
</td>
</tr>
</table>
</table>
{{ previous_fields }}
<input type="hidden" name="{{ step_field }}" value="{{ step }}" />
</form>
{% endblock %}