david / django-invitation-backend (http://code.welldev.org/django-invitation/)
fork of django-invitation
A fork of django-invitation to use the new django-registration-backends branch. See http://bitbucket.org/ubernostrum/django-registr... for the reasons.
Clone this repository (size: 52.2 KB): HTTPS / SSH
$ hg clone http://code.welldev.org/django-invitation-backend
| commit 26: | be8229c1326b |
| parent 25: | 7b31544810e9 |
| branch: | default |
remaining_invitations_for_user creates InvitationUser if it does not exist.
This is a fix for issue #9
http://bitbucket.org/david/django-invitation/issue/9/
Thanks zebuline for the report and patch.
Changed (Δ700 bytes):
raw changeset »
invitation/models.py (5 lines added, 2 lines removed)
invitation/tests.py (9 lines added, 0 lines removed)
Up to file-list invitation/models.py:
| … | … | @@ -50,9 +50,12 @@ class InvitationKeyManager(models.Manage |
50 |
50 |
|
51 |
51 |
def remaining_invitations_for_user(self, user): |
52 |
52 |
""" |
53 |
Return |
|
53 |
Return the number of remaining invitations for a given ``User``. |
|
54 |
54 |
""" |
55 |
|
|
55 |
invitation_user, created = InvitationUser.objects.get_or_create( |
|
56 |
inviter=user, |
|
57 |
defaults={'invitations_remaining': settings.INVITATIONS_PER_USER}) |
|
58 |
return invitation_user.invitations_remaining |
|
56 |
59 |
|
57 |
60 |
def delete_expired_keys(self): |
58 |
61 |
for key in self.all(): |
Up to file-list invitation/tests.py:
| … | … | @@ -121,6 +121,15 @@ class InvitationModelTests(InvitationTes |
121 |
121 |
remaining = remaining_invites(self.sample_user) |
122 |
122 |
self.assertEqual(remaining, new_remaining) |
123 |
123 |
|
124 |
# If no InvitationUser (for pre-existing/legacy User), one is created |
|
125 |
old_sample_user = User.objects.create_user(username='lewis', |
|
126 |
password='secret', |
|
127 |
email='lewis@example.com') |
|
128 |
old_sample_user.invitationuser_set.all().delete() |
|
129 |
self.assertEqual(old_sample_user.invitationuser_set.count(), 0) |
|
130 |
remaining = remaining_invites(old_sample_user) |
|
131 |
self.assertEqual(remaining, settings.INVITATIONS_PER_USER) |
|
132 |
||
124 |
133 |
|
125 |
134 |
class InvitationFormTests(InvitationTestCase): |
126 |
135 |
""" |
