diff --git a/.coveragerc b/.coveragerc index 75a24c2..671ccc9 100644 --- a/.coveragerc +++ b/.coveragerc @@ -4,7 +4,6 @@ src/postorius/tests/*.py src/postorius/tests/*/*.py src/postorius/doc/*.py - src/postorius/south_migrations/*.py src/postorius/migrations/*.py [html] diff --git a/src/postorius/migrations/0003_drop_addressconfirmationprofile.py b/src/postorius/migrations/0003_drop_addressconfirmationprofile.py new file mode 100644 index 0000000..0ec04a8 --- /dev/null +++ b/src/postorius/migrations/0003_drop_addressconfirmationprofile.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2016-08-13 09:48 + +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('postorius', '0002_auto_20160210_0721'), + ] + + operations = [ + migrations.RemoveField( + model_name='addressconfirmationprofile', + name='user', + ), + migrations.DeleteModel( + name='AddressConfirmationProfile', + ), + ] diff --git a/src/postorius/models.py b/src/postorius/models.py index 69779fa..2f63441 100644 --- a/src/postorius/models.py +++ b/src/postorius/models.py @@ -218,87 +218,3 @@ """Member model class. """ objects = MailmanRestManager('member', 'members') - - -class AddressConfirmationProfile(models.Model): - """ - Profile model for temporarily storing an activation key to register - an email address. - """ - email = models.EmailField(unique=True) - activation_key = models.CharField(max_length=32, unique=True) - created = models.DateTimeField(auto_now=True) - user = models.ForeignKey(User) - - def save(self, *args, **kwargs): - self.activation_key = uuid.uuid4().hex - super(AddressConfirmationProfile, self).save(*args, **kwargs) - - def __unicode__(self): - return u'Address Confirmation Profile for {0}'.format(self.email) - - @property - def is_expired(self): - """ - a profile expires after 1 day by default. - This can be configured in the settings. - - >>> EMAIL_CONFIRMATION_EXPIRATION_DELTA = timedelta(days=2) - - """ - expiration_delta = getattr( - settings, 'EMAIL_CONFIRMATION_EXPIRATION_DELTA', timedelta(days=1)) - age = datetime.now().replace(tzinfo=None) - \ - self.created.replace(tzinfo=None) - return age > expiration_delta - - def send_confirmation_link(self, request, template_context=None, - template_path=None): - """ - Send out a message containing a link to activate the given address. - - The following settings are recognized: - - >>> EMAIL_CONFIRMATION_TEMPLATE = \ - 'postorius/user/address_confirmation_message.txt' - >>> EMAIL_CONFIRMATION_FROM = 'postmaster@list.org' - >>> EMAIL_CONFIRMATION_SUBJECT = 'Confirmation needed' - - :param request: The HTTP request object. - :type request: HTTPRequest - :param template_context: The context used when rendering the template. - Falls back to host url and activation link. - :type template_context: django.template.Context - """ - # Get the url string from url conf. - url = reverse('address_activation_link', - kwargs={'activation_key': self.activation_key}) - activation_link = request.build_absolute_uri(url) - # Detect the right template path, either from the param, - # the setting or the default - if not template_path: - template_path = getattr( - settings, 'EMAIL_CONFIRMATION_TEMPLATE', - 'postorius/user/address_confirmation_message.txt') - # Create a template context (if there is none) containing - # the activation_link and the host_url. - if not template_context: - template_context = {'activation_link': activation_link, - 'host_url': request.build_absolute_uri("/")} - email_subject = getattr( - settings, 'EMAIL_CONFIRMATION_SUBJECT', u'Confirmation needed') - try: - sender_address = getattr(settings, 'EMAIL_CONFIRMATION_FROM') - except AttributeError: - # settings.EMAIL_CONFIRMATION_FROM is not defined, fallback - # settings.DEFAULT_EMAIL_FROM as mentioned in the django - # docs. If that also fails, raise a `ImproperlyConfigured` Error. - try: - sender_address = getattr(settings, 'DEFAULT_FROM_EMAIL') - except AttributeError: - raise ImproperlyConfigured - - send_mail(email_subject, - render_to_string(template_path, template_context), - sender_address, - [self.email])