Commit 2daaf992 authored by Sli's avatar Sli

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

parent 1c97c8a7
Pipeline #302 failed with stage
in 3 minutes and 34 seconds
# -*- 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),
),
]
......@@ -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():
......
......@@ -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,
......
......@@ -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):
"""
......
......@@ -284,6 +284,9 @@ class CounterClick(CounterTabsMixin, DetailView):
if product.limit_age >= 18 and self.customer.user.is_banned_alcohol:
request.session['not_allowed'] = True
return False
if self.customer.user.is_banned_counter:
request.session['not_allowed'] = True
return False
if self.customer.user.date_of_birth and self.customer.user.get_age() < product.limit_age: # Check if affordable
request.session['too_young'] = True
return False
......
This diff is collapsed.
......@@ -256,6 +256,18 @@ SITH_GROUPS = {
'id': 5,
'name': "Counter admin",
},
'banned-alcohol': {
'id': 6,
'name': "Banned from buying alcohol",
},
'banned-from-counters': {
'id': 7,
'name': "Banned from counters",
},
'banned-to-subscribe': {
'id': 8,
'name': "Banned to subscribe",
}
}
SITH_BOARD_SUFFIX="-bureau"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment