Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor invite accepting logic into model methods

  • Loading branch information...
commit 5c66959ca2131335c33bd9c14d4aa6391cd43b2e 1 parent 3e1be39
@paltman paltman authored
Showing with 12 additions and 9 deletions.
  1. +11 −1 kaleo/models.py
  2. +1 −8 kaleo/receivers.py
View
12 kaleo/models.py
@@ -6,7 +6,7 @@
from account.models import SignupCode
-from kaleo.signals import invite_sent
+from kaleo.signals import invite_sent, invite_accepted
DEFAULT_INVITE_EXPIRATION = getattr(settings, "KALEO_DEFAULT_EXPIRATION", 168) # 168 Hours = 7 Days
@@ -39,6 +39,12 @@ class JoinInvitation(models.Model):
def to_user_email(self):
return self.signup_code.email
+ def accept(self, user):
+ self.to_user = user
+ self.status = JoinInvitation.STATUS_ACCEPTED
+ self.save()
+ self.from_user.invitationstat.increment_accepted()
+ invite_accepted.send(sender=JoinInvitation, invitation=self)
@classmethod
def invite(cls, from_user, to_email, message=None):
if not from_user.invitationstat.can_send():
@@ -72,6 +78,10 @@ class InvitationStat(models.Model):
invites_allocated = models.IntegerField(default=DEFAULT_INVITE_ALLOCATION)
invites_accepted = models.IntegerField(default=0)
+ def increment_accepted(self):
+ self.invites_accepted += 1
+ self.save()
+
@classmethod
def add_invites_to_user(cls, user, amount):
stat, _ = InvitationStat.objects.get_or_create(user=user)
View
9 kaleo/receivers.py
@@ -7,7 +7,6 @@
from account.signals import signup_code_used, email_confirmed
from kaleo.models import JoinInvitation, InvitationStat
-from kaleo.signals import invite_accepted
@receiver(signup_code_used, sender=SignupCodeResult)
@@ -15,13 +14,7 @@ def handle_signup_code_used(sender, **kwargs):
result = kwargs.get("signup_code_result")
try:
invite = result.signup_code.joininvitation
- invite.to_user = result.user
- invite.status = JoinInvitation.STATUS_ACCEPTED
- invite.save()
- stat = invite.from_user.invitationstat
- stat.invites_accepted += 1
- stat.save()
- invite_accepted.send(sender=JoinInvitation, invitation=invite)
+ invite.accept(result.user)
except JoinInvitation.DoesNotExist:
pass
Please sign in to comment.
Something went wrong with that request. Please try again.