Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
re2o
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nounous
re2o
Commits
58ff2a2c
Commit
58ff2a2c
authored
Dec 27, 2017
by
Gabriel Detraz
Committed by
root
Jan 06, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Nouvelle fonction pour check par field
parent
15852329
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
0 deletions
+21
-0
re2o/utils.py
re2o/utils.py
+21
-0
No files found.
re2o/utils.py
View file @
58ff2a2c
...
...
@@ -96,6 +96,27 @@ def can_edit(model):
return
decorator
def
can_change
(
model
,
field_list
):
"""Decorator to check if an user can edit a field of a model.
It assumes that a valid user exists in the request and that the model has a
method can_create(user) which returns true if the user can create this kind
of models.
"""
def
decorator
(
view
):
def
wrapper
(
request
,
*
args
,
**
kwargs
):
for
field
in
field_list
:
can_create
=
getattr
(
model
,
'can_change_'
+
field
)
can
,
msg
=
can_create
(
request
.
user
,
*
args
,
**
kwargs
)
if
not
can
:
messages
.
error
(
request
,
msg
or
"Vous ne pouvez pas accéder à ce menu"
)
return
redirect
(
reverse
(
'users:profil'
,
kwargs
=
{
'userid'
:
str
(
request
.
user
.
id
)}
))
return
view
(
request
,
*
args
,
**
kwargs
)
return
wrapper
return
decorator
def
can_delete
(
model
):
"""Decorator to check if an user can delete a model.
It tries to get an instance of the model, using
...
...
Write
Preview
Markdown
is supported
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