Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
AE UTBM
Sith
Commits
257cb9cf
Commit
257cb9cf
authored
Oct 15, 2016
by
Sli
Browse files
Add ban for alcohol
parent
a0319887
Pipeline
#296
failed with stage
in 6 minutes and 29 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
core/migrations/0005_user_is_banned_alcohol.py
0 → 100644
View file @
257cb9cf
# -*- 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
),
),
]
core/models.py
View file @
257cb9cf
...
...
@@ -169,6 +169,13 @@ 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
()
...
...
core/views/forms.py
View file @
257cb9cf
...
...
@@ -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'
]
'forum_signature'
,
'is_subscriber_viewable'
,
'is_banned_alcohol'
]
widgets
=
{
'date_of_birth'
:
SelectDate
,
'profile_pict'
:
forms
.
ClearableFileInput
,
...
...
core/views/user.py
View file @
257cb9cf
...
...
@@ -319,22 +319,29 @@ 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'
]
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
:
if
getattr
(
self
.
form
.
instance
,
i
)
and
not
(
request
.
user
.
is_board_member
or
request
.
user
.
is_root
):
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
):
self
.
object
=
self
.
get_object
()
self
.
form
=
self
.
get_form
()
self
.
remove_
once_edi
ted_fields
(
request
)
self
.
remove_
restric
ted_fields
(
request
)
return
self
.
render_to_response
(
self
.
get_context_data
(
form
=
self
.
form
))
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
object
=
self
.
get_object
()
self
.
form
=
self
.
get_form
()
self
.
remove_
once_edi
ted_fields
(
request
)
self
.
remove_
restric
ted_fields
(
request
)
files
=
request
.
FILES
.
items
()
self
.
form
.
process
(
files
)
if
request
.
user
.
is_authenticated
()
and
request
.
user
.
can_edit
(
self
.
object
)
and
self
.
form
.
is_valid
():
...
...
counter/views.py
View file @
257cb9cf
...
...
@@ -278,6 +278,9 @@ class CounterClick(CounterTabsMixin, DetailView):
if
product
.
limit_age
>=
18
and
not
self
.
customer
.
user
.
date_of_birth
:
request
.
session
[
'no_age'
]
=
True
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
request
.
session
[
'too_young'
]
=
True
return
False
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment