Add groups, allow to ban users from counters and from buying alcohol

This commit is contained in:
2016-10-16 03:45:06 +02:00
parent 1c97c8a74f
commit 2daaf992f2
8 changed files with 155 additions and 163 deletions

View File

@ -1,19 +0,0 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0004_user_godfathers'),
]
operations = [
migrations.AddField(
model_name='user',
name='is_banned_alcohol',
field=models.BooleanField(help_text='Designates whether this user is denyed from buying alchool. ', verbose_name='banned from buying alcohol', default=False),
),
]

View File

@ -169,13 +169,6 @@ class User(AbstractBaseUser):
parent_address = models.CharField(_("parent address"), max_length=128, blank=True, default="")
is_subscriber_viewable = models.BooleanField(_("is subscriber viewable"), default=True)
godfathers = models.ManyToManyField('User', related_name='godchildren', blank=True)
is_banned_alcohol = models.BooleanField(
_('banned from buying alcohol'),
default=False,
help_text=_(
'Designates whether this user is denyed from buying alchool. '
),
)
objects = UserManager()
@ -248,6 +241,14 @@ class User(AbstractBaseUser):
from club.models import Club
return Club.objects.filter(unix_name=settings.SITH_LAUNDERETTE_MANAGER['unix_name']).first().get_membership_for(self)
@property
def is_banned_alcohol(self):
return self.groups.filter(name=settings.SITH_GROUPS['banned-alcohol']['name']).exists()
@property
def is_banned_counter(self):
return self.groups.filter(name=settings.SITH_GROUPS['banned-from-counters']['name']).exists()
def save(self, *args, **kwargs):
create = False
with transaction.atomic():

View File

@ -127,7 +127,7 @@ class UserProfileForm(forms.ModelForm):
fields = ['first_name', 'last_name', 'nick_name', 'email', 'date_of_birth', 'profile_pict', 'avatar_pict',
'scrub_pict', 'sex', 'second_email', 'address', 'parent_address', 'phone', 'parent_phone',
'tshirt_size', 'role', 'department', 'dpt_option', 'semester', 'quote', 'school', 'promo',
'forum_signature', 'is_subscriber_viewable', 'is_banned_alcohol']
'forum_signature', 'is_subscriber_viewable']
widgets = {
'date_of_birth': SelectDate,
'profile_pict': forms.ClearableFileInput,

View File

@ -319,7 +319,7 @@ class UserUpdateProfileView(UserTabsMixin, CanEditMixin, UpdateView):
form_class = UserProfileForm
current_tab = "edit"
edit_once = ['profile_pict', 'date_of_birth', 'first_name', 'last_name']
board_only = ['is_banned_alcohol']
board_only = []
def remove_restricted_fields(self, request):
"""