From b8aa94d0070dcf63192d2050f422844342d85657 Mon Sep 17 00:00:00 2001 From: Bill Fenner Date: Thu, 24 May 2007 17:29:05 +0000 Subject: [PATCH] Add preview and done to NonWgWizard. - Legacy-Id: 161 --- ietf/mailinglists/forms.py | 11 +++- ietf/mailinglists/views.py | 63 ++++++++++++++++--- .../mailinglists/nwg_addedit_email.txt | 4 ++ .../mailinglists/nwg_delete_email.txt | 4 ++ ietf/templates/mailinglists/nwg_wizard.html | 2 + .../nwg_wizard_addedit_step3.html | 46 ++++++++++++++ 6 files changed, 120 insertions(+), 10 deletions(-) create mode 100644 ietf/templates/mailinglists/nwg_addedit_email.txt create mode 100644 ietf/templates/mailinglists/nwg_delete_email.txt create mode 100644 ietf/templates/mailinglists/nwg_wizard_addedit_step3.html diff --git a/ietf/mailinglists/forms.py b/ietf/mailinglists/forms.py index 812a92242..3f6b5cc21 100644 --- a/ietf/mailinglists/forms.py +++ b/ietf/mailinglists/forms.py @@ -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) diff --git a/ietf/mailinglists/views.py b/ietf/mailinglists/views.py index edaf16db3..9f50763cd 100644 --- a/ietf/mailinglists/views.py +++ b/ietf/mailinglists/views.py @@ -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 ]) diff --git a/ietf/templates/mailinglists/nwg_addedit_email.txt b/ietf/templates/mailinglists/nwg_addedit_email.txt new file mode 100644 index 000000000..98536980f --- /dev/null +++ b/ietf/templates/mailinglists/nwg_addedit_email.txt @@ -0,0 +1,4 @@ +This is a request to add or edit a non-wg list. + +I got {{ forms }} + diff --git a/ietf/templates/mailinglists/nwg_delete_email.txt b/ietf/templates/mailinglists/nwg_delete_email.txt new file mode 100644 index 000000000..b5f2dd99e --- /dev/null +++ b/ietf/templates/mailinglists/nwg_delete_email.txt @@ -0,0 +1,4 @@ +This is a request to delete a non-wg list. + +I got {{ forms }} + diff --git a/ietf/templates/mailinglists/nwg_wizard.html b/ietf/templates/mailinglists/nwg_wizard.html index fd0585254..47147f9ed 100644 --- a/ietf/templates/mailinglists/nwg_wizard.html +++ b/ietf/templates/mailinglists/nwg_wizard.html @@ -11,4 +11,6 @@ +clean_forms: {{ clean_forms|escape }} + {% endblock %} diff --git a/ietf/templates/mailinglists/nwg_wizard_addedit_step3.html b/ietf/templates/mailinglists/nwg_wizard_addedit_step3.html new file mode 100644 index 000000000..158bfa096 --- /dev/null +++ b/ietf/templates/mailinglists/nwg_wizard_addedit_step3.html @@ -0,0 +1,46 @@ +{% extends "mailinglists/nwg_wizard_base.html" %} + +{% block nwgcontent %} +

Step 4

+

Please verify the following information:

+
+ +
+ + + + + + + + + + + + + + + + + + + +
+

Request Submit Confirmation

+Please review the following information that you are about to submit.
+Once you click the 'Submit' button below, this request will be sent to +the selected Area Director for approval.
+
+
Request Type: +{% ifequal clean_forms.0.add_edit "add" %} +Adding a new entry +{% else %} +Editing an existing entry +{% endifequal %}
Submitter's Name:{{ clean_forms.1.s_name.data|escape }}
Submitter's Email Address:{{ clean_forms.1.s_email.data|escape }}
Mailing List Name:{{ clean_forms.1.list_name.data|escape }}
URL or Email Address of Mailing List:
{{ clean_forms.1.list_url.data|escape }}
URL to Subscribe:
{% firstof clean_forms.1.subscribe_url.data "Not Applicable" %}
Other Info. to Subscribe:
{{ clean_forms.1.subscribe_other.data|escape }}
Administrator(s)' Email Address(es):
{{ clean_forms.1.admin.data|escape|linebreaks }}
Purpose: {{ clean_forms.1.purpose.data|escape }}
Area:
{{ area }}
Approving Area Director:
{{ approver|escape }}
+ +
+
+{{ previous_fields }} + +
+{% endblock %}