diff --git a/ietf/mailinglists/models.py b/ietf/mailinglists/models.py index f3007c6fc..e5f62984a 100644 --- a/ietf/mailinglists/models.py +++ b/ietf/mailinglists/models.py @@ -1,5 +1,6 @@ from django.db import models from ietf.idtracker.models import Acronym, Areas, PersonOrOrgInfo +import random class ImportedMailingList(models.Model): group_acronym = models.ForeignKey(Acronym, null=True) @@ -70,6 +71,16 @@ class MailingList(models.Model): domain_name = models.CharField(blank=True, maxlength=10) def __str__(self): return self.mlist_name + def save(self, *args, **kwargs): + if self.mailing_list_id is None: + generate = True + while generate: + self.mailing_list_id = ''.join([random.choice('0123456789abcdefghijklmnopqrstuvwxyz') for i in range(35)]) + try: + MailingList.objects.get(pk=self.mailing_list_id) + except MailingList.DoesNotExist: + generate = False + super(MailingList, self).save(*args, **kwargs) class Meta: db_table = 'mailing_list' class Admin: @@ -94,6 +105,16 @@ class NonWgMailingList(models.Model): msg_to_ad = models.TextField(blank=True) def __str__(self): return self.list_name + def save(self, *args, **kwargs): + if self.id is None: + generate = True + while generate: + self.id = ''.join([random.choice('0123456789abcdefghijklmnopqrstuvwxyz') for i in range(35)]) + try: + NonWgMailingList.objects.get(pk=self.id) + except NonWgMailingList.DoesNotExist: + generate = False + super(NonWgMailingList, self).save(*args, **kwargs) def choices(): return [(list.id, list.list_name) for list in NonWgMailingList.objects.all().filter(status__gt=0)] choices = staticmethod(choices) diff --git a/ietf/mailinglists/urls.py b/ietf/mailinglists/urls.py index c5d6b5580..f12942a7d 100644 --- a/ietf/mailinglists/urls.py +++ b/ietf/mailinglists/urls.py @@ -11,5 +11,4 @@ urlpatterns = patterns('django.views.generic.list_detail', urlpatterns += patterns('', (r'^nonwg_lists/submit/$', views.non_wg_wizard), (r'^request/$', views.list_req_wizard), - (r'^nonwg_lists/s2/$', views.non_wg_submit), ) diff --git a/ietf/mailinglists/views.py b/ietf/mailinglists/views.py index 9f50763cd..12134045d 100644 --- a/ietf/mailinglists/views.py +++ b/ietf/mailinglists/views.py @@ -5,7 +5,7 @@ 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 +from ietf.utils.mail import send_mail_subj def formchoice(form, field): if not(form.is_valid()): @@ -107,15 +107,26 @@ class NonWgWizard(wizard.Wizard): 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 + list = None + old = None if add_edit == 'add' or add_edit == 'edit': template = 'mailinglists/nwg_addedit_email.txt' approver = self.clean_forms[2].clean_data['approver'] + list = NonWgMailingList(**self.clean_forms[1].clean_data) + list.__dict__.update(self.clean_forms[2].clean_data) + list.id = None # create a new row no matter what + list.status = 0 + if add_edit == 'edit': + old = NonWgMailingList.objects.get(pk=self.clean_forms[0].clean_data['list_id']) else: template = 'mailinglists/nwg_delete_email.txt' approver = self.clean_forms[1].clean_data['approver'] + list = NonWgMailingList.objects.get(pk=self.clean_forms[0].clean_data['list_id_delete']) + list.__dict__.update(self.clean_forms[1].clean_data) + list.status = 1 + list.save() 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}) + send_mail_subj(request, [ approver_email ], None, 'mailinglists/nwg_wizard_subject.txt', 'mailinglists/nwg_wizard_done_email.txt', {'add_edit': add_edit, 'old': old, 'list': list, '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): diff --git a/ietf/templates/mailinglists/nwg_wizard_done.html b/ietf/templates/mailinglists/nwg_wizard_done.html new file mode 100644 index 000000000..507f2dc8a --- /dev/null +++ b/ietf/templates/mailinglists/nwg_wizard_done.html @@ -0,0 +1,5 @@ +{% extends "mailinglists/nwg_wizard_base.html" %} + +{% block nwgcontent %} +Your mail has been sent, blah blah blah. +{% endblock %} diff --git a/ietf/templates/mailinglists/nwg_wizard_done_email.txt b/ietf/templates/mailinglists/nwg_wizard_done_email.txt new file mode 100644 index 000000000..61c6361af --- /dev/null +++ b/ietf/templates/mailinglists/nwg_wizard_done_email.txt @@ -0,0 +1,36 @@ +The Secretariat has received a request to {% ifequal add_edit "edit" %}edit an existing entry on{% else %}{% ifequal add_edit "add" %}add a new entry to{% else %}delete an existing entry from{% endifequal %}{% endifequal %} +the "IETF Non-WG Mailing Lists" Web Page, https://datatracker.ietf.org/public/nwg_list.cgi +The details of the request are provided below. + +Please approve or deny this request via the "IETF Non-WG Mailing List Approval Page," +https://datatracker.ietf.org/cgi-bin/nwg_list_approve.cgi?id={{ list.id }}&old_id={% firstof old.id "0" %} +You can use the same user name and password that you use with the I-D Tracker. +------------------------- +{% if old %} +Current Entry: + +Submitter's Name: {{ old.s_name }} +Submitter's Email Address: {{ old.s_email }} +List Name: {{ old.list_name }} +URL or Email Address of Mailing List: {{ old.list_url }} +URL to Subscribe: {{ old.subscribe_url }} +Other Info. to Subscribe: {{ old.subscribe_other }} +Administrator(s)' Email Address(es): {{ old.admin }} +Purpose: {{ old.purpose }} +Area: {{ old.area }} + +Revised Entry: +{% endif %} +Submitter's Name: {% ifequal add_edit "delete" %}{{ list.ds_name }}{% else %}{{ list.s_name }}{% endifequal %} +Submitter's Email Address: {% ifequal add_edit "delete" %}{{ list.ds_name }}{% else %}{{ list.s_email }}{% endifequal %} +Mailing List Name: {{ list.list_name }} +URL or Email Address of Mailing List: {{ list.list_url }} +URL to Subscribe: {{ list.subscribe_url }} +Other Info. to Subscribe: {{ list.subscribe_other }} +Administrator(s)' Email Address(es): {{ list.admin }} +Purpose: {{ list.purpose }} +Area: {{ list.area }} +{% ifequal add_edit "delete" %} +Message from submitter: +{{ list.msg_to_ad }} +{% endifequal %} diff --git a/ietf/templates/mailinglists/nwg_wizard_subject.txt b/ietf/templates/mailinglists/nwg_wizard_subject.txt new file mode 100644 index 000000000..8a6331bb8 --- /dev/null +++ b/ietf/templates/mailinglists/nwg_wizard_subject.txt @@ -0,0 +1,9 @@ +{% ifequal add_edit "edit" %} +Request to Edit an Existing Entry on the Non-WG Mailing List Web Page +{% else %} + {% ifequal add_edit "add" %} + Request to Add a New Entry to the Non-WG Mailing List Web Page + {% else %} + Request to Delete an Existing Entry on the Non-WG Mailing List Web Page + {% endifequal %} +{% endifequal %}