Add ban for alcohol

This commit is contained in:
Antoine Bartuccio 2016-10-15 02:33:38 +02:00
parent a0319887c8
commit 257cb9cfe7
5 changed files with 40 additions and 4 deletions

View File

@ -0,0 +1,19 @@
# -*- 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,6 +169,13 @@ class User(AbstractBaseUser):
parent_address = models.CharField(_("parent address"), max_length=128, blank=True, default="") parent_address = models.CharField(_("parent address"), max_length=128, blank=True, default="")
is_subscriber_viewable = models.BooleanField(_("is subscriber viewable"), default=True) is_subscriber_viewable = models.BooleanField(_("is subscriber viewable"), default=True)
godfathers = models.ManyToManyField('User', related_name='godchildren', blank=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() objects = UserManager()

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', 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', 'scrub_pict', 'sex', 'second_email', 'address', 'parent_address', 'phone', 'parent_phone',
'tshirt_size', 'role', 'department', 'dpt_option', 'semester', 'quote', 'school', 'promo', 'tshirt_size', 'role', 'department', 'dpt_option', 'semester', 'quote', 'school', 'promo',
'forum_signature', 'is_subscriber_viewable'] 'forum_signature', 'is_subscriber_viewable', 'is_banned_alcohol']
widgets = { widgets = {
'date_of_birth': SelectDate, 'date_of_birth': SelectDate,
'profile_pict': forms.ClearableFileInput, 'profile_pict': forms.ClearableFileInput,

View File

@ -319,22 +319,29 @@ class UserUpdateProfileView(UserTabsMixin, CanEditMixin, UpdateView):
form_class = UserProfileForm form_class = UserProfileForm
current_tab = "edit" current_tab = "edit"
edit_once = ['profile_pict', 'date_of_birth', 'first_name', 'last_name'] edit_once = ['profile_pict', 'date_of_birth', 'first_name', 'last_name']
board_only = ['is_banned_alcohol']
def remove_once_edited_fields(self, request): def remove_restricted_fields(self, request):
"""
Removes edit_once and board_only fields
"""
for i in self.edit_once: for i in self.edit_once:
if getattr(self.form.instance, i) and not (request.user.is_board_member or request.user.is_root): if getattr(self.form.instance, i) and not (request.user.is_board_member or request.user.is_root):
self.form.fields.pop(i, None) self.form.fields.pop(i, None)
for i in self.board_only:
if not (request.user.is_board_member or request.user.is_root):
self.form.fields.pop(i, None)
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
self.object = self.get_object() self.object = self.get_object()
self.form = self.get_form() self.form = self.get_form()
self.remove_once_edited_fields(request) self.remove_restricted_fields(request)
return self.render_to_response(self.get_context_data(form=self.form)) return self.render_to_response(self.get_context_data(form=self.form))
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
self.object = self.get_object() self.object = self.get_object()
self.form = self.get_form() self.form = self.get_form()
self.remove_once_edited_fields(request) self.remove_restricted_fields(request)
files = request.FILES.items() files = request.FILES.items()
self.form.process(files) self.form.process(files)
if request.user.is_authenticated() and request.user.can_edit(self.object) and self.form.is_valid(): if request.user.is_authenticated() and request.user.can_edit(self.object) and self.form.is_valid():

View File

@ -278,6 +278,9 @@ class CounterClick(CounterTabsMixin, DetailView):
if product.limit_age >= 18 and not self.customer.user.date_of_birth: if product.limit_age >= 18 and not self.customer.user.date_of_birth:
request.session['no_age'] = True request.session['no_age'] = True
return False return False
if product.limit_age >= 18 and self.customer.user.is_banned_alcohol:
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 if self.customer.user.date_of_birth and self.customer.user.get_age() < product.limit_age: # Check if affordable
request.session['too_young'] = True request.session['too_young'] = True
return False return False