users can disable notifications

This commit is contained in:
Élie Bouttier 2014-09-04 20:12:38 -07:00
parent 4a61d463bd
commit f420dd98ac
9 changed files with 82 additions and 22 deletions

View file

@ -7,7 +7,7 @@ from accounts.models import *
__all__ = ['UserForm', 'UserFormWithoutUsername', 'ProfileForm', 'GroupForm', 'TeamForm']
user_fields=['first_name', 'last_name', 'email']
user_fields=['first_name', 'last_name', 'email', 'notifications']
UserForm = modelform_factory(User,
fields=['username']+user_fields+['is_superuser'])

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('accounts', '0002_auto_20140905_0229'),
]
operations = [
migrations.AddField(
model_name='user',
name='notifications',
field=models.IntegerField(choices=[(0, 'Never'), (1, 'Ignore my actions'), (2, 'Always')], default=1),
preserve_default=True,
),
]

View file

@ -14,6 +14,18 @@ class User(AbstractUser):
class Meta:
ordering = ['username']
NOTIFICATIONS_NEVER = 0 # do not change: used as boolean value
NOTIFICATIONS_OTHERS = 1
NOTIFICATIONS_ALWAYS = 2
NOTIFICATIONS_CHOICES = (
(NOTIFICATIONS_NEVER, 'Never'),
(NOTIFICATIONS_OTHERS, 'Ignore my actions'),
(NOTIFICATIONS_ALWAYS, 'Always'),
)
notifications = models.IntegerField(choices=NOTIFICATIONS_CHOICES,
default=NOTIFICATIONS_OTHERS)
@property
def teams(self):
query = Q(groups__in=self.groups.all()) | Q(users=self)

View file

@ -20,6 +20,7 @@ class TestViews(TestCase):
self.assertEqual(response.status_code, 200)
response = self.client.post(reverse('profile'), {
'first_name': 'newfirstname',
'notifications': User.NOTIFICATIONS_OTHERS,
}, follow=True)
self.assertRedirects(response, reverse('profile'))
self.assertContains(response, 'successfully')
@ -46,6 +47,7 @@ class TestViews(TestCase):
user_count = User.objects.count()
response = self.client.post(reverse('add-user'), {
'username': 'newuser',
'notifications': User.NOTIFICATIONS_OTHERS,
})
self.assertEqual(User.objects.count(), user_count + 1)
user = User.objects.get(username='newuser')
@ -63,6 +65,7 @@ class TestViews(TestCase):
response = self.client.post(reverse('edit-user', args=[user.id]), {
'username': user.username,
'first_name': 'newfirstname',
'notifications': User.NOTIFICATIONS_OTHERS,
})
self.assertRedirects(response, reverse('show-user', args=[user.id]))
user = User.objects.get(pk=user.pk)