]> git.ozlabs.org Git - patchwork/commitdiff
Merge branch 'notifications'
authorJeremy Kerr <jk@ozlabs.org>
Mon, 19 Sep 2011 01:42:44 +0000 (09:42 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Mon, 19 Sep 2011 01:42:44 +0000 (09:42 +0800)
52 files changed:
apps/patchwork/bin/patchwork-cron.py [new file with mode: 0755]
apps/patchwork/forms.py
apps/patchwork/models.py
apps/patchwork/tests/__init__.py
apps/patchwork/tests/confirm.py [new file with mode: 0644]
apps/patchwork/tests/mail_settings.py [new file with mode: 0644]
apps/patchwork/tests/notifications.py [new file with mode: 0644]
apps/patchwork/tests/registration.py [new file with mode: 0644]
apps/patchwork/tests/user.py [new file with mode: 0644]
apps/patchwork/tests/utils.py
apps/patchwork/urls.py
apps/patchwork/utils.py
apps/patchwork/views/base.py
apps/patchwork/views/mail.py [new file with mode: 0644]
apps/patchwork/views/user.py
apps/settings.py
apps/urls.py
docs/INSTALL
lib/sql/grant-all.mysql.sql
lib/sql/grant-all.postgres.sql
lib/sql/migration/008-confirmations.sql [new file with mode: 0644]
lib/sql/migration/009-drop-registrationprofile.sql [new file with mode: 0644]
lib/sql/migration/010-optout-tables.sql [new file with mode: 0644]
lib/sql/migration/011-patch-change-notifications.sql [new file with mode: 0644]
templates/base.html
templates/patchwork/activation_email.txt [new file with mode: 0644]
templates/patchwork/activation_email_subject.txt [new file with mode: 0644]
templates/patchwork/confirm-error.html [new file with mode: 0644]
templates/patchwork/help/about.html
templates/patchwork/login.html [new file with mode: 0644]
templates/patchwork/logout.html [new file with mode: 0644]
templates/patchwork/mail-form.html [new file with mode: 0644]
templates/patchwork/mail-settings.html [new file with mode: 0644]
templates/patchwork/optin-request.html [new file with mode: 0644]
templates/patchwork/optin-request.mail [new file with mode: 0644]
templates/patchwork/optin.html [new file with mode: 0644]
templates/patchwork/optout-request.html [new file with mode: 0644]
templates/patchwork/optout-request.mail [new file with mode: 0644]
templates/patchwork/optout.html [new file with mode: 0644]
templates/patchwork/patch-change-notification-subject.text [new file with mode: 0644]
templates/patchwork/patch-change-notification.mail [new file with mode: 0644]
templates/patchwork/profile.html
templates/patchwork/registration-confirm.html [new file with mode: 0644]
templates/patchwork/registration_form.html [new file with mode: 0644]
templates/patchwork/user-link.mail
templates/registration/activate.html [deleted file]
templates/registration/activation_email.txt [deleted file]
templates/registration/activation_email_subject.txt [deleted file]
templates/registration/login.html [deleted file]
templates/registration/logout.html [deleted file]
templates/registration/registration_complete.html [deleted file]
templates/registration/registration_form.html [deleted file]

diff --git a/apps/patchwork/bin/patchwork-cron.py b/apps/patchwork/bin/patchwork-cron.py
new file mode 100755 (executable)
index 0000000..e9bd0c1
--- /dev/null
@@ -0,0 +1,13 @@
+#!/usr/bin/env python
+
+import sys
+from patchwork.utils import send_notifications
+
+def main(args):
+    errors = send_notifications()
+    for (recipient, error) in errors:
+        print "Failed sending to %s: %s" % (recipient.email, ex)
+
+if __name__ == '__main__':
+    sys.exit(main(sys.argv))
+
index 1ff2bd0088c765711a26c176f652337409bc4d56..d5e51a2c8b9dfcc52954b13e95bb3d774f0b03c2 100644 (file)
@@ -22,34 +22,33 @@ from django.contrib.auth.models import User
 from django import forms
 
 from patchwork.models import Patch, State, Bundle, UserProfile
-from registration.forms import RegistrationFormUniqueEmail
-from registration.models import RegistrationProfile
 
-class RegistrationForm(RegistrationFormUniqueEmail):
+class RegistrationForm(forms.Form):
     first_name = forms.CharField(max_length = 30, required = False)
     last_name = forms.CharField(max_length = 30, required = False)
-    username = forms.CharField(max_length=30, label=u'Username')
+    username = forms.RegexField(regex = r'^\w+$', max_length=30,
+                                label=u'Username')
     email = forms.EmailField(max_length=100, label=u'Email address')
     password = forms.CharField(widget=forms.PasswordInput(),
                                 label='Password')
-    password1 = forms.BooleanField(required = False)
-    password2 = forms.BooleanField(required = False)
 
-    def save(self, profile_callback = None):
-        user = RegistrationProfile.objects.create_inactive_user( \
-                username = self.cleaned_data['username'],
-                password = self.cleaned_data['password'],
-                email = self.cleaned_data['email'],
-                profile_callback = profile_callback)
-        user.first_name = self.cleaned_data.get('first_name', '')
-        user.last_name = self.cleaned_data.get('last_name', '')
-        user.save()
-
-        # saving the userprofile causes the firstname/lastname to propagate
-        # to the person objects.
-        user.get_profile().save()
-
-        return user
+    def clean_username(self):
+        value = self.cleaned_data['username']
+        try:
+            user = User.objects.get(username__iexact = value)
+        except User.DoesNotExist:
+            return self.cleaned_data['username']
+        raise forms.ValidationError('This username is already taken. ' + \
+                                    'Please choose another.')
+
+    def clean_email(self):
+        value = self.cleaned_data['email']
+        try:
+            user = User.objects.get(email__iexact = value)
+        except User.DoesNotExist:
+            return self.cleaned_data['email']
+        raise forms.ValidationError('This email address is already in use ' + \
+                                    'for the account "%s".\n' % user.username)
 
     def clean(self):
         return self.cleaned_data
@@ -228,5 +227,8 @@ class MultiplePatchForm(forms.Form):
             instance.save()
         return instance
 
-class UserPersonLinkForm(forms.Form):
+class EmailForm(forms.Form):
     email = forms.EmailField(max_length = 200)
+
+UserPersonLinkForm = EmailForm
+OptinoutRequestForm = EmailForm
index 6c8fc7191cbd5e5712da07e95333999a8e83c18d..22062c2189f468eb20e4b8ad2ff1f9e1a16b3632 100644 (file)
@@ -21,6 +21,7 @@ from django.db import models
 from django.contrib.auth.models import User
 from django.core.urlresolvers import reverse
 from django.contrib.sites.models import Site
+from django.conf import settings
 from patchwork.parser import hash_patch
 
 import re
@@ -63,6 +64,7 @@ class Project(models.Model):
     name = models.CharField(max_length=255, unique=True)
     listid = models.CharField(max_length=255, unique=True)
     listemail = models.CharField(max_length=200)
+    send_notifications = models.BooleanField()
 
     def __unicode__(self):
         return self.name
@@ -373,34 +375,83 @@ class BundlePatch(models.Model):
         unique_together = [('bundle', 'patch')]
         ordering = ['order']
 
-class UserPersonConfirmation(models.Model):
-    user = models.ForeignKey(User)
+class EmailConfirmation(models.Model):
+    validity = datetime.timedelta(days = settings.CONFIRMATION_VALIDITY_DAYS)
+    type = models.CharField(max_length = 20, choices = [
+                                ('userperson', 'User-Person association'),
+                                ('registration', 'Registration'),
+                                ('optout', 'Email opt-out'),
+                            ])
     email = models.CharField(max_length = 200)
+    user = models.ForeignKey(User, null = True)
     key = HashField()
-    date = models.DateTimeField(default=datetime.datetime.now)
+    date = models.DateTimeField(default = datetime.datetime.now)
     active = models.BooleanField(default = True)
 
-    def confirm(self):
-        if not self.active:
-            return
-        person = None
-        try:
-            person = Person.objects.get(email__iexact = self.email)
-        except Exception:
-            pass
-        if not person:
-            person = Person(email = self.email)
-
-        person.link_to_user(self.user)
-        person.save()
+    def deactivate(self):
         self.active = False
         self.save()
 
+    def is_valid(self):
+        return self.date + self.validity > datetime.datetime.now()
+
     def save(self):
         max = 1 << 32
         if self.key == '':
             str = '%s%s%d' % (self.user, self.email, random.randint(0, max))
             self.key = self._meta.get_field('key').construct(str).hexdigest()
-        super(UserPersonConfirmation, self).save()
+        super(EmailConfirmation, self).save()
+
+class EmailOptout(models.Model):
+    email = models.CharField(max_length = 200, primary_key = True)
+
+    def __unicode__(self):
+        return self.email
+
+    @classmethod
+    def is_optout(cls, email):
+        email = email.lower().strip()
+        return cls.objects.filter(email = email).count() > 0
+
+class PatchChangeNotification(models.Model):
+    patch = models.ForeignKey(Patch, primary_key = True)
+    last_modified = models.DateTimeField(default = datetime.datetime.now)
+    orig_state = models.ForeignKey(State)
+
+def _patch_change_callback(sender, instance, **kwargs):
+    # we only want notification of modified patches
+    if instance.pk is None:
+        return
+
+    if instance.project is None or not instance.project.send_notifications:
+        return
+
+    try:
+        orig_patch = Patch.objects.get(pk = instance.pk)
+    except Patch.DoesNotExist:
+        return
+
+    # If there's no interesting changes, abort without creating the
+    # notification
+    if orig_patch.state == instance.state:
+        return
+
+    notification = None
+    try:
+        notification = PatchChangeNotification.objects.get(patch = instance)
+    except PatchChangeNotification.DoesNotExist:
+        pass
+
+    if notification is None:
+        notification = PatchChangeNotification(patch = instance,
+                                               orig_state = orig_patch.state)
+
+    elif notification.orig_state == instance.state:
+        # If we're back at the original state, there is no need to notify
+        notification.delete()
+        return
 
+    notification.last_modified = datetime.datetime.now()
+    notification.save()
 
+models.signals.pre_save.connect(_patch_change_callback, sender = Patch)
index 68fe563df004850a703c59aaf72e7ac5e0f8a761..8ae271ae0871c51a16f16a1df46f5ad66e00ff50 100644 (file)
@@ -23,3 +23,8 @@ from patchwork.tests.bundles import *
 from patchwork.tests.mboxviews import *
 from patchwork.tests.updates import *
 from patchwork.tests.filters import *
+from patchwork.tests.confirm import *
+from patchwork.tests.registration import *
+from patchwork.tests.user import *
+from patchwork.tests.mail_settings import *
+from patchwork.tests.notifications import *
diff --git a/apps/patchwork/tests/confirm.py b/apps/patchwork/tests/confirm.py
new file mode 100644 (file)
index 0000000..fad5125
--- /dev/null
@@ -0,0 +1,67 @@
+# Patchwork - automated patch tracking system
+# Copyright (C) 2011 Jeremy Kerr <jk@ozlabs.org>
+#
+# This file is part of the Patchwork package.
+#
+# Patchwork is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# Patchwork is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Patchwork; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+import unittest
+from django.test import TestCase
+from django.contrib.auth.models import User
+from django.core.urlresolvers import reverse
+from patchwork.models import EmailConfirmation, Person
+
+def _confirmation_url(conf):
+    return reverse('patchwork.views.confirm', kwargs = {'key': conf.key})
+
+class TestUser(object):
+    username = 'testuser'
+    email = 'test@example.com'
+    secondary_email = 'test2@example.com'
+    password = None
+
+    def __init__(self):
+        self.password = User.objects.make_random_password()
+        self.user = User.objects.create_user(self.username,
+                            self.email, self.password)
+
+class InvalidConfirmationTest(TestCase):
+    def setUp(self):
+        EmailConfirmation.objects.all().delete()
+        Person.objects.all().delete()
+        self.user = TestUser()
+        self.conf = EmailConfirmation(type = 'userperson',
+                                      email = self.user.secondary_email,
+                                      user = self.user.user)
+        self.conf.save()
+
+    def testInactiveConfirmation(self):
+        self.conf.active = False
+        self.conf.save()
+        response = self.client.get(_confirmation_url(self.conf))
+        self.assertEquals(response.status_code, 200)
+        self.assertTemplateUsed(response, 'patchwork/confirm-error.html')
+        self.assertEqual(response.context['error'], 'inactive')
+        self.assertEqual(response.context['conf'], self.conf)
+
+    def testExpiredConfirmation(self):
+        self.conf.date -= self.conf.validity
+        self.conf.save()
+        response = self.client.get(_confirmation_url(self.conf))
+        self.assertEquals(response.status_code, 200)
+        self.assertTemplateUsed(response, 'patchwork/confirm-error.html')
+        self.assertEqual(response.context['error'], 'expired')
+        self.assertEqual(response.context['conf'], self.conf)
+
diff --git a/apps/patchwork/tests/mail_settings.py b/apps/patchwork/tests/mail_settings.py
new file mode 100644 (file)
index 0000000..36dc5cc
--- /dev/null
@@ -0,0 +1,302 @@
+# Patchwork - automated patch tracking system
+# Copyright (C) 2010 Jeremy Kerr <jk@ozlabs.org>
+#
+# This file is part of the Patchwork package.
+#
+# Patchwork is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# Patchwork is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Patchwork; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+import unittest
+import re
+from django.test import TestCase
+from django.test.client import Client
+from django.core import mail
+from django.core.urlresolvers import reverse
+from django.contrib.auth.models import User
+from patchwork.models import EmailOptout, EmailConfirmation, Person
+from patchwork.tests.utils import create_user
+
+class MailSettingsTest(TestCase):
+    view = 'patchwork.views.mail.settings'
+    url = reverse(view)
+
+    def testMailSettingsGET(self):
+        response = self.client.get(self.url)
+        self.assertEquals(response.status_code, 200)
+        self.assertTrue(response.context['form'])
+
+    def testMailSettingsPOST(self):
+        email = u'foo@example.com'
+        response = self.client.post(self.url, {'email': email})
+        self.assertEquals(response.status_code, 200)
+        self.assertTemplateUsed(response, 'patchwork/mail-settings.html')
+        self.assertEquals(response.context['email'], email)
+
+    def testMailSettingsPOSTEmpty(self):
+        response = self.client.post(self.url, {'email': ''})
+        self.assertEquals(response.status_code, 200)
+        self.assertTemplateUsed(response, 'patchwork/mail-form.html')
+        self.assertFormError(response, 'form', 'email',
+                'This field is required.')
+
+    def testMailSettingsPOSTInvalid(self):
+        response = self.client.post(self.url, {'email': 'foo'})
+        self.assertEquals(response.status_code, 200)
+        self.assertTemplateUsed(response, 'patchwork/mail-form.html')
+        self.assertFormError(response, 'form', 'email',
+                'Enter a valid e-mail address.')
+
+    def testMailSettingsPOSTOptedIn(self):
+        email = u'foo@example.com'
+        response = self.client.post(self.url, {'email': email})
+        self.assertEquals(response.status_code, 200)
+        self.assertTemplateUsed(response, 'patchwork/mail-settings.html')
+        self.assertEquals(response.context['is_optout'], False)
+        self.assertTrue('<strong>may</strong>' in response.content)
+        optout_url = reverse('patchwork.views.mail.optout')
+        self.assertTrue(('action="%s"' % optout_url) in response.content)
+
+    def testMailSettingsPOSTOptedOut(self):
+        email = u'foo@example.com'
+        EmailOptout(email = email).save()
+        response = self.client.post(self.url, {'email': email})
+        self.assertEquals(response.status_code, 200)
+        self.assertTemplateUsed(response, 'patchwork/mail-settings.html')
+        self.assertEquals(response.context['is_optout'], True)
+        self.assertTrue('<strong>may not</strong>' in response.content)
+        optin_url = reverse('patchwork.views.mail.optin')
+        self.assertTrue(('action="%s"' % optin_url) in response.content)
+
+class OptoutRequestTest(TestCase):
+    view = 'patchwork.views.mail.optout'
+    url = reverse(view)
+
+    def testOptOutRequestGET(self):
+        response = self.client.get(self.url)
+        self.assertRedirects(response, reverse('patchwork.views.mail.settings'))
+
+    def testOptoutRequestValidPOST(self):
+        email = u'foo@example.com'
+        response = self.client.post(self.url, {'email': email})
+
+        # check for a confirmation object
+        self.assertEquals(EmailConfirmation.objects.count(), 1)
+        conf = EmailConfirmation.objects.get(email = email)
+
+        # check confirmation page
+        self.assertEquals(response.status_code, 200)
+        self.assertEquals(response.context['confirmation'], conf)
+        self.assertTrue(email in response.content)
+
+        # check email
+        url = reverse('patchwork.views.confirm', kwargs = {'key': conf.key})
+        self.assertEquals(len(mail.outbox), 1)
+        msg = mail.outbox[0]
+        self.assertEquals(msg.to, [email])
+        self.assertEquals(msg.subject, 'Patchwork opt-out confirmation')
+        self.assertTrue(url in msg.body)
+
+    def testOptoutRequestInvalidPOSTEmpty(self):
+        response = self.client.post(self.url, {'email': ''})
+        self.assertEquals(response.status_code, 200)
+        self.assertFormError(response, 'form', 'email',
+                'This field is required.')
+        self.assertTrue(response.context['error'])
+        self.assertTrue('email_sent' not in response.context)
+        self.assertEquals(len(mail.outbox), 0)
+
+    def testOptoutRequestInvalidPOSTNonEmail(self):
+        response = self.client.post(self.url, {'email': 'foo'})
+        self.assertEquals(response.status_code, 200)
+        self.assertFormError(response, 'form', 'email',
+                'Enter a valid e-mail address.')
+        self.assertTrue(response.context['error'])
+        self.assertTrue('email_sent' not in response.context)
+        self.assertEquals(len(mail.outbox), 0)
+
+class OptoutTest(TestCase):
+    view = 'patchwork.views.mail.optout'
+    url = reverse(view)
+
+    def setUp(self):
+        self.email = u'foo@example.com'
+        self.conf = EmailConfirmation(type = 'optout', email = self.email)
+        self.conf.save()
+
+    def testOptoutValidHash(self):
+        url = reverse('patchwork.views.confirm',
+                        kwargs = {'key': self.conf.key})
+        response = self.client.get(url)
+
+        self.assertEquals(response.status_code, 200)
+        self.assertTemplateUsed(response, 'patchwork/optout.html')
+        self.assertTrue(self.email in response.content)
+
+        # check that we've got an optout in the list
+        self.assertEquals(EmailOptout.objects.count(), 1)
+        self.assertEquals(EmailOptout.objects.all()[0].email, self.email)
+
+        # check that the confirmation is now inactive
+        self.assertFalse(EmailConfirmation.objects.get(
+                                    pk = self.conf.pk).active)
+
+
+class OptoutPreexistingTest(OptoutTest):
+    """Test that a duplicated opt-out behaves the same as the initial one"""
+    def setUp(self):
+        super(OptoutPreexistingTest, self).setUp()
+        EmailOptout(email = self.email).save()
+
+class OptinRequestTest(TestCase):
+    view = 'patchwork.views.mail.optin'
+    url = reverse(view)
+
+    def setUp(self):
+        self.email = u'foo@example.com'
+        EmailOptout(email = self.email).save()
+
+    def testOptInRequestGET(self):
+        response = self.client.get(self.url)
+        self.assertRedirects(response, reverse('patchwork.views.mail.settings'))
+
+    def testOptInRequestValidPOST(self):
+        response = self.client.post(self.url, {'email': self.email})
+
+        # check for a confirmation object
+        self.assertEquals(EmailConfirmation.objects.count(), 1)
+        conf = EmailConfirmation.objects.get(email = self.email)
+
+        # check confirmation page
+        self.assertEquals(response.status_code, 200)
+        self.assertEquals(response.context['confirmation'], conf)
+        self.assertTrue(self.email in response.content)
+
+        # check email
+        url = reverse('patchwork.views.confirm', kwargs = {'key': conf.key})
+        self.assertEquals(len(mail.outbox), 1)
+        msg = mail.outbox[0]
+        self.assertEquals(msg.to, [self.email])
+        self.assertEquals(msg.subject, 'Patchwork opt-in confirmation')
+        self.assertTrue(url in msg.body)
+
+    def testOptoutRequestInvalidPOSTEmpty(self):
+        response = self.client.post(self.url, {'email': ''})
+        self.assertEquals(response.status_code, 200)
+        self.assertFormError(response, 'form', 'email',
+                'This field is required.')
+        self.assertTrue(response.context['error'])
+        self.assertTrue('email_sent' not in response.context)
+        self.assertEquals(len(mail.outbox), 0)
+
+    def testOptoutRequestInvalidPOSTNonEmail(self):
+        response = self.client.post(self.url, {'email': 'foo'})
+        self.assertEquals(response.status_code, 200)
+        self.assertFormError(response, 'form', 'email',
+                'Enter a valid e-mail address.')
+        self.assertTrue(response.context['error'])
+        self.assertTrue('email_sent' not in response.context)
+        self.assertEquals(len(mail.outbox), 0)
+
+class OptinTest(TestCase):
+
+    def setUp(self):
+        self.email = u'foo@example.com'
+        self.optout = EmailOptout(email = self.email)
+        self.optout.save()
+        self.conf = EmailConfirmation(type = 'optin', email = self.email)
+        self.conf.save()
+
+    def testOptinValidHash(self):
+        url = reverse('patchwork.views.confirm',
+                        kwargs = {'key': self.conf.key})
+        response = self.client.get(url)
+
+        self.assertEquals(response.status_code, 200)
+        self.assertTemplateUsed(response, 'patchwork/optin.html')
+        self.assertTrue(self.email in response.content)
+
+        # check that there's no optout remaining
+        self.assertEquals(EmailOptout.objects.count(), 0)
+
+        # check that the confirmation is now inactive
+        self.assertFalse(EmailConfirmation.objects.get(
+                                    pk = self.conf.pk).active)
+
+class OptinWithoutOptoutTest(TestCase):
+    """Test an opt-in with no existing opt-out"""
+    view = 'patchwork.views.mail.optin'
+    url = reverse(view)
+
+    def testOptInWithoutOptout(self):
+        email = u'foo@example.com'
+        response = self.client.post(self.url, {'email': email})
+
+        # check for an error message
+        self.assertEquals(response.status_code, 200)
+        self.assertTrue(bool(response.context['error']))
+        self.assertTrue('not on the patchwork opt-out list' in response.content)
+
+class UserProfileOptoutFormTest(TestCase):
+    """Test that the correct optin/optout forms appear on the user profile
+       page, for logged-in users"""
+
+    view = 'patchwork.views.user.profile'
+    url = reverse(view)
+    optout_url = reverse('patchwork.views.mail.optout')
+    optin_url = reverse('patchwork.views.mail.optin')
+    form_re_template = ('<form\s+[^>]*action="%(url)s"[^>]*>'
+                        '.*?<input\s+[^>]*value="%(email)s"[^>]*>.*?'
+                        '</form>')
+    secondary_email = 'test2@example.com'
+
+    def setUp(self):
+        self.user = create_user()
+        self.client.login(username = self.user.username,
+                password = self.user.username)
+
+    def _form_re(self, url, email):
+        return re.compile(self.form_re_template % {'url': url, 'email': email},
+                          re.DOTALL)
+
+    def testMainEmailOptoutForm(self):
+        form_re = self._form_re(self.optout_url, self.user.email)
+        response = self.client.get(self.url)
+        self.assertEquals(response.status_code, 200)
+        self.assertTrue(form_re.search(response.content) is not None)
+
+    def testMainEmailOptinForm(self):
+        EmailOptout(email = self.user.email).save()
+        form_re = self._form_re(self.optin_url, self.user.email)
+        response = self.client.get(self.url)
+        self.assertEquals(response.status_code, 200)
+        self.assertTrue(form_re.search(response.content) is not None)
+
+    def testSecondaryEmailOptoutForm(self):
+        p = Person(email = self.secondary_email, user = self.user)
+        p.save()
+        
+        form_re = self._form_re(self.optout_url, p.email)
+        response = self.client.get(self.url)
+        self.assertEquals(response.status_code, 200)
+        self.assertTrue(form_re.search(response.content) is not None)
+
+    def testSecondaryEmailOptinForm(self):
+        p = Person(email = self.secondary_email, user = self.user)
+        p.save()
+        EmailOptout(email = p.email).save()
+
+        form_re = self._form_re(self.optin_url, self.user.email)
+        response = self.client.get(self.url)
+        self.assertEquals(response.status_code, 200)
+        self.assertTrue(form_re.search(response.content) is not None)
diff --git a/apps/patchwork/tests/notifications.py b/apps/patchwork/tests/notifications.py
new file mode 100644 (file)
index 0000000..f14b30b
--- /dev/null
@@ -0,0 +1,241 @@
+# Patchwork - automated patch tracking system
+# Copyright (C) 2011 Jeremy Kerr <jk@ozlabs.org>
+#
+# This file is part of the Patchwork package.
+#
+# Patchwork is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# Patchwork is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Patchwork; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+import datetime
+from django.test import TestCase
+from django.core.urlresolvers import reverse
+from django.core import mail
+from django.conf import settings
+from django.db.utils import IntegrityError
+from patchwork.models import Patch, State, PatchChangeNotification, EmailOptout
+from patchwork.tests.utils import defaults, create_maintainer
+from patchwork.utils import send_notifications
+
+class PatchNotificationModelTest(TestCase):
+    """Tests for the creation & update of the PatchChangeNotification model"""
+
+    def setUp(self):
+        self.project = defaults.project
+        self.project.send_notifications = True
+        self.project.save()
+        self.submitter = defaults.patch_author_person
+        self.submitter.save()
+        self.patch = Patch(project = self.project, msgid = 'testpatch',
+                        name = 'testpatch', content = '',
+                        submitter = self.submitter)
+
+    def tearDown(self):
+        self.patch.delete()
+        self.submitter.delete()
+        self.project.delete()
+
+    def testPatchCreation(self):
+        """Ensure we don't get a notification on create"""
+        self.patch.save()
+        self.assertEqual(PatchChangeNotification.objects.count(), 0)
+
+    def testPatchUninterestingChange(self):
+        """Ensure we don't get a notification for "uninteresting" changes"""
+        self.patch.save()
+        self.patch.archived = True
+        self.patch.save()
+        self.assertEqual(PatchChangeNotification.objects.count(), 0)
+
+    def testPatchChange(self):
+        """Ensure we get a notification for interesting patch changes"""
+        self.patch.save()
+        oldstate = self.patch.state
+        state = State.objects.exclude(pk = oldstate.pk)[0]
+
+        self.patch.state = state
+        self.patch.save()
+        self.assertEqual(PatchChangeNotification.objects.count(), 1)
+        notification = PatchChangeNotification.objects.all()[0]
+        self.assertEqual(notification.patch, self.patch)
+        self.assertEqual(notification.orig_state, oldstate)
+
+    def testNotificationCancelled(self):
+        """Ensure we cancel notifications that are no longer valid"""
+        self.patch.save()
+        oldstate = self.patch.state
+        state = State.objects.exclude(pk = oldstate.pk)[0]
+
+        self.patch.state = state
+        self.patch.save()
+        self.assertEqual(PatchChangeNotification.objects.count(), 1)
+
+        self.patch.state = oldstate
+        self.patch.save()
+        self.assertEqual(PatchChangeNotification.objects.count(), 0)
+
+    def testNotificationUpdated(self):
+        """Ensure we update notifications when the patch has a second change,
+           but keep the original patch details"""
+        self.patch.save()
+        oldstate = self.patch.state
+        newstates = State.objects.exclude(pk = oldstate.pk)[:2]
+
+        self.patch.state = newstates[0]
+        self.patch.save()
+        self.assertEqual(PatchChangeNotification.objects.count(), 1)
+        notification = PatchChangeNotification.objects.all()[0]
+        self.assertEqual(notification.orig_state, oldstate)
+        orig_timestamp = notification.last_modified
+                         
+        self.patch.state = newstates[1]
+        self.patch.save()
+        self.assertEqual(PatchChangeNotification.objects.count(), 1)
+        notification = PatchChangeNotification.objects.all()[0]
+        self.assertEqual(notification.orig_state, oldstate)
+        self.assertTrue(notification.last_modified > orig_timestamp)
+
+    def testProjectNotificationsDisabled(self):
+        """Ensure we don't see notifications created when a project is
+           configured not to send them"""
+        self.project.send_notifications = False
+        self.project.save()
+
+        self.patch.save()
+        oldstate = self.patch.state
+        state = State.objects.exclude(pk = oldstate.pk)[0]
+
+        self.patch.state = state
+        self.patch.save()
+        self.assertEqual(PatchChangeNotification.objects.count(), 0)
+
+class PatchNotificationEmailTest(TestCase):
+
+    def setUp(self):
+        self.project = defaults.project
+        self.project.send_notifications = True
+        self.project.save()
+        self.submitter = defaults.patch_author_person
+        self.submitter.save()
+        self.patch = Patch(project = self.project, msgid = 'testpatch',
+                        name = 'testpatch', content = '',
+                        submitter = self.submitter)
+        self.patch.save()
+
+    def tearDown(self):
+        self.patch.delete()
+        self.submitter.delete()
+        self.project.delete()
+
+    def _expireNotifications(self, **kwargs):
+        timestamp = datetime.datetime.now() - \
+                    datetime.timedelta(minutes =
+                            settings.NOTIFICATION_DELAY_MINUTES + 1)
+
+        qs = PatchChangeNotification.objects.all()
+        if kwargs:
+            qs = qs.filter(**kwargs)
+
+        qs.update(last_modified = timestamp)
+
+    def testNoNotifications(self):
+        self.assertEquals(send_notifications(), [])
+
+    def testNoReadyNotifications(self):
+        """ We shouldn't see immediate notifications"""
+        PatchChangeNotification(patch = self.patch,
+                               orig_state = self.patch.state).save()
+
+        errors = send_notifications()
+        self.assertEquals(errors, [])
+        self.assertEquals(len(mail.outbox), 0)
+
+    def testNotifications(self):
+        PatchChangeNotification(patch = self.patch,
+                               orig_state = self.patch.state).save()
+        self._expireNotifications()
+
+        errors = send_notifications()
+        self.assertEquals(errors, [])
+        self.assertEquals(len(mail.outbox), 1)
+        msg = mail.outbox[0]
+        self.assertEquals(msg.to, [self.submitter.email])
+        self.assertTrue(self.patch.get_absolute_url() in msg.body)
+
+    def testNotificationOptout(self):
+        """ensure opt-out addresses don't get notifications"""
+        PatchChangeNotification(patch = self.patch,
+                               orig_state = self.patch.state).save()
+        self._expireNotifications()
+
+        EmailOptout(email = self.submitter.email).save()
+
+        errors = send_notifications()
+        self.assertEquals(errors, [])
+        self.assertEquals(len(mail.outbox), 0)
+
+    def testNotificationMerge(self):
+        patches = [self.patch,
+                   Patch(project = self.project, msgid = 'testpatch-2',
+                         name = 'testpatch 2', content = '',
+                         submitter = self.submitter)]
+
+        for patch in patches:
+            patch.save()
+            PatchChangeNotification(patch = patch,
+                                   orig_state = patch.state).save()
+
+        self.assertEquals(PatchChangeNotification.objects.count(), len(patches))
+        self._expireNotifications()
+        errors = send_notifications()
+        self.assertEquals(errors, [])
+        self.assertEquals(len(mail.outbox), 1)
+        msg = mail.outbox[0]
+        self.assertTrue(patches[0].get_absolute_url() in msg.body)
+        self.assertTrue(patches[1].get_absolute_url() in msg.body)
+
+    def testUnexpiredNotificationMerge(self):
+        """Test that when there are multiple pending notifications, with
+           at least one within the notification delay, that other notifications
+           are held"""
+        patches = [self.patch,
+                   Patch(project = self.project, msgid = 'testpatch-2',
+                         name = 'testpatch 2', content = '',
+                         submitter = self.submitter)]
+
+        for patch in patches:
+            patch.save()
+            PatchChangeNotification(patch = patch,
+                                   orig_state = patch.state).save()
+
+        self.assertEquals(PatchChangeNotification.objects.count(), len(patches))
+        self._expireNotifications()
+
+        # update one notification, to bring it out of the notification delay
+        patches[0].state = State.objects.exclude(pk = patches[0].state.pk)[0]
+        patches[0].save()
+
+        # the updated notification should prevent the other from being sent
+        errors = send_notifications()
+        self.assertEquals(errors, [])
+        self.assertEquals(len(mail.outbox), 0)
+
+        # expire the updated notification
+        self._expireNotifications()
+
+        errors = send_notifications()
+        self.assertEquals(errors, [])
+        self.assertEquals(len(mail.outbox), 1)
+        msg = mail.outbox[0]
+        self.assertTrue(patches[0].get_absolute_url() in msg.body)
+        self.assertTrue(patches[1].get_absolute_url() in msg.body)
diff --git a/apps/patchwork/tests/registration.py b/apps/patchwork/tests/registration.py
new file mode 100644 (file)
index 0000000..18b781f
--- /dev/null
@@ -0,0 +1,150 @@
+# Patchwork - automated patch tracking system
+# Copyright (C) 2010 Jeremy Kerr <jk@ozlabs.org>
+#
+# This file is part of the Patchwork package.
+#
+# Patchwork is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# Patchwork is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Patchwork; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+import unittest
+from django.test import TestCase
+from django.test.client import Client
+from django.core import mail
+from django.core.urlresolvers import reverse
+from django.contrib.auth.models import User
+from patchwork.models import EmailConfirmation, Person
+from patchwork.tests.utils import create_user
+
+def _confirmation_url(conf):
+    return reverse('patchwork.views.confirm', kwargs = {'key': conf.key})
+
+class TestUser(object):
+    firstname = 'Test'
+    lastname = 'User'
+    username = 'testuser'
+    email = 'test@example.com'
+    password = 'foobar'
+
+class RegistrationTest(TestCase):
+    def setUp(self):
+        self.user = TestUser()
+        self.client = Client()
+        self.default_data = {'username': self.user.username,
+                             'first_name': self.user.firstname,
+                             'last_name': self.user.lastname,
+                             'email': self.user.email,
+                             'password': self.user.password}
+        self.required_error = 'This field is required.'
+        self.invalid_error = 'Enter a valid value.'
+
+    def testRegistrationForm(self):
+        response = self.client.get('/register/')
+        self.assertEquals(response.status_code, 200)
+        self.assertTemplateUsed(response, 'patchwork/registration_form.html')
+
+    def testBlankFields(self):
+        for field in ['username', 'email', 'password']:
+            data = self.default_data.copy()
+            del data[field]
+            response = self.client.post('/register/', data)
+            self.assertEquals(response.status_code, 200)
+            self.assertFormError(response, 'form', field, self.required_error)
+
+    def testInvalidUsername(self):
+        data = self.default_data.copy()
+        data['username'] = 'invalid user'
+        response = self.client.post('/register/', data)
+        self.assertEquals(response.status_code, 200)
+        self.assertFormError(response, 'form', 'username', self.invalid_error)
+
+    def testExistingUsername(self):
+        user = create_user()
+        data = self.default_data.copy()
+        data['username'] = user.username
+        response = self.client.post('/register/', data)
+        self.assertEquals(response.status_code, 200)
+        self.assertFormError(response, 'form', 'username',
+                'This username is already taken. Please choose another.')
+
+    def testExistingEmail(self):
+        user = create_user()
+        data = self.default_data.copy()
+        data['email'] = user.email
+        response = self.client.post('/register/', data)
+        self.assertEquals(response.status_code, 200)
+        self.assertFormError(response, 'form', 'email',
+                'This email address is already in use ' + \
+                'for the account "%s".\n' % user.username)
+
+    def testValidRegistration(self):
+        response = self.client.post('/register/', self.default_data)
+        self.assertEquals(response.status_code, 200)
+        self.assertContains(response, 'confirmation email has been sent')
+
+        # check for presence of an inactive user object
+        users = User.objects.filter(username = self.user.username)
+        self.assertEquals(users.count(), 1)
+        user = users[0]
+        self.assertEquals(user.username, self.user.username)
+        self.assertEquals(user.email, self.user.email)
+        self.assertEquals(user.is_active, False)
+
+        # check for confirmation object
+        confs = EmailConfirmation.objects.filter(user = user,
+                                                 type = 'registration')
+        self.assertEquals(len(confs), 1)
+        conf = confs[0]
+        self.assertEquals(conf.email, self.user.email)
+
+        # check for a sent mail
+        self.assertEquals(len(mail.outbox), 1)
+        msg = mail.outbox[0]
+        self.assertEquals(msg.subject, 'Patchwork account confirmation')
+        self.assertTrue(self.user.email in msg.to)
+        self.assertTrue(_confirmation_url(conf) in msg.body)
+
+        # ...and that the URL is valid
+        response = self.client.get(_confirmation_url(conf))
+        self.assertEquals(response.status_code, 200)
+
+class RegistrationConfirmationTest(TestCase):
+
+    def setUp(self):
+        self.user = TestUser()
+        self.default_data = {'username': self.user.username,
+                             'first_name': self.user.firstname,
+                             'last_name': self.user.lastname,
+                             'email': self.user.email,
+                             'password': self.user.password}
+
+    def testRegistrationConfirmation(self):
+        self.assertEqual(EmailConfirmation.objects.count(), 0)
+        response = self.client.post('/register/', self.default_data)
+        self.assertEquals(response.status_code, 200)
+        self.assertContains(response, 'confirmation email has been sent')
+
+        self.assertEqual(EmailConfirmation.objects.count(), 1)
+        conf = EmailConfirmation.objects.filter()[0]
+        self.assertFalse(conf.user.is_active)
+        self.assertTrue(conf.active)
+
+        response = self.client.get(_confirmation_url(conf))
+        self.assertEquals(response.status_code, 200)
+        self.assertTemplateUsed(response, 'patchwork/registration-confirm.html')
+
+        conf = EmailConfirmation.objects.get(pk = conf.pk)
+        self.assertTrue(conf.user.is_active)
+        self.assertFalse(conf.active)
+
+
diff --git a/apps/patchwork/tests/user.py b/apps/patchwork/tests/user.py
new file mode 100644 (file)
index 0000000..e96e6c5
--- /dev/null
@@ -0,0 +1,128 @@
+# Patchwork - automated patch tracking system
+# Copyright (C) 2010 Jeremy Kerr <jk@ozlabs.org>
+#
+# This file is part of the Patchwork package.
+#
+# Patchwork is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# Patchwork is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Patchwork; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+import unittest
+from django.test import TestCase
+from django.test.client import Client
+from django.core import mail
+from django.core.urlresolvers import reverse
+from django.conf import settings
+from django.contrib.auth.models import User
+from patchwork.models import EmailConfirmation, Person
+
+def _confirmation_url(conf):
+    return reverse('patchwork.views.confirm', kwargs = {'key': conf.key})
+
+class TestUser(object):
+    username = 'testuser'
+    email = 'test@example.com'
+    secondary_email = 'test2@example.com'
+    password = None
+
+    def __init__(self):
+        self.password = User.objects.make_random_password()
+        self.user = User.objects.create_user(self.username,
+                            self.email, self.password)
+
+class UserPersonRequestTest(TestCase):
+    def setUp(self):
+        self.user = TestUser()
+        self.client.login(username = self.user.username,
+                          password = self.user.password)
+        EmailConfirmation.objects.all().delete()
+
+    def testUserPersonRequestForm(self):
+        response = self.client.get('/user/link/')
+        self.assertEquals(response.status_code, 200)
+        self.assertTrue(response.context['linkform'])
+
+    def testUserPersonRequestEmpty(self):
+        response = self.client.post('/user/link/', {'email': ''})
+        self.assertEquals(response.status_code, 200)
+        self.assertTrue(response.context['linkform'])
+        self.assertFormError(response, 'linkform', 'email',
+                'This field is required.')
+
+    def testUserPersonRequestInvalid(self):
+        response = self.client.post('/user/link/', {'email': 'foo'})
+        self.assertEquals(response.status_code, 200)
+        self.assertTrue(response.context['linkform'])
+        self.assertFormError(response, 'linkform', 'email',
+                'Enter a valid e-mail address.')
+
+    def testUserPersonRequestValid(self):
+        response = self.client.post('/user/link/',
+                                {'email': self.user.secondary_email})
+        self.assertEquals(response.status_code, 200)
+        self.assertTrue(response.context['confirmation'])
+
+        # check that we have a confirmation saved
+        self.assertEquals(EmailConfirmation.objects.count(), 1)
+        conf = EmailConfirmation.objects.all()[0]
+        self.assertEquals(conf.user, self.user.user)
+        self.assertEquals(conf.email, self.user.secondary_email)
+        self.assertEquals(conf.type, 'userperson')
+
+        # check that an email has gone out...
+        self.assertEquals(len(mail.outbox), 1)
+        msg = mail.outbox[0]
+        self.assertEquals(msg.subject, 'Patchwork email address confirmation')
+        self.assertTrue(self.user.secondary_email in msg.to)
+        self.assertTrue(_confirmation_url(conf) in msg.body)
+
+        # ...and that the URL is valid
+        response = self.client.get(_confirmation_url(conf))
+        self.assertEquals(response.status_code, 200)
+        self.assertTemplateUsed(response, 'patchwork/user-link-confirm.html')
+
+class UserPersonConfirmTest(TestCase):
+    def setUp(self):
+        EmailConfirmation.objects.all().delete()
+        Person.objects.all().delete()
+        self.user = TestUser()
+        self.client.login(username = self.user.username,
+                          password = self.user.password)
+        self.conf = EmailConfirmation(type = 'userperson',
+                                      email = self.user.secondary_email,
+                                      user = self.user.user)
+        self.conf.save()
+
+    def testUserPersonConfirm(self):
+        self.assertEquals(Person.objects.count(), 1)
+        response = self.client.get(_confirmation_url(self.conf))
+        self.assertEquals(response.status_code, 200)
+
+        # check that the Person object has been created and linked
+        self.assertEquals(Person.objects.count(), 2)
+        person = Person.objects.get(email = self.user.secondary_email)
+        self.assertEquals(person.email, self.user.secondary_email)
+        self.assertEquals(person.user, self.user.user)
+
+        # check that the confirmation has been marked as inactive. We
+        # need to reload the confirmation to check this.
+        conf = EmailConfirmation.objects.get(pk = self.conf.pk)
+        self.assertEquals(conf.active, False)
+
+class UserLoginRedirectTest(TestCase):
+    
+    def testUserLoginRedirect(self):
+        url = '/user/'
+        response = self.client.get(url)
+        self.assertRedirects(response, settings.LOGIN_URL + '?next=' + url)
+
index f1c95e8a8d274054bdcc927dc2c8ed2e18259a14..1cb5dfb95d529375b980d4629b7855790384ae55 100644 (file)
@@ -59,7 +59,7 @@ class defaults(object):
 _user_idx = 1
 def create_user():
     global _user_idx
-    userid = 'test-%d' % _user_idx
+    userid = 'test%d' % _user_idx
     email = '%s@example.com' % userid
     _user_idx += 1
 
index b49b4e10b0f67ce32347285b537112c72e142a1e..10fc3b900d9653188f6d4ac6901a54599d8f2048 100644 (file)
@@ -19,6 +19,7 @@
 
 from django.conf.urls.defaults import *
 from django.conf import settings
+from django.contrib.auth import views as auth_views
 
 urlpatterns = patterns('',
     # Example:
@@ -44,16 +45,39 @@ urlpatterns = patterns('',
         'patchwork.views.bundle.mbox'),
 
     (r'^user/link/$', 'patchwork.views.user.link'),
-    (r'^user/link/(?P<key>[^/]+)/$', 'patchwork.views.user.link_confirm'),
     (r'^user/unlink/(?P<person_id>[^/]+)/$', 'patchwork.views.user.unlink'),
 
+    # password change
+    url(r'^user/password-change/$', auth_views.password_change,
+            name='auth_password_change'),
+    url(r'^user/password-change/done/$', auth_views.password_change_done,
+            name='auth_password_change_done'),
+
+    # login/logout
+    url(r'^user/login/$', auth_views.login,
+        {'template_name': 'patchwork/login.html'},
+        name = 'auth_login'),
+    url(r'^user/logout/$', auth_views.logout,
+        {'template_name': 'patchwork/logout.html'},
+        name = 'auth_logout'),
+
+    # registration
+    (r'^register/', 'patchwork.views.user.register'),
+
     # public view for bundles
     (r'^bundle/(?P<username>[^/]*)/(?P<bundlename>[^/]*)/$',
                                 'patchwork.views.bundle.public'),
 
+    (r'^confirm/(?P<key>[0-9a-f]+)/$', 'patchwork.views.confirm'),
+
     # submitter autocomplete
     (r'^submitter/$', 'patchwork.views.submitter_complete'),
 
+    # email setup
+    (r'^mail/$', 'patchwork.views.mail.settings'),
+    (r'^mail/optout/$', 'patchwork.views.mail.optout'),
+    (r'^mail/optin/$', 'patchwork.views.mail.optin'),
+
     # help!
     (r'^help/(?P<path>.*)$', 'patchwork.views.help'),
 )
index 5a8e4c0a4746f700bd201f316db32b0e7519d371..e7619c319091ce2dd9e78396f24ffbe8dac1f6db 100644 (file)
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 
-from patchwork.models import Bundle, Project, BundlePatch
+import itertools
+import datetime
 from django.shortcuts import get_object_or_404
+from django.template.loader import render_to_string
+from django.contrib.sites.models import Site
+from django.conf import settings
+from django.core.mail import EmailMessage
+from django.db.models import Max
+from patchwork.forms import MultiplePatchForm
+from patchwork.models import Bundle, Project, BundlePatch, UserProfile, \
+        PatchChangeNotification, EmailOptout
 
 def get_patch_ids(d, prefix = 'patch_id'):
     ids = []
@@ -136,3 +145,60 @@ def set_bundle(user, project, action, data, patches, context):
     bundle.save()
 
     return []
+
+def send_notifications():
+    date_limit = datetime.datetime.now() - \
+                     datetime.timedelta(minutes =
+                                settings.NOTIFICATION_DELAY_MINUTES)
+
+    # This gets funky: we want to filter out any notifications that should
+    # be grouped with other notifications that aren't ready to go out yet. To
+    # do that, we join back onto PatchChangeNotification (PCN -> Patch ->
+    # Person -> Patch -> max(PCN.last_modified)), filtering out any maxima
+    # that are with the date_limit.
+    qs = PatchChangeNotification.objects \
+            .annotate(m = Max('patch__submitter__patch__patchchangenotification'
+                        '__last_modified')) \
+                .filter(m__lt = date_limit)
+
+    groups = itertools.groupby(qs.order_by('patch__submitter'),
+                               lambda n: n.patch.submitter)
+
+    errors = []
+
+    for (recipient, notifications) in groups:
+        notifications = list(notifications)
+
+        def delete_notifications():
+            PatchChangeNotification.objects.filter(
+                                pk__in = notifications).delete()
+
+        if EmailOptout.is_optout(recipient.email):
+            delete_notifications()
+            continue
+
+        context = {
+            'site': Site.objects.get_current(),
+            'person': recipient,
+            'notifications': notifications,
+        }
+        subject = render_to_string(
+                        'patchwork/patch-change-notification-subject.text',
+                        context).strip()
+        content = render_to_string('patchwork/patch-change-notification.mail',
+                                context)
+
+        message = EmailMessage(subject = subject, body = content,
+                               from_email = settings.NOTIFICATION_FROM_EMAIL,
+                               to = [recipient.email],
+                               headers = {'Precedence': 'bulk'})
+
+        try:
+            message.send()
+        except ex:
+            errors.append((recipient, ex))
+            continue
+
+        delete_notifications()
+
+    return errors
index c0e68ed409034b6ed16715b2702f4927a77f3b3d..82c036811688cf668b75be22969a86af9771c3ae 100644 (file)
@@ -18,7 +18,7 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 
-from patchwork.models import Patch, Project, Person
+from patchwork.models import Patch, Project, Person, EmailConfirmation
 from django.shortcuts import render_to_response, get_object_or_404
 from django.http import HttpResponse, HttpResponseRedirect, Http404
 from patchwork.requestcontext import PatchworkRequestContext
@@ -58,6 +58,31 @@ def pwclient(request):
     response.write(render_to_string('patchwork/pwclient', context))
     return response
 
+def confirm(request, key):
+    import patchwork.views.user, patchwork.views.mail
+    views = {
+        'userperson': patchwork.views.user.link_confirm,
+        'registration': patchwork.views.user.register_confirm,
+        'optout': patchwork.views.mail.optout_confirm,
+        'optin': patchwork.views.mail.optin_confirm,
+    }
+
+    conf = get_object_or_404(EmailConfirmation, key = key)
+    if conf.type not in views:
+        raise Http404
+
+    if conf.active and conf.is_valid():
+        return views[conf.type](request, conf)
+
+    context = PatchworkRequestContext(request)
+    context['conf'] = conf
+    if not conf.active:
+        context['error'] = 'inactive'
+    elif not conf.is_valid():
+        context['error'] = 'expired'
+
+    return render_to_response('patchwork/confirm-error.html', context)
+
 def submitter_complete(request):
     search = request.GET.get('q', '')
     response = HttpResponse(mimetype = "text/plain")
diff --git a/apps/patchwork/views/mail.py b/apps/patchwork/views/mail.py
new file mode 100644 (file)
index 0000000..aebba34
--- /dev/null
@@ -0,0 +1,119 @@
+# Patchwork - automated patch tracking system
+# Copyright (C) 2010 Jeremy Kerr <jk@ozlabs.org>
+#
+# This file is part of the Patchwork package.
+#
+# Patchwork is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# Patchwork is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Patchwork; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+from patchwork.requestcontext import PatchworkRequestContext
+from patchwork.models import EmailOptout, EmailConfirmation
+from patchwork.forms import OptinoutRequestForm, EmailForm
+from django.shortcuts import render_to_response
+from django.template.loader import render_to_string
+from django.conf import settings as conf_settings
+from django.core.mail import send_mail
+from django.core.urlresolvers import reverse
+from django.http import HttpResponseRedirect
+
+def settings(request):
+    context = PatchworkRequestContext(request)
+    if request.method == 'POST':
+        form = EmailForm(data = request.POST)
+        if form.is_valid():
+            email = form.cleaned_data['email']
+            is_optout = EmailOptout.objects.filter(email = email).count() > 0
+            context.update({
+                'email': email,
+                'is_optout': is_optout,
+            })
+            return render_to_response('patchwork/mail-settings.html', context)
+
+    else:
+        form = EmailForm()
+    context['form'] = form
+    return render_to_response('patchwork/mail-form.html', context)
+
+def optout_confirm(request, conf):
+    context = PatchworkRequestContext(request)
+
+    email = conf.email.strip().lower()
+    # silently ignore duplicated optouts
+    if EmailOptout.objects.filter(email = email).count() == 0:
+        optout = EmailOptout(email = email)
+        optout.save()
+
+    conf.deactivate()
+    context['email'] = conf.email
+
+    return render_to_response('patchwork/optout.html', context)
+
+def optin_confirm(request, conf):
+    context = PatchworkRequestContext(request)
+
+    email = conf.email.strip().lower()
+    EmailOptout.objects.filter(email = email).delete()
+
+    conf.deactivate()
+    context['email'] = conf.email
+
+    return render_to_response('patchwork/optin.html', context)
+
+def optinout(request, action, description):
+    context = PatchworkRequestContext(request)
+
+    mail_template = 'patchwork/%s-request.mail' % action
+    html_template = 'patchwork/%s-request.html' % action
+
+    if request.method != 'POST':
+        return HttpResponseRedirect(reverse(settings))
+
+    form = OptinoutRequestForm(data = request.POST)
+    if not form.is_valid():
+        context['error'] = ('There was an error in the %s form. ' +
+                           'Please review the form and re-submit.') % \
+                            description
+        context['form'] = form
+        return render_to_response(html_template, context)
+
+    email = form.cleaned_data['email']
+    if action == 'optin' and \
+            EmailOptout.objects.filter(email = email).count() == 0:
+        context['error'] = ('The email address %s is not on the ' +
+                            'patchwork opt-out list, so you don\'t ' +
+                            'need to opt back in') % email
+        context['form'] = form
+        return render_to_response(html_template, context)
+
+    conf = EmailConfirmation(type = action, email = email)
+    conf.save()
+    context['confirmation'] = conf
+    mail = render_to_string(mail_template, context)
+    try:
+        send_mail('Patchwork %s confirmation' % description, mail,
+                    conf_settings.DEFAULT_FROM_EMAIL, [email])
+        context['email'] = mail
+        context['email_sent'] = True
+    except Exception, ex:
+        context['error'] = 'An error occurred during confirmation . ' + \
+                           'Please try again later.'
+        context['admins'] = conf_settings.ADMINS
+
+    return render_to_response(html_template, context)
+
+def optout(request):
+    return optinout(request, 'optout', 'opt-out')
+
+def optin(request):
+    return optinout(request, 'optin', 'opt-in')
index 1ae3c2dd3843cc37c33f32dc31e9b9262dc4b3df..4a0e8458721ed62013310cc6475e4f760f7135a8 100644 (file)
 from django.contrib.auth.decorators import login_required
 from patchwork.requestcontext import PatchworkRequestContext
 from django.shortcuts import render_to_response, get_object_or_404
+from django.contrib import auth
+from django.contrib.sites.models import Site
 from django.http import HttpResponseRedirect
-from patchwork.models import Project, Bundle, Person, UserPersonConfirmation, \
-         State
-from patchwork.forms import UserProfileForm, UserPersonLinkForm
+from patchwork.models import Project, Bundle, Person, EmailConfirmation, \
+         State, EmailOptout
+from patchwork.forms import UserProfileForm, UserPersonLinkForm, \
+         RegistrationForm
 from patchwork.filters import DelegateFilter
 from patchwork.views import generic_list
 from django.template.loader import render_to_string
@@ -32,6 +35,55 @@ from django.conf import settings
 from django.core.mail import send_mail
 import django.core.urlresolvers
 
+def register(request):
+    context = PatchworkRequestContext(request)
+    if request.method == 'POST':
+        form = RegistrationForm(request.POST)
+        if form.is_valid():
+            data = form.cleaned_data
+            # create inactive user
+            user = auth.models.User.objects.create_user(data['username'],
+                                                        data['email'],
+                                                        data['password'])
+            user.is_active = False;
+            user.first_name = data.get('first_name', '')
+            user.last_name = data.get('last_name', '')
+            user.save()
+
+            # create confirmation
+            conf = EmailConfirmation(type = 'registration', user = user,
+                                     email = user.email)
+            conf.save()
+
+            # send email
+            mail_ctx = {'site': Site.objects.get_current(),
+                        'confirmation': conf}
+
+            subject = render_to_string('patchwork/activation_email_subject.txt',
+                                mail_ctx).replace('\n', ' ').strip()
+            
+            message = render_to_string('patchwork/activation_email.txt',
+                                    mail_ctx)
+            
+            send_mail(subject, message, settings.DEFAULT_FROM_EMAIL,
+                            [conf.email])
+
+            # setting 'confirmation' in the template indicates success
+            context['confirmation'] = conf
+
+    else:
+        form = RegistrationForm()
+    
+    return render_to_response('patchwork/registration_form.html',
+                              { 'form': form },
+                              context_instance=context)
+
+def register_confirm(request, conf):
+    conf.user.is_active = True
+    conf.user.save()
+    conf.deactivate()
+    return render_to_response('patchwork/registration-confirm.html')
+
 @login_required
 def profile(request):
     context = PatchworkRequestContext(request)
@@ -48,7 +100,13 @@ def profile(request):
     context['bundles'] = Bundle.objects.filter(owner = request.user)
     context['profileform'] = form
 
-    people = Person.objects.filter(user = request.user)
+    optout_query = '%s.%s IN (SELECT %s FROM %s)' % (
+                        Person._meta.db_table,
+                        Person._meta.get_field('email').column,
+                        EmailOptout._meta.get_field('email').column,
+                        EmailOptout._meta.db_table)
+    people = Person.objects.filter(user = request.user) \
+             .extra(select = {'is_optout': optout_query})
     context['linked_emails'] = people
     context['linkform'] = UserPersonLinkForm()
 
@@ -61,7 +119,8 @@ def link(request):
     if request.method == 'POST':
         form = UserPersonLinkForm(request.POST)
         if form.is_valid():
-            conf = UserPersonConfirmation(user = request.user,
+            conf = EmailConfirmation(type = 'userperson',
+                    user = request.user,
                     email = form.cleaned_data['email'])
             conf.save()
             context['confirmation'] = conf
@@ -83,15 +142,19 @@ def link(request):
     return render_to_response('patchwork/user-link.html', context)
 
 @login_required
-def link_confirm(request, key):
+def link_confirm(request, conf):
     context = PatchworkRequestContext(request)
-    confirmation = get_object_or_404(UserPersonConfirmation, key = key)
 
-    errors = confirmation.confirm()
-    if errors:
-        context['errors'] = errors
-    else:
-        context['person'] = Person.objects.get(email = confirmation.email)
+    try:
+        person = Person.objects.get(email__iexact = conf.email)
+    except Person.DoesNotExist:
+        person = Person(email = conf.email)
+
+    person.link_to_user(conf.user)
+    person.save()
+    conf.deactivate()
+
+    context['person'] = person
 
     return render_to_response('patchwork/user-link-confirm.html', context)
 
index 24d376259dff926ecab7ee9ebfca3ef670b7a19b..7523099374cc09922008bc3cb3ddc3f81b101842 100644 (file)
@@ -64,7 +64,7 @@ MIDDLEWARE_CLASSES = (
 
 ROOT_URLCONF = 'apps.urls'
 
-LOGIN_URL = '/accounts/login'
+LOGIN_URL = '/user/login/'
 LOGIN_REDIRECT_URL = '/user/'
 
 # If you change the ROOT_DIR setting in your local_settings.py, you'll need to
@@ -96,13 +96,15 @@ INSTALLED_APPS = (
     'django.contrib.sites',
     'django.contrib.admin',
     'patchwork',
-    'registration',
 )
 
 DEFAULT_PATCHES_PER_PAGE = 100
 DEFAULT_FROM_EMAIL = 'Patchwork <patchwork@patchwork.example.com>'
 
-ACCOUNT_ACTIVATION_DAYS = 7
+CONFIRMATION_VALIDITY_DAYS = 7
+
+NOTIFICATION_DELAY_MINUTES = 10
+NOTIFICATION_FROM_EMAIL = DEFAULT_FROM_EMAIL
 
 # Set to True to enable the Patchwork XML-RPC interface
 ENABLE_XMLRPC = False
index 3894708af605363d875a22f6ed70dbeb426e7c8b..4ddef9e15532e864a7cc2a963d60113fea10b45b 100644 (file)
@@ -23,9 +23,6 @@ from django.conf.urls.defaults import *
 from django.conf import settings
 from django.contrib import admin
 
-from registration.views import register
-from patchwork.forms import RegistrationForm
-
 admin.autodiscover()
 
 htdocs = os.path.join(settings.ROOT_DIR, 'htdocs')
@@ -34,13 +31,6 @@ urlpatterns = patterns('',
     # Example:
     (r'^', include('patchwork.urls')),
 
-    # override the default registration form
-    url(r'^accounts/register/$',
-        register, {'form_class': RegistrationForm},
-        name='registration_register'),
-
-    (r'^accounts/', include('registration.urls')),
-
     # Uncomment this for admin:
      (r'^admin/', include(admin.site.urls)),
 
index ee87e4d5d58837c87a525f6b1e922ce77a361996..c63d6f707e08690c38539a15247bd5a09ebb1df0 100644 (file)
@@ -81,17 +81,6 @@ in brackets):
          cd ../python
          ln -s ../packages/django/django ./django
 
-        We also use the django-registration infrastructure from
-        http://bitbucket.org/ubernostrum/django-registration/. Your distro
-        may provide the django-registration python module (in Ubuntu/Debian it's
-        called 'python-django-registration'). If not, download the module
-        and symlink it to lib/python/ :
-
-         cd lib/packages/
-         hg clone http://bitbucket.org/ubernostrum/django-registration/
-         cd ../python
-         ln -s ../packages/django-registration/registration ./registration
-
         We also use some Javascript libraries:
 
          cd lib/packages
@@ -115,6 +104,8 @@ in brackets):
           ADMINS
           TIME_ZONE
           LANGUAGE_CODE
+          DEFAULT_FROM_EMAIL
+          NOTIFICATION_FROM_EMAIL
 
         You can generate the SECRET_KEY with the following python code:
 
index 4dd6efb611f62e4a885665dd746ad19679059d9d..1bff526f44d20ec750cdb80b5aaa0cdd8c16978c 100644 (file)
@@ -12,7 +12,7 @@ GRANT SELECT, UPDATE, INSERT, DELETE ON auth_user_groups TO 'www-data'@localhost
 GRANT SELECT, UPDATE, INSERT, DELETE ON auth_group TO 'www-data'@localhost;
 GRANT SELECT, UPDATE, INSERT, DELETE ON auth_user_user_permissions TO 'www-data'@localhost;
 GRANT SELECT, UPDATE, INSERT, DELETE ON auth_permission TO 'www-data'@localhost;
-GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_userpersonconfirmation TO 'www-data'@localhost;
+GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_emailconfirmation TO 'www-data'@localhost;
 GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_state TO 'www-data'@localhost;
 GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_comment TO 'www-data'@localhost;
 GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_person TO 'www-data'@localhost;
@@ -22,7 +22,8 @@ GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_project TO 'www-data'@localhos
 GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_bundle TO 'www-data'@localhost;
 GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_bundle_patches TO 'www-data'@localhost;
 GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_patch TO 'www-data'@localhost;
-GRANT SELECT, UPDATE, INSERT, DELETE ON registration_registrationprofile TO 'www-data'@localhost;
+GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_emailoptout TO 'www-data'@localhost;
+GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_patchchangenotification TO 'www-data'@localhost;
 
 -- allow the mail user (in this case, 'nobody') to add patches
 GRANT INSERT, SELECT ON patchwork_patch TO 'nobody'@localhost;
index 6a1a47dab2c0a6dbe61fcd5e585c89816e685406..72abb570e017150195798d5076d9523917ed1a5d 100644 (file)
@@ -13,7 +13,7 @@ GRANT SELECT, UPDATE, INSERT, DELETE ON
        auth_group,
        auth_user_user_permissions,
        auth_permission,
-       patchwork_userpersonconfirmation,
+       patchwork_emailconfirmation,
        patchwork_state,
        patchwork_comment,
        patchwork_person,
@@ -23,7 +23,8 @@ GRANT SELECT, UPDATE, INSERT, DELETE ON
        patchwork_bundle,
        patchwork_bundlepatch,
        patchwork_patch,
-       registration_registrationprofile
+       patchwork_emailoptout,
+       patchwork_patchchangenotification
 TO "www-data";
 GRANT SELECT, UPDATE ON
        auth_group_id_seq,
@@ -43,10 +44,10 @@ GRANT SELECT, UPDATE ON
        patchwork_person_id_seq,
        patchwork_project_id_seq,
        patchwork_state_id_seq,
-       patchwork_userpersonconfirmation_id_seq,
+       patchwork_emailconfirmation_id_seq,
        patchwork_userprofile_id_seq,
        patchwork_userprofile_maintainer_projects_id_seq,
-       registration_registrationprofile_id_seq
+       patchwork_patchchangenotification_id_seq
 TO "www-data";
 
 -- allow the mail user (in this case, 'nobody') to add patches
diff --git a/lib/sql/migration/008-confirmations.sql b/lib/sql/migration/008-confirmations.sql
new file mode 100644 (file)
index 0000000..89437a2
--- /dev/null
@@ -0,0 +1,11 @@
+BEGIN;
+ALTER TABLE "patchwork_userpersonconfirmation"
+        RENAME TO "patchwork_emailconfirmation";
+ALTER SEQUENCE "patchwork_userpersonconfirmation_id_seq"
+        RENAME TO "patchwork_emailconfirmation_id_seq";
+ALTER TABLE "patchwork_emailconfirmation"
+        ALTER COLUMN "user_id" DROP NOT NULL,
+        ADD COLUMN "type" varchar(20) NOT NULL DEFAULT 'userperson';
+ALTER TABLE "patchwork_emailconfirmation"
+        ALTER COLUMN "type" DROP DEFAULT;
+COMMIT;
diff --git a/lib/sql/migration/009-drop-registrationprofile.sql b/lib/sql/migration/009-drop-registrationprofile.sql
new file mode 100644 (file)
index 0000000..f1c2b43
--- /dev/null
@@ -0,0 +1,27 @@
+BEGIN;
+
+DELETE FROM registration_registrationprofile;
+
+-- unlink users who have contributed
+
+UPDATE patchwork_person SET user_id = NULL
+    WHERE user_id IN (SELECT id FROM auth_user WHERE is_active = False)
+           AND id IN (SELECT DISTINCT submitter_id FROM patchwork_comment);
+
+-- remove persons who only have a user linkage
+
+DELETE FROM patchwork_person WHERE user_id IN
+    (SELECT id FROM auth_user WHERE is_active = False);
+
+-- delete profiles
+
+DELETE FROM patchwork_userprofile WHERE user_id IN
+    (SELECT id FROM auth_user WHERE is_active = False);
+
+-- delete inactive users
+
+DELETE FROM auth_user WHERE is_active = False;
+
+DROP TABLE registration_registrationprofile;
+
+COMMIT;
diff --git a/lib/sql/migration/010-optout-tables.sql b/lib/sql/migration/010-optout-tables.sql
new file mode 100644 (file)
index 0000000..0a5d835
--- /dev/null
@@ -0,0 +1,5 @@
+BEGIN;
+CREATE TABLE "patchwork_emailoptout" (
+    "email" varchar(200) NOT NULL PRIMARY KEY
+);
+COMMIT;
diff --git a/lib/sql/migration/011-patch-change-notifications.sql b/lib/sql/migration/011-patch-change-notifications.sql
new file mode 100644 (file)
index 0000000..0a9b9b7
--- /dev/null
@@ -0,0 +1,12 @@
+BEGIN;
+CREATE TABLE "patchwork_patchchangenotification" (
+    "patch_id" integer NOT NULL PRIMARY KEY REFERENCES "patchwork_patch" ("id") DEFERRABLE INITIALLY DEFERRED,
+    "last_modified" timestamp with time zone NOT NULL,
+    "orig_state_id" integer NOT NULL REFERENCES "patchwork_state" ("id") DEFERRABLE INITIALLY DEFERRED
+)
+;
+ALTER TABLE "patchwork_project" ADD COLUMN
+    "send_notifications" boolean NOT NULL DEFAULT False;
+ALTER TABLE "patchwork_project" ALTER COLUMN
+    "send_notifications" DROP DEFAULT;
+COMMIT;
index e14470e8c4c33feec0059de909777e6a89dcbd98..d3b8e6776690471e7bb2941bfbe95da0fb4da7af 100644 (file)
@@ -30,7 +30,9 @@
 {% else %}
      <a href="{% url auth_login %}">login</a>
      <br/>
-     <a href="{% url registration_register %}">register</a>
+     <a href="{% url patchwork.views.user.register %}">register</a>
+     <br/>
+     <a href="{% url patchwork.views.mail.settings %}">mail settings</a>
 {% endif %}
    </div>
    <div style="clear: both;"></div>
diff --git a/templates/patchwork/activation_email.txt b/templates/patchwork/activation_email.txt
new file mode 100644 (file)
index 0000000..e918e5f
--- /dev/null
@@ -0,0 +1,11 @@
+Hi,
+
+This email is to confirm your account on the patchwork patch-tracking
+system. You can activate your account by visiting the url:
+
+ http://{{site.domain}}{% url patchwork.views.confirm key=confirmation.key %}
+
+If you didn't request a user account on patchwork, then you can ignore
+this mail.
+
+Happy patchworking.
diff --git a/templates/patchwork/activation_email_subject.txt b/templates/patchwork/activation_email_subject.txt
new file mode 100644 (file)
index 0000000..c409f38
--- /dev/null
@@ -0,0 +1 @@
+Patchwork account confirmation
diff --git a/templates/patchwork/confirm-error.html b/templates/patchwork/confirm-error.html
new file mode 100644 (file)
index 0000000..81292e2
--- /dev/null
@@ -0,0 +1,19 @@
+{% extends "base.html" %}
+
+{% block title %}Confirmation{% endblock %}
+{% block heading %}Confirmation{% endblock %}
+
+
+{% block body %}
+
+{% if error == 'inactive' %}
+<p>This confirmation has already been processed; you've probably visited this
+page before.</p>
+{% endif %}
+
+{% if error == 'expired' %}
+<p>The confirmation has expired. If you'd still like to perform the
+{{conf.get_type_display}} process, you'll need to resubmit the request.</p>
+{% endif %}
+
+{% endblock %}
index edc381ec4618ad6dde8943eec46227766525f4f7..0d784d7fcbd9d537705c3d88fe0d5966f9a216fa 100644 (file)
 <p>Patchwork is built on the <a href="http://djangoproject.com/">django</a>
 web framework.</p>
 
-<p>Patchwork includes the <a
-href="http://code.google.com/p/django-registration/">django-registration</a>
-application.</p>
-
 <p>Icons from the <a href="http://sweetie.sublink.ca/">Sweetie</a> icon set.</a>
 
 {% endblock %}
diff --git a/templates/patchwork/login.html b/templates/patchwork/login.html
new file mode 100644 (file)
index 0000000..2dfc2a7
--- /dev/null
@@ -0,0 +1,27 @@
+{% extends "base.html" %}
+
+{% block title %}Login{% endblock %}
+{% block heading %}Login{% endblock %}
+
+
+{% block body %}
+<form method="post">
+{% csrf_token %}
+<table class="form loginform">
+ <tr>
+  <th colspan="2" class="headerrow">login</th>
+ </tr>
+ {% if error %}
+  <tr>
+   <td colspan="2">{{ error }}</td>
+  </tr>
+ {% endif %}
+ {{ form }}
+ <tr>
+  <td colspan="2" class="submitrow">
+   <input type="submit" value="Login"/>
+  </td>
+ </tr>
+</table>
+</form>
+{% endblock %}
diff --git a/templates/patchwork/logout.html b/templates/patchwork/logout.html
new file mode 100644 (file)
index 0000000..f030aee
--- /dev/null
@@ -0,0 +1,8 @@
+{% extends "base.html" %}
+
+{% block title %}Logout{% endblock %}
+{% block heading %}Logout{% endblock %}
+
+{% block body %}
+<p>Logged out</p>
+{% endblock %}
diff --git a/templates/patchwork/mail-form.html b/templates/patchwork/mail-form.html
new file mode 100644 (file)
index 0000000..d71b2fb
--- /dev/null
@@ -0,0 +1,38 @@
+{% extends "base.html" %}
+
+{% block title %}mail settings{% endblock %}
+{% block heading %}mail settings{% endblock %}
+
+{% block body %}
+
+<p>You can configure patchwork to send you mail on certain events,
+or block automated mail altogether. Enter your email address to
+view or change your email settings.</p>
+
+<form method="post">
+{% csrf_token %}
+<table class="form registerform">
+{% if form.errors %}
+ <tr>
+  <td colspan="2" class="error">
+   There was an error accessing your mail settings:
+  </td>
+ </tr>
+{% endif %}
+ <tr>
+  <th>{{ form.email.label_tag }}</th>
+  <td>
+   {{form.email}}
+   {{form.email.errors}}
+  </td>
+ </tr>
+ <tr>
+  <td colspan="2" class="submitrow">
+   <input type="submit" value="Access mail settings"/>
+  </td>
+ </tr>
+</table>
+</form>
+
+
+{% endblock %}
diff --git a/templates/patchwork/mail-settings.html b/templates/patchwork/mail-settings.html
new file mode 100644 (file)
index 0000000..303139a
--- /dev/null
@@ -0,0 +1,37 @@
+{% extends "base.html" %}
+
+{% block title %}mail settings{% endblock %}
+{% block heading %}mail settings{% endblock %}
+
+{% block body %}
+<p>Settings for <strong>{{email}}</strong>:</p>
+
+<table class="horizontal">
+ <tr>
+  <th>Opt-out list</th>
+{% if is_optout %}
+  <td>Patchwork <strong>may not</strong> send automated notifications to
+   this address.</td>
+  <td>
+   <form method="post" action="{% url patchwork.views.mail.optin %}">
+    {% csrf_token %}
+    <input type="hidden" name="email" value="{{email}}"/>
+    <input type="submit" value="Opt-in"/>
+   </form>
+  </td>
+   
+{% else %}
+  <td>Patchwork <strong>may</strong> send automated notifications to
+   this address.</td>
+  <td>
+   <form method="post" action="{% url patchwork.views.mail.optout %}">
+    {% csrf_token %}
+    <input type="hidden" name="email" value="{{email}}"/>
+    <input type="submit" value="Opt-out"/>
+   </form>
+  </td>
+{% endif %}
+ </tr>
+</table>
+
+{% endblock %}
diff --git a/templates/patchwork/optin-request.html b/templates/patchwork/optin-request.html
new file mode 100644 (file)
index 0000000..63a4e12
--- /dev/null
@@ -0,0 +1,50 @@
+{% extends "base.html" %}
+
+{% block title %}opt-in{% endblock %}
+{% block heading %}opt-in{% endblock %}
+
+{% block body %}
+{% if email_sent %}
+<p><strong>Opt-in confirmation email sent</strong></p>
+<p>An opt-in confirmation mail has been sent to
+<strong>{{confirmation.email}}</strong>, containing a link. Please click on
+that link to confirm your opt-in.</p>
+{% else %}
+{% if error %}
+<p class="error">{{error}}</p>
+{% endif %}
+
+{% if form %}
+<p>This form allows you to opt-in to automated email from patchwork. Use
+this if you have previously opted-out of patchwork mail, but now want to
+received notifications from patchwork.</p>
+When you submit it, an email will be sent to your address with a link to click
+to finalise the opt-in. Patchwork does this to prevent someone opting you in
+without your consent.</p>
+<form method="post" action="">
+{% csrf_token %}
+{{form.email.errors}}
+<div style="padding: 0.5em 1em 2em;">
+{{form.email.label_tag}}: {{form.email}}
+</div>
+<input type="submit" value="Send me an opt-in link">
+</form>
+{% endif %}
+
+{% if error and admins %}
+<p>If you are having trouble opting in, please email
+{% for admin in admins %}
+{% if admins|length > 1 and forloop.last %} or {% endif %}
+{{admin.0}} &lt;<a href="mailto:{{admin.1}}">{{admin.1}}</a
+>&gt;{% if admins|length > 2 and not forloop.last %}, {% endif %}
+{% endfor %}
+{% endif %}
+
+{% endif %}
+
+{% if user.is_authenticated %}
+<p>Return to your <a href="{% url patchwork.views.user.profile %}">user
+profile</a>.</p>
+{% endif %}
+
+{% endblock %}
diff --git a/templates/patchwork/optin-request.mail b/templates/patchwork/optin-request.mail
new file mode 100644 (file)
index 0000000..34dd2c7
--- /dev/null
@@ -0,0 +1,12 @@
+Hi,
+
+This email is to confirm that you would like to opt-in to automated
+email from the patchwork system at {{site.domain}}.
+
+To complete the opt-in process, visit:
+
+ http://{{site.domain}}{% url patchwork.views.confirm key=confirmation.key %}
+
+If you didn't request this opt-in, you don't need to do anything.
+
+Happy patchworking.
diff --git a/templates/patchwork/optin.html b/templates/patchwork/optin.html
new file mode 100644 (file)
index 0000000..f7c0c04
--- /dev/null
@@ -0,0 +1,19 @@
+{% extends "base.html" %}
+
+{% block title %}opt-in{% endblock %}
+{% block heading %}opt-in{% endblock %}
+
+{% block body %}
+
+<p><strong>Opt-in complete</strong>. You have sucessfully opted back in to
+automated email from this patchwork system, using the address
+<strong>{{email}}</strong>.</p>
+<p>If you later decide that you no longer want to receive automated mail from
+patchwork, just visit <a href="{% url patchwork.views.mail.settings %}"
+>http://{{site.domain}}{% url patchwork.views.mail.settings %}</a>, or
+visit the main patchwork page and navigate from there.</p>
+{% if user.is_authenticated %}
+<p>Return to your <a href="{% url patchwork.views.user.profile %}">user
+profile</a>.</p>
+{% endif %}
+{% endblock %}
diff --git a/templates/patchwork/optout-request.html b/templates/patchwork/optout-request.html
new file mode 100644 (file)
index 0000000..dbdf250
--- /dev/null
@@ -0,0 +1,51 @@
+{% extends "base.html" %}
+
+{% block title %}opt-out{% endblock %}
+{% block heading %}opt-out{% endblock %}
+
+{% block body %}
+{% if email_sent %}
+<p><strong>Opt-out confirmation email sent</strong></p>
+<p>An opt-out confirmation mail has been sent to
+<strong>{{confirmation.email}}</strong>, containing a link. Please click on
+that link to confirm your opt-out.</p>
+{% else %}
+{% if error %}
+<p class="error">{{error}}</p>
+{% endif %}
+
+{% if form %}
+<p>This form allows you to opt-out of automated email from patchwork.</p>
+<p>If you opt-out of email, Patchwork may still email you if you do certain
+actions yourself (such as create a new patchwork account), but will not send
+you unsolicited email.</p>
+When you submit it, one email will be sent to your address with a link to click
+to finalise the opt-out. Patchwork does this to prevent someone opting you out
+without your consent.</p>
+<form method="post" action="">
+{% csrf_token %}
+{{form.email.errors}}
+<div style="padding: 0.5em 1em 2em;">
+{{form.email.label_tag}}: {{form.email}}
+</div>
+<input type="submit" value="Send me an opt-out link">
+</form>
+{% endif %}
+
+{% if error and admins %}
+<p>If you are having trouble opting out, please email
+{% for admin in admins %}
+{% if admins|length > 1 and forloop.last %} or {% endif %}
+{{admin.0}} &lt;<a href="mailto:{{admin.1}}">{{admin.1}}</a
+>&gt;{% if admins|length > 2 and not forloop.last %}, {% endif %}
+{% endfor %}
+{% endif %}
+
+{% endif %}
+
+{% if user.is_authenticated %}
+<p>Return to your <a href="{% url patchwork.views.user.profile %}">user
+profile</a>.</p>
+{% endif %}
+
+{% endblock %}
diff --git a/templates/patchwork/optout-request.mail b/templates/patchwork/optout-request.mail
new file mode 100644 (file)
index 0000000..f896e3c
--- /dev/null
@@ -0,0 +1,12 @@
+Hi,
+
+This email is to confirm that you would like to opt-out from all email
+from the patchwork system at {{site.domain}}.
+
+To complete the opt-out process, visit:
+
+ http://{{site.domain}}{% url patchwork.views.confirm key=confirmation.key %}
+
+If you didn't request this opt-out, you don't need to do anything.
+
+Happy patchworking.
diff --git a/templates/patchwork/optout.html b/templates/patchwork/optout.html
new file mode 100644 (file)
index 0000000..6b97806
--- /dev/null
@@ -0,0 +1,22 @@
+{% extends "base.html" %}
+
+{% block title %}opt-out{% endblock %}
+{% block heading %}opt-out{% endblock %}
+
+{% block body %}
+
+<p><strong>Opt-out complete</strong>. You have successfully opted-out of
+automated notifications from this patchwork system, from the address
+<strong>{{email}}</strong></p>
+<p>Please note that you may still receive email from other patchwork setups at
+different sites, as they are run independently. You may need to opt-out of
+those separately.</p>
+<p>If you later decide to receive mail from patchwork, just visit
+<a href="{% url patchwork.views.mail.settings %}"
+>http://{{site.domain}}{% url patchwork.views.mail.settings %}</a>, or
+visit the main patchwork page and navigate from there.</p>
+{% if user.is_authenticated %}
+<p>Return to your <a href="{% url patchwork.views.user.profile %}">user
+profile</a>.</p>
+{% endif %}
+{% endblock %}
diff --git a/templates/patchwork/patch-change-notification-subject.text b/templates/patchwork/patch-change-notification-subject.text
new file mode 100644 (file)
index 0000000..02ee55b
--- /dev/null
@@ -0,0 +1 @@
+Patch update notification: {{notifications|length}} patch{{notifications|length|pluralize:"es"}} updated
diff --git a/templates/patchwork/patch-change-notification.mail b/templates/patchwork/patch-change-notification.mail
new file mode 100644 (file)
index 0000000..d86a6af
--- /dev/null
@@ -0,0 +1,19 @@
+Hello,
+
+The following patch{{notifications|length|pluralize:"es"}} (submitted by you) {{notifications|length|pluralize:"has,have"}} been updated in patchwork:
+{% for notification in notifications %}
+ * {{notification.patch.name}}
+     - http://{{site.domain}}{{notification.patch.get_absolute_url}}
+    was: {{notification.orig_state}}
+    now: {{notification.patch.state}}
+{% endfor %}
+This email is a notification only - you do not need to respond.
+
+Happy patchworking.
+
+--
+
+This is an automated mail sent by the patchwork system at
+{{site.domain}}. To stop receiving these notifications, edit
+your mail settings at:
+  http://{{site.domain}}{% url patchwork.views.mail.settings %}
index 44df9219122576deee36337e7566144a51d2c4b3..130b94732500b657f6003ac3e15b26e502c0bf97 100644 (file)
@@ -40,34 +40,50 @@ Contributor to
 <p>The following email addresses are associated with this patchwork account.
 Adding alternative addresses allows patchwork to group contributions that
 you have made under different addresses.</p>
+<p>The "notify?" column allows you to opt-in or -out of automated
+patchwork notification emails. Setting it to "no" will disable automated
+notifications for that address.</p>
 <p>Adding a new email address will send a confirmation email to that
 address.</p>
-<table class="vertical" style="width: 20em;">
+<table class="vertical">
  <tr>
   <th>email</th>
-  <th/>
- </tr>
- <tr>
-  <td>{{ user.email }}</td>
-  <td></td>
+  <th>action</th>
+  <th>notify?</th>
  </tr>
 {% for email in linked_emails %}
- {% ifnotequal email.email user.email %}
  <tr>
   <td>{{ email.email }}</td>
   <td>
-   {% ifnotequal user.email email.email %}
+  {% ifnotequal user.email email.email %}
    <form action="{% url patchwork.views.user.unlink person_id=email.id %}"
     method="post">
     {% csrf_token %}
     <input type="submit" value="Unlink"/>
    </form>
     {% endifnotequal %}
+  </td>
+  <td>
+   {% if email.is_optout %}
+   <form method="post" action="{% url patchwork.views.mail.optin %}">
+    No,
+     {% csrf_token %}
+     <input type="hidden" name="email" value="{{email.email}}"/>
+     <input type="submit" value="Opt-in"/>
+    </form>
+   {% else %}
+    <form method="post" action="{% url patchwork.views.mail.optout %}">
+    Yes,
+     {% csrf_token %}
+     <input type="hidden" name="email" value="{{email.email}}"/>
+     <input type="submit" value="Opt-out"/>
+    </form>
+   {% endif %}
+  </td>
  </tr>
- {% endifnotequal %}
 {% endfor %}
  <tr>
-  <td colspan="2">
+  <td colspan="3">
    <form action="{% url patchwork.views.user.link %}" method="post">
     {% csrf_token %}
     {{ linkform.email }}
diff --git a/templates/patchwork/registration-confirm.html b/templates/patchwork/registration-confirm.html
new file mode 100644 (file)
index 0000000..f0cc39f
--- /dev/null
@@ -0,0 +1,13 @@
+{% extends "base.html" %}
+
+{% block title %}Registration{% endblock %}
+{% block heading %}Registration{% endblock %}
+
+{% block body %}
+<p>Registraton confirmed!</p>
+
+<p>Your patchwork registration is complete. Head over to your <a
+ href="{% url patchwork.views.user.profile %}">profile</a> to start using
+patchwork's extra features.</p>
+
+{% endblock %}
diff --git a/templates/patchwork/registration_form.html b/templates/patchwork/registration_form.html
new file mode 100644 (file)
index 0000000..3a314b8
--- /dev/null
@@ -0,0 +1,121 @@
+{% extends "base.html" %}
+
+{% block title %}Registration{% endblock %}
+{% block heading %}Registration{% endblock %}
+
+
+{% block body %}
+
+{% if confirmation and not error %}
+ <p>Registration successful!</p>
+ <p>A confirmation email has been sent to {{ confirmation.email }}. You'll
+ need to visit the link provided in that email to confirm your
+ registration.</p>
+</p>
+{% else %}
+<p>By creating a patchwork account, you can:<p>
+<ul>
+ <li>create "bundles" of patches</li>
+ <li>update the state of your own patches</li>
+</ul>
+<form method="post">
+{% csrf_token %}
+<table class="form registerform">
+ <tr>
+  <th colspan="2" class="headerrow">register</th>
+ </tr>
+ {% if error %}
+  <tr>
+   <td colspan="2">{{ error }}</td>
+  </tr>
+ {% endif %}
+
+  <tr>
+   <td>{{ form.first_name.label_tag }}</td>
+   <td>
+{% if form.first_name.errors %}
+    {{ form.first_name.errors }}
+{% endif %}
+    {{ form.first_name }}
+{% if form.first_name.help_text %}
+    <div class="help_text"/>{{ form.first_name.help_text }}</div>
+{% endif %}
+   </td>
+  </tr>
+   
+  <tr>
+   <td>{{ form.last_name.label_tag }}</td>
+   <td>
+{% if form.last_name.errors %}
+    {{ form.last_name.errors }}
+{% endif %}
+    {{ form.last_name }}
+{% if form.last_name.help_text %}
+    <div class="help_text"/>{{ form.last_name.help_text }}</div>
+{% endif %}
+   </td>
+  </tr>
+
+  <tr>
+   <td></td>
+   <td class="form-help">
+    Your name is used to identify you on the site
+   </td>
+  </tr>
+   
+  <tr>
+   <td>{{ form.email.label_tag }}</td>
+   <td>
+{% if form.email.errors %}
+    {{ form.email.errors }}
+{% endif %}
+    {{ form.email }}
+{% if form.email.help_text %}
+    <div class="help_text"/>{{ form.email.help_text }}</div>
+{% endif %}
+   </td>
+  </tr>
+   
+  <tr>
+   <td></td>
+   <td class="form-help">
+    Patchwork will send a confirmation email to this address
+   </td>
+  </tr>
+
+  <tr>
+   <td>{{ form.username.label_tag }}</td>
+   <td>
+{% if form.username.errors %}
+    {{ form.username.errors }}
+{% endif %}
+    {{ form.username }}
+{% if form.username.help_text %}
+    <div class="help_text"/>{{ form.username.help_text }}</div>
+{% endif %}
+   </td>
+  </tr>
+   
+  <tr>
+   <td>{{ form.password.label_tag }}</td>
+   <td>
+{% if form.password.errors %}
+    {{ form.password.errors }}
+{% endif %}
+    {{ form.password }}
+{% if form.password.help_text %}
+    <div class="help_text"/>{{ form.password.help_text }}</div>
+{% endif %}
+   </td>
+  </tr>
+
+   <tr>
+  <td colspan="2" class="submitrow">
+   <input type="submit" value="Register"/>
+  </td>
+ </tr>
+</table>
+</form>
+{% endif %}
+
+{% endblock %}
index 5f74d3bbfe9d16c2a011abdede40412dd31fd8eb..c483181578b94c656ab2cb5ba31dc7c1ac9fe005 100644 (file)
@@ -7,6 +7,6 @@ This email is to confirm that you own the email address:
 So that you can add it to your patchwork profile. You can confirm this
 email address by visiting the url:
 
- http://{{site.domain}}{% url patchwork.views.user.link_confirm key=confirmation.key %}
+ http://{{site.domain}}{% url patchwork.views.confirm key=confirmation.key %}
 
 Happy patchworking.
diff --git a/templates/registration/activate.html b/templates/registration/activate.html
deleted file mode 100644 (file)
index f0cc39f..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-{% extends "base.html" %}
-
-{% block title %}Registration{% endblock %}
-{% block heading %}Registration{% endblock %}
-
-{% block body %}
-<p>Registraton confirmed!</p>
-
-<p>Your patchwork registration is complete. Head over to your <a
- href="{% url patchwork.views.user.profile %}">profile</a> to start using
-patchwork's extra features.</p>
-
-{% endblock %}
diff --git a/templates/registration/activation_email.txt b/templates/registration/activation_email.txt
deleted file mode 100644 (file)
index 6b1477d..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-Hi,
-
-This email is to confirm your account on the patchwork patch-tracking
-system. You can activate your account by visiting the url:
-
- http://{{site.domain}}{% url registration_activate activation_key=activation_key %}
-
-If you didn't request a user account on patchwork, then you can ignore
-this mail.
-
-Happy patchworking.
diff --git a/templates/registration/activation_email_subject.txt b/templates/registration/activation_email_subject.txt
deleted file mode 100644 (file)
index c409f38..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Patchwork account confirmation
diff --git a/templates/registration/login.html b/templates/registration/login.html
deleted file mode 100644 (file)
index 2dfc2a7..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-{% extends "base.html" %}
-
-{% block title %}Login{% endblock %}
-{% block heading %}Login{% endblock %}
-
-
-{% block body %}
-<form method="post">
-{% csrf_token %}
-<table class="form loginform">
- <tr>
-  <th colspan="2" class="headerrow">login</th>
- </tr>
- {% if error %}
-  <tr>
-   <td colspan="2">{{ error }}</td>
-  </tr>
- {% endif %}
- {{ form }}
- <tr>
-  <td colspan="2" class="submitrow">
-   <input type="submit" value="Login"/>
-  </td>
- </tr>
-</table>
-</form>
-{% endblock %}
diff --git a/templates/registration/logout.html b/templates/registration/logout.html
deleted file mode 100644 (file)
index f030aee..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-{% extends "base.html" %}
-
-{% block title %}Logout{% endblock %}
-{% block heading %}Logout{% endblock %}
-
-{% block body %}
-<p>Logged out</p>
-{% endblock %}
diff --git a/templates/registration/registration_complete.html b/templates/registration/registration_complete.html
deleted file mode 100644 (file)
index a89c116..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-{% extends "base.html" %}
-
-{% block title %}Registration{% endblock %}
-{% block heading %}Registration{% endblock %}
-
-{% block body %}
-
- <p>Registration successful!</p>
- <p>A confirmation email has been sent to your email address. You'll
- need to visit the link provided in that email to activate your
- patchwork account.</p>
-
-{% endblock %}
diff --git a/templates/registration/registration_form.html b/templates/registration/registration_form.html
deleted file mode 100644 (file)
index e2b17c1..0000000
+++ /dev/null
@@ -1,122 +0,0 @@
-{% extends "base.html" %}
-
-{% block title %}Registration{% endblock %}
-{% block heading %}Registration{% endblock %}
-
-
-{% block body %}
-
-{% if request and not error %}
- <p>Registration successful!</p>
- <p>A confirmation email has been sent to {{ request.email }}. You'll
- need to visit the link provided in that email to confirm your
- registration.</p>
- <pre>{{email}}</pre>
-</p>
-{% else %}
-<p>By creating a patchwork account, you can:<p>
-<ul>
- <li>create "bundles" of patches</li>
- <li>update the state of your own patches</li>
-</ul>
-<form method="post">
-{% csrf_token %}
-<table class="form registerform">
- <tr>
-  <th colspan="2" class="headerrow">register</th>
- </tr>
- {% if error %}
-  <tr>
-   <td colspan="2">{{ error }}</td>
-  </tr>
- {% endif %}
-
-  <tr>
-   <td>{{ form.first_name.label_tag }}</td>
-   <td>
-{% if form.first_name.errors %}
-    {{ form.first_name.errors }}
-{% endif %}
-    {{ form.first_name }}
-{% if form.first_name.help_text %}
-    <div class="help_text"/>{{ form.first_name.help_text }}</div>
-{% endif %}
-   </td>
-  </tr>
-   
-  <tr>
-   <td>{{ form.last_name.label_tag }}</td>
-   <td>
-{% if form.last_name.errors %}
-    {{ form.last_name.errors }}
-{% endif %}
-    {{ form.last_name }}
-{% if form.last_name.help_text %}
-    <div class="help_text"/>{{ form.last_name.help_text }}</div>
-{% endif %}
-   </td>
-  </tr>
-
-  <tr>
-   <td></td>
-   <td class="form-help">
-    Your name is used to identify you on the site
-   </td>
-  </tr>
-   
-  <tr>
-   <td>{{ form.email.label_tag }}</td>
-   <td>
-{% if form.email.errors %}
-    {{ form.email.errors }}
-{% endif %}
-    {{ form.email }}
-{% if form.email.help_text %}
-    <div class="help_text"/>{{ form.email.help_text }}</div>
-{% endif %}
-   </td>
-  </tr>
-   
-  <tr>
-   <td></td>
-   <td class="form-help">
-    Patchwork will send a confirmation email to this address
-   </td>
-  </tr>
-
-  <tr>
-   <td>{{ form.username.label_tag }}</td>
-   <td>
-{% if form.username.errors %}
-    {{ form.username.errors }}
-{% endif %}
-    {{ form.username }}
-{% if form.username.help_text %}
-    <div class="help_text"/>{{ form.username.help_text }}</div>
-{% endif %}
-   </td>
-  </tr>
-   
-  <tr>
-   <td>{{ form.password.label_tag }}</td>
-   <td>
-{% if form.password.errors %}
-    {{ form.password.errors }}
-{% endif %}
-    {{ form.password }}
-{% if form.password.help_text %}
-    <div class="help_text"/>{{ form.password.help_text }}</div>
-{% endif %}
-   </td>
-  </tr>
-
-   <tr>
-  <td colspan="2" class="submitrow">
-   <input type="submit" value="Register"/>
-  </td>
- </tr>
-</table>
-</form>
-{% endif %}
-
-{% endblock %}