Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f492d2b0
authored
Nov 08, 2013
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
acl: document model methods
parent
9585adae
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
2 deletions
+28
-2
circle/acl/models.py
+28
-2
No files found.
circle/acl/models.py
View file @
f492d2b0
...
...
@@ -16,7 +16,7 @@ class Level(Model):
"""Definition of a permission level.
Instances are automatically populated based on AclBase.
.
"""
Instances are automatically populated based on AclBase."""
name
=
CharField
(
'name'
,
max_length
=
50
)
content_type
=
ForeignKey
(
ContentType
)
codename
=
CharField
(
'codename'
,
max_length
=
100
)
...
...
@@ -55,18 +55,36 @@ class AclBase(Model):
object_level_set
=
GenericRelation
(
ObjectLevel
)
def
get_level_object
(
self
,
level
):
"""Get Level object for this model by codename."""
ct
=
ContentType
.
objects
.
get_for_model
(
self
)
return
Level
.
objects
.
get
(
codename
=
level
,
content_type
=
ct
)
def
set_level
(
self
,
whom
,
level
):
"""Set level of object for a user or group.
:param whom: user or group the level is set for
:type whom: User or Group
:param level: codename of level to set
:type level: Level or str or unicode
"""
if
isinstance
(
whom
,
User
):
self
.
set_user_level
(
whom
,
level
)
elif
isinstance
(
whom
,
Group
):
self
.
set_group_level
(
whom
,
level
)
else
:
raise
AttributeError
(
"Whom must be a User or Group object."
)
raise
AttributeError
(
'"whom" must be a User or Group object.'
)
def
set_user_level
(
self
,
user
,
level
):
"""Set level of object for a user.
:param whom: user the level is set for
:type whom: User
:param level: codename of level to set
:type level: Level or str or unicode
"""
logger
.
info
(
'
%
s.set_user_level(
%
s,
%
s) called'
,
*
[
unicode
(
p
)
for
p
in
[
self
,
user
,
level
]])
if
isinstance
(
level
,
basestring
):
...
...
@@ -81,6 +99,14 @@ class AclBase(Model):
i
.
save
()
def
set_group_level
(
self
,
group
,
level
):
"""Set level of object for a user.
:param whom: user the level is set for
:type whom: User or unicode or str
:param level: codename of level to set
:type level: str or unicode
"""
logger
.
info
(
'
%
s.set_group_level(
%
s,
%
s) called'
,
*
[
unicode
(
p
)
for
p
in
[
self
,
group
,
level
]])
if
isinstance
(
level
,
basestring
):
...
...
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