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
593050d9
Commit
593050d9
authored
Jul 18, 2016
by
Skia
🤘
Browse files
Improve greatly the counter right management
parent
e92a73df
Changes
14
Hide whitespace changes
Inline
Side-by-side
core/management/commands/populate.py
View file @
593050d9
...
...
@@ -20,25 +20,38 @@ class Command(BaseCommand):
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'--prod'
,
action
=
"store_true"
)
def
reset_index
(
self
,
*
args
):
sqlcmd
=
StringIO
()
call_command
(
"sqlsequencereset"
,
*
args
,
stdout
=
sqlcmd
)
cursor
=
connection
.
cursor
()
cursor
.
execute
(
sqlcmd
.
getvalue
())
def
handle
(
self
,
*
args
,
**
options
):
os
.
environ
[
'DJANGO_COLORS'
]
=
'nocolor'
root_path
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
dirname
(
__file__
))))
for
g
in
settings
.
SITH_GROUPS
.
values
():
Group
(
id
=
g
[
'id'
],
name
=
g
[
'name'
]).
save
()
sqlcmd
=
StringIO
()
call_command
(
"sqlsequencereset"
,
"core"
,
"auth"
,
stdout
=
sqlcmd
)
cursor
=
connection
.
cursor
()
print
(
sqlcmd
.
getvalue
())
cursor
.
execute
(
sqlcmd
.
getvalue
())
self
.
reset_index
(
"core"
,
"auth"
)
root
=
User
(
username
=
'root'
,
last_name
=
""
,
first_name
=
"Bibou"
,
email
=
"ae.info@utbm.fr"
,
date_of_birth
=
"1942-06-12"
,
is_superuser
=
True
,
is_staff
=
True
)
root
.
set_password
(
"plop"
)
root
.
save
()
ae
=
Club
(
name
=
settings
.
SITH_MAIN_CLUB
[
'name'
],
unix_name
=
settings
.
SITH_MAIN_CLUB
[
'unix_name'
],
main_club
=
Club
(
name
=
settings
.
SITH_MAIN_CLUB
[
'name'
],
unix_name
=
settings
.
SITH_MAIN_CLUB
[
'unix_name'
],
address
=
settings
.
SITH_MAIN_CLUB
[
'address'
])
ae
.
save
()
main_club
.
save
()
bar_club
=
Club
(
name
=
settings
.
SITH_BAR_MANAGER
[
'name'
],
unix_name
=
settings
.
SITH_BAR_MANAGER
[
'unix_name'
],
address
=
settings
.
SITH_BAR_MANAGER
[
'address'
])
bar_club
.
save
()
for
b
in
settings
.
SITH_COUNTER_BARS
:
g
=
Group
(
name
=
b
[
1
]
+
" admin"
)
g
.
save
()
c
=
Counter
(
id
=
b
[
0
],
name
=
b
[
1
],
club
=
bar_club
,
type
=
'BAR'
)
c
.
save
()
c
.
edit_groups
=
[
g
]
c
.
save
()
self
.
reset_index
(
"counter"
)
p
=
Page
(
name
=
'Index'
)
p
.
set_lock
(
root
)
p
.
save
()
...
...
@@ -77,6 +90,16 @@ Welcome to the wiki page!
subscriber
.
save
()
subscriber
.
view_groups
=
[
Group
.
objects
.
filter
(
name
=
settings
.
SITH_MAIN_MEMBERS_GROUP
).
first
().
id
]
subscriber
.
save
()
# Adding user Counter admin
counter
=
User
(
username
=
'counter'
,
last_name
=
"Ter"
,
first_name
=
"Coun"
,
email
=
"counter@git.an"
,
date_of_birth
=
"1942-06-12"
,
is_superuser
=
False
,
is_staff
=
False
)
counter
.
set_password
(
"plop"
)
counter
.
save
()
counter
.
view_groups
=
[
Group
.
objects
.
filter
(
name
=
settings
.
SITH_MAIN_MEMBERS_GROUP
).
first
().
id
]
counter
.
groups
=
[
Group
.
objects
.
filter
(
name
=
settings
.
SITH_GROUPS
[
'counter-admin'
][
'name'
]).
first
().
id
]
counter
.
save
()
# Adding user Comptable
comptable
=
User
(
username
=
'comptable'
,
last_name
=
"Able"
,
first_name
=
"Compte"
,
email
=
"compta@git.an"
,
...
...
@@ -155,17 +178,15 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
# Clubs
Club
(
name
=
"Bibo'UT"
,
unix_name
=
"bibout"
,
address
=
"46 de la Boustifaille"
,
parent
=
ae
).
save
()
address
=
"46 de la Boustifaille"
,
parent
=
main_club
).
save
()
guyut
=
Club
(
name
=
"Guy'UT"
,
unix_name
=
"guyut"
,
address
=
"42 de la Boustifaille"
,
parent
=
ae
)
address
=
"42 de la Boustifaille"
,
parent
=
main_club
)
guyut
.
save
()
Club
(
name
=
"Woenzel'UT"
,
unix_name
=
"woenzel"
,
address
=
"Woenzel"
,
parent
=
guyut
).
save
()
Club
(
name
=
"BdF"
,
unix_name
=
"bdf"
,
address
=
"6 Bd Anatole France"
).
save
()
Membership
(
user
=
skia
,
club
=
ae
,
role
=
3
,
description
=
""
).
save
()
Membership
(
user
=
skia
,
club
=
main_club
,
role
=
3
,
description
=
""
).
save
()
troll
=
Club
(
name
=
"Troll Penché"
,
unix_name
=
"troll"
,
address
=
"Terre Du Milieu"
,
parent
=
ae
)
address
=
"Terre Du Milieu"
,
parent
=
main_club
)
troll
.
save
()
# Counters
...
...
@@ -174,25 +195,24 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
p
=
ProductType
(
name
=
"Bières bouteilles"
)
p
.
save
()
barb
=
Product
(
name
=
"Barbar"
,
code
=
"BARB"
,
product_type
=
p
,
purchase_price
=
"1.50"
,
selling_price
=
"1.7"
,
special_selling_price
=
"1.6"
,
club
=
ae
)
special_selling_price
=
"1.6"
,
club
=
main_club
)
barb
.
save
()
cble
=
Product
(
name
=
"Chimay Bleue"
,
code
=
"CBLE"
,
product_type
=
p
,
purchase_price
=
"1.50"
,
selling_price
=
"1.7"
,
special_selling_price
=
"1.6"
,
club
=
ae
)
special_selling_price
=
"1.6"
,
club
=
main_club
)
cble
.
save
()
Product
(
name
=
"Corsendonk"
,
code
=
"CORS"
,
product_type
=
p
,
purchase_price
=
"1.50"
,
selling_price
=
"1.7"
,
special_selling_price
=
"1.6"
,
club
=
ae
).
save
()
special_selling_price
=
"1.6"
,
club
=
main_club
).
save
()
Product
(
name
=
"Carolus"
,
code
=
"CARO"
,
product_type
=
p
,
purchase_price
=
"1.50"
,
selling_price
=
"1.7"
,
special_selling_price
=
"1.6"
,
club
=
ae
).
save
()
mde
=
Counter
(
name
=
"MDE"
,
club
=
ae
,
type
=
"BAR"
)
mde
.
save
()
special_selling_price
=
"1.6"
,
club
=
main_club
).
save
()
mde
=
Counter
.
objects
.
filter
(
name
=
"MDE"
).
first
()
mde
.
products
.
add
(
barb
)
mde
.
products
.
add
(
cble
)
mde
.
save
()
# Accounting test values:
BankAccount
(
name
=
"AE TG"
,
club
=
ae
).
save
()
BankAccount
(
name
=
"Carte AE"
,
club
=
ae
).
save
()
ba
=
BankAccount
(
name
=
"AE TI"
,
club
=
ae
)
BankAccount
(
name
=
"AE TG"
,
club
=
main_club
).
save
()
BankAccount
(
name
=
"Carte AE"
,
club
=
main_club
).
save
()
ba
=
BankAccount
(
name
=
"AE TI"
,
club
=
main_club
)
ba
.
save
()
ca
=
ClubAccount
(
name
=
"Troll Penché"
,
bank_account
=
ba
,
club
=
troll
)
ca
.
save
()
...
...
core/migrations/0005_auto_20160717_1459.py
0 → 100644
View file @
593050d9
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'core'
,
'0004_preferences'
),
]
operations
=
[
migrations
.
RemoveField
(
model_name
=
'user'
,
name
=
'edit_groups'
,
),
migrations
.
RemoveField
(
model_name
=
'user'
,
name
=
'owner_group'
,
),
migrations
.
RemoveField
(
model_name
=
'user'
,
name
=
'view_groups'
,
),
]
core/migrations/0006_auto_20160717_1506.py
0 → 100644
View file @
593050d9
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'core'
,
'0005_auto_20160717_1459'
),
]
operations
=
[
migrations
.
AlterModelOptions
(
name
=
'user'
,
options
=
{},
),
migrations
.
RemoveField
(
model_name
=
'user'
,
name
=
'is_superuser'
,
),
migrations
.
RemoveField
(
model_name
=
'user'
,
name
=
'user_permissions'
,
),
migrations
.
AlterField
(
model_name
=
'user'
,
name
=
'groups'
,
field
=
models
.
ManyToManyField
(
blank
=
True
,
to
=
'core.RealGroup'
,
related_name
=
'users'
),
),
]
core/migrations/0007_user_is_superuser.py
0 → 100644
View file @
593050d9
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'core'
,
'0006_auto_20160717_1506'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'user'
,
name
=
'is_superuser'
,
field
=
models
.
BooleanField
(
help_text
=
'Designates whether this user is a superuser. '
,
default
=
False
,
verbose_name
=
'superuser'
),
),
]
core/models.py
View file @
593050d9
...
...
@@ -45,7 +45,7 @@ class RealGroup(Group):
class
Meta
:
proxy
=
True
class
User
(
AbstractBaseUser
,
PermissionsMixin
):
class
User
(
AbstractBaseUser
):
"""
Defines the base user class, useable in every app
...
...
@@ -91,27 +91,20 @@ class User(AbstractBaseUser, PermissionsMixin):
),
)
date_joined
=
models
.
DateField
(
_
(
'date joined'
),
auto_now_add
=
True
)
owner_group
=
models
.
ForeignKey
(
Group
,
related_name
=
"owned_user"
,
default
=
settings
.
SITH_GROUPS
[
'root'
][
'id'
])
edit_groups
=
models
.
ManyToManyField
(
Group
,
related_name
=
"editable_user"
,
blank
=
True
)
view_groups
=
models
.
ManyToManyField
(
Group
,
related_name
=
"viewable_user"
,
blank
=
True
)
is_superuser
=
models
.
BooleanField
(
_
(
'superuser'
),
default
=
False
,
help_text
=
_
(
'Designates whether this user is a superuser. '
),
)
groups
=
models
.
ManyToManyField
(
RealGroup
,
related_name
=
'users'
,
blank
=
True
)
objects
=
UserManager
()
USERNAME_FIELD
=
'username'
# REQUIRED_FIELDS = ['email']
class
Meta
:
verbose_name
=
_
(
'user'
)
verbose_name_plural
=
_
(
'users'
)
# Add permissions like this to allow automatic permission validation in is_owner&co
# model: change_prop_<class_name>
# view_<class_name>
permissions
=
(
(
"change_prop_user"
,
"Can change the user's properties (groups, ...)"
),
(
"view_user"
,
"Can view user's profile"
),
)
def
get_absolute_url
(
self
):
"""
This is needed for black magic powered UpdateView's children
...
...
core/templates/core/user_base.jinja
View file @
593050d9
...
...
@@ -8,7 +8,7 @@
<a
href=
"
{{
url
(
'core:user_edit'
,
user_id
=
profile.id
)
}}
"
>
Edit
</a>
{%
endif
%}
{%
if
can_edit_prop
(
profile
,
request.user
)
%}
<a
href=
"
{{
url
(
'core:user_
p
ro
p
'
,
user_id
=
profile.id
)
}}
"
>
P
rops
</a>
<a
href=
"
{{
url
(
'core:user_
g
ro
ups
'
,
user_id
=
profile.id
)
}}
"
>
G
ro
u
ps
</a>
{%
endif
%}
{%
if
(
profile
==
request.user
or
request.user.is_in_group
(
settings.SITH_GROUPS
[
'accounting-admin'
][
'name'
])
...
...
core/templates/core/user_
p
rop.jinja
→
core/templates/core/user_
g
ro
u
p.jinja
View file @
593050d9
File moved
core/templates/core/user_tools.jinja
View file @
593050d9
...
...
@@ -12,14 +12,27 @@
{%
if
user.is_in_group
(
settings.SITH_GROUPS
[
'root'
][
'name'
])
%}
<li><a
href=
"
{{
url
(
'core:group_list'
)
}}
"
>
Groups
</a></li>
{%
endif
%}
{%
if
user.is_in_group
(
settings.SITH_GROUPS
[
'counter-admin'
][
'name'
])
%}
<li><a
href=
"
{{
url
(
'counter:admin_list'
)
}}
"
>
Counters management
</a></li>
{%
endif
%}
{%
if
user.is_in_group
(
settings.SITH_GROUPS
[
'accounting-admin'
][
'name'
])
%}
<li><a
href=
"
{{
url
(
'accounting:bank_list'
)
}}
"
>
Accounting
</a></li>
{%
endif
%}
{%
if
user.is_in_group
(
settings.SITH_MAIN_BOARD_GROUP
)
or
user.is_in_group
(
settings.SITH_GROUPS
[
'root'
][
'name'
])
%}
<li><a
href=
"
{{
url
(
'subscription:subscription'
)
}}
"
>
Subscriptions
</a></li>
<li><a
href=
"
{{
url
(
'counter:admin_list'
)
}}
"
>
Counters management
</a></li>
{%
endif
%}
</ul>
<h4>
Counters
</h4>
<ul>
{%
for
b
in
settings.SITH_COUNTER_BARS
%}
{%
if
user.is_in_group
(
b
[
1
]
+
" admin"
)
%}
<li><a
href=
"
{{
url
(
'counter:details'
,
counter_id
=
b
[
0
])
}}
"
>
{{
b
[
1
]
}}
</a>
-
<a
href=
"
{{
url
(
'counter:admin'
,
counter_id
=
b
[
0
])
}}
"
>
Edit
</a></li>
{%
endif
%}
{%
endfor
%}
</ul>
<h4>
Clubs
</h4>
<ul>
{%
for
m
in
user.membership.
filter
(
end_date
=
None
)
.
all
()
%}
...
...
core/urls.py
View file @
593050d9
...
...
@@ -27,7 +27,7 @@ urlpatterns = [
url
(
r
'^user/$'
,
UserListView
.
as_view
(),
name
=
'user_list'
),
url
(
r
'^user/(?P<user_id>[0-9]+)/$'
,
UserView
.
as_view
(),
name
=
'user_profile'
),
url
(
r
'^user/(?P<user_id>[0-9]+)/edit$'
,
UserUpdateProfileView
.
as_view
(),
name
=
'user_edit'
),
url
(
r
'^user/(?P<user_id>[0-9]+)/
p
ro
p
$'
,
UserUpdate
P
ropView
.
as_view
(),
name
=
'user_
p
ro
p
'
),
url
(
r
'^user/(?P<user_id>[0-9]+)/
g
ro
ups
$'
,
UserUpdate
G
ro
u
pView
.
as_view
(),
name
=
'user_
g
ro
ups
'
),
url
(
r
'^user/tools/$'
,
UserToolsView
.
as_view
(),
name
=
'user_tools'
),
url
(
r
'^user/(?P<user_id>[0-9]+)/account$'
,
UserAccountView
.
as_view
(),
name
=
'user_account'
),
...
...
core/views/forms.py
View file @
593050d9
...
...
@@ -11,7 +11,7 @@ class RegisteringForm(UserCreationForm):
required_css_class
=
'required'
class
Meta
:
model
=
User
fields
=
(
'first_name'
,
'last_name'
,
'email'
,
'date_of_birth'
)
fields
=
(
'first_name'
,
'last_name'
,
'email'
)
def
save
(
self
,
commit
=
True
):
user
=
super
(
RegisteringForm
,
self
).
save
(
commit
=
False
)
...
...
@@ -27,21 +27,12 @@ class UserPropForm(forms.ModelForm):
required_css_class
=
'required'
class
Meta
:
model
=
User
fields
=
[
'groups'
,
'edit_groups'
,
'view_groups'
]
labels
=
{
'edit_groups'
:
"Edit profile group"
,
'view_groups'
:
"View profile group"
,
}
fields
=
[
'groups'
]
help_texts
=
{
'edit_groups'
:
"Groups that can edit this user's profile"
,
'view_groups'
:
"Groups that can view this user's profile"
,
'groups'
:
"Which groups this user belongs to"
,
}
widgets
=
{
'groups'
:
CheckboxSelectMultiple
,
'user_permissions'
:
CheckboxSelectMultiple
,
'edit_groups'
:
CheckboxSelectMultiple
,
'view_groups'
:
CheckboxSelectMultiple
,
}
class
PagePropForm
(
forms
.
ModelForm
):
...
...
core/views/user.py
View file @
593050d9
...
...
@@ -5,6 +5,8 @@ from django.core.urlresolvers import reverse
from
django.core.exceptions
import
PermissionDenied
,
ObjectDoesNotExist
from
django.views.generic.edit
import
UpdateView
from
django.views.generic
import
ListView
,
DetailView
,
TemplateView
from
django.forms.models
import
modelform_factory
from
django.forms
import
CheckboxSelectMultiple
import
logging
from
core.views
import
CanViewMixin
,
CanEditMixin
,
CanEditPropMixin
...
...
@@ -114,14 +116,15 @@ class UserUpdateProfileView(CanEditMixin, UpdateView):
template_name
=
"core/user_edit.jinja"
fields
=
(
'first_name'
,
'last_name'
,
'nick_name'
,
'email'
,
'date_of_birth'
,
)
class
UserUpdate
P
ropView
(
CanEditPropMixin
,
UpdateView
):
class
UserUpdate
G
ro
u
pView
(
CanEditPropMixin
,
UpdateView
):
"""
Edit a user's groups
"""
model
=
User
pk_url_kwarg
=
"user_id"
template_name
=
"core/user_prop.jinja"
form_class
=
UserPropForm
template_name
=
"core/user_group.jinja"
form_class
=
modelform_factory
(
User
,
fields
=
[
'groups'
],
widgets
=
{
'groups'
:
CheckboxSelectMultiple
})
context_object_name
=
"profile"
class
UserToolsView
(
TemplateView
):
...
...
counter/models.py
View file @
593050d9
...
...
@@ -85,7 +85,7 @@ class Counter(models.Model):
def
__getattribute__
(
self
,
name
):
if
name
==
"owner_group"
:
return
Group
(
name
=
self
.
club
.
unix_name
+
settings
.
SITH_BOARD_SUFFIX
)
return
Group
.
objects
.
filter
(
name
=
self
.
club
.
unix_name
+
settings
.
SITH_BOARD_SUFFIX
)
.
first
()
return
object
.
__getattribute__
(
self
,
name
)
def
__str__
(
self
):
...
...
@@ -94,6 +94,9 @@ class Counter(models.Model):
def
get_absolute_url
(
self
):
return
reverse
(
'counter:details'
,
kwargs
=
{
'counter_id'
:
self
.
id
})
def
can_be_edited_by
(
self
,
user
):
return
user
.
is_in_group
(
settings
.
SITH_GROUPS
[
'counter-admin'
][
'name'
])
def
can_be_viewed_by
(
self
,
user
):
return
user
.
is_in_group
(
settings
.
SITH_MAIN_BOARD_GROUP
)
...
...
counter/templates/counter/counter_list.jinja
View file @
593050d9
...
...
@@ -11,8 +11,7 @@
<ul>
{%
for
c
in
counter_list
%}
<li><a
href=
"
{{
url
(
'counter:details'
,
counter_id
=
c.id
)
}}
"
>
{{
c
}}
</a>
-
<a
href=
"
{{
url
(
'counter:admin'
,
counter_id
=
c.id
)
}}
"
>
Edit
</a>
-
<a
href=
"
{{
url
(
'counter:delete'
,
counter_id
=
c.id
)
}}
"
>
Delete
</a></li>
<a
href=
"
{{
url
(
'counter:admin'
,
counter_id
=
c.id
)
}}
"
>
Edit
</a></li>
{%
endfor
%}
</ul>
{%
else
%}
...
...
sith/settings_sample.py
View file @
593050d9
...
...
@@ -180,21 +180,34 @@ SITH_MAIN_CLUB = {
'unix_name'
:
"ae"
,
'address'
:
"6 Boulevard Anatole France, 90000 Belfort"
}
# Bar managers
SITH_BAR_MANAGER
=
{
'name'
:
"BdF"
,
'unix_name'
:
"bdf"
,
'address'
:
"6 Boulevard Anatole France, 90000 Belfort"
}
# Define the date in the year serving as reference for the subscriptions calendar
# (month, day)
SITH_START_DATE
=
(
8
,
15
)
# 15th August
SITH_GROUPS
=
{
'root'
:
{
'id'
:
1
,
'name'
:
"
r
oot"
,
'name'
:
"
R
oot"
,
},
'
accounting-admin
'
:
{
'
public
'
:
{
'id'
:
2
,
'name'
:
"
accounting-admin
"
,
'name'
:
"
Not registered users
"
,
},
'
public
'
:
{
'
accounting-admin
'
:
{
'id'
:
3
,
'name'
:
"not-registered-users"
,
'name'
:
"Accounting admin"
,
},
'counter-admin'
:
{
'id'
:
4
,
'name'
:
"Counter admin"
,
},
}
...
...
@@ -217,6 +230,12 @@ SITH_SUBSCRIPTION_PAYMENT_METHOD = [
(
'other'
,
'Autre'
),
]
SITH_COUNTER_BARS
=
[
(
1
,
"Foyer"
),
(
2
,
"MDE"
),
(
3
,
"La Gommette"
),
]
SITH_COUNTER_PAYMENT_METHOD
=
[
(
'cheque'
,
'Chèque'
),
(
'cash'
,
'Espèce'
),
...
...
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