Skip to content

Commit

Permalink
Send email on unregister. Closes #49.
Browse files Browse the repository at this point in the history
  • Loading branch information
fgaudin committed Feb 15, 2011
1 parent bca44bc commit dcb8ae0
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 159 deletions.
11 changes: 11 additions & 0 deletions autoentrepreneur/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
from django.db.models.aggregates import Max
from core.models import OwnedObject
from bugtracker.models import Issue, Comment, Vote
from django.core.mail import send_mail
from django.contrib.sites.models import Site
import datetime
from django.conf import settings

AUTOENTREPRENEUR_ACTIVITY_PRODUCT_SALE_BIC = 1
AUTOENTREPRENEUR_ACTIVITY_SERVICE_BIC = 2
Expand Down Expand Up @@ -70,10 +73,18 @@ class UserProfile(models.Model):
payment_option = models.IntegerField(choices=AUTOENTREPRENEUR_PAYMENT_OPTION, blank=True, null=True, verbose_name=_('Payment option'))

def unregister(self):
user_email = self.user.email
Issue.objects.filter(owner=self.user).update(owner=None)
Comment.objects.filter(owner=self.user).update(owner=None)
Vote.objects.filter(owner=self.user).delete()
self.user.delete()
subject = _("You've just unregistered from %(site)s") % {'site': Site.objects.get_current()}
message = _("You have left the site and your data has been deleted.\n\n"
"Our service is continually evolving and if it does not meet your "
"needs today, please come back to test later.")
from_email = settings.EMAIL_FROM
recipient_list = [user_email]
send_mail(subject, message, from_email, recipient_list, fail_silently=False)

def settings_defined(self):
settings_defined = False
Expand Down
6 changes: 6 additions & 0 deletions autoentrepreneur/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
from bugtracker.models import ISSUE_CATEGORY_BUG, ISSUE_STATE_OPEN, Issue, \
Comment, Vote
from django.core.urlresolvers import reverse
from django.core import mail
from django.contrib.sites.models import Site
from django.utils.translation import ugettext
import datetime

class SubcriptionTest(TestCase):
Expand Down Expand Up @@ -279,3 +282,6 @@ def testUnregister(self):
self.assertEquals(Subscription.objects.filter(owner__id=1).count(), 0)
self.assertEquals(User.objects.filter(pk=1).count(), 0)
self.assertEquals(UserProfile.objects.filter(pk=1).count(), 0)
self.assertEquals(len(mail.outbox), 1)
self.assertEquals(mail.outbox[0].subject, ugettext("You've just unregistered from %(site)s") % {'site': Site.objects.get_current()})
self.assertEquals(mail.outbox[0].to, ['test@example.com'])
Binary file modified locale/en/LC_MESSAGES/django.mo
Binary file not shown.
Loading

0 comments on commit dcb8ae0

Please sign in to comment.