Permalink
Browse files

Added a resend flag to utils.invite

Version bump
  • Loading branch information...
1 parent c0f7a3a commit 8f62bf710e7fed2c27134be21470ffa1f8001f0e @flashingpumpkin flashingpumpkin committed Mar 28, 2012
Showing with 14 additions and 2 deletions.
  1. +1 −1 inviter/__init__.py
  2. +9 −0 inviter/tests.py
  3. +4 −1 inviter/utils.py
View
@@ -1 +1 @@
-__version__ = "0.2.3"
+__version__ = "0.2.4"
View
@@ -36,12 +36,21 @@ def test_inviting(self):
self.assertEqual(1, len(mail.outbox))
self.assertEqual(3, User.objects.count())
+ # Resend the mail
user, sent = invite("foo@example.com", self.inviter)
self.assertTrue(sent)
self.assertFalse(user.is_active)
self.assertEqual(2, len(mail.outbox))
self.assertEqual(3, User.objects.count())
+ # Don't resend the mail
+ user, sent = invite("foo@example.com", self.inviter, resend = False)
+ self.assertFalse(sent)
+ self.assertFalse(user.is_active)
+ self.assertEqual(2, len(mail.outbox))
+ self.assertEqual(3, User.objects.count())
+
+ # Don't send the email to active users
user, sent = invite("existing@example.com", self.inviter)
self.assertFalse(sent)
self.assertTrue(user.is_active)
View
@@ -46,7 +46,7 @@ def send_invite(invitee, inviter, url=None, opt_out_url=None, **kwargs):
send_mail(subject, body, FROM_EMAIL, [invitee.email])
-def invite(email, inviter, sendfn=send_invite, **kwargs):
+def invite(email, inviter, sendfn=send_invite, resend=True, **kwargs):
"""
Invite a given email address and return a ``(User, sent)`` tuple similar
to the Django :meth:`django.db.models.Manager.get_or_create` method.
@@ -87,6 +87,7 @@ def invite(email, inviter, sendfn=send_invite, **kwargs):
:param email: The email address
:param inviter: The user inviting the email address
:param sendfn: An email sending function. Defaults to :attr:`inviter.utils.send_invite`
+ :param resend: Resend email to users that are not registered yet
"""
if OptOut.objects.is_blocked(email):
@@ -95,6 +96,8 @@ def invite(email, inviter, sendfn=send_invite, **kwargs):
user = User.objects.get(email=email)
if user.is_active:
return user, False
+ if not resend:
+ return user, False
except User.DoesNotExist:
user = User.objects.create(
username=shortuuid.uuid(),

0 comments on commit 8f62bf7

Please sign in to comment.