Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Rex Dri
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
32
Issues
32
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Container Registry
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
Rex Dri
Rex Dri
Commits
964ee65a
Commit
964ee65a
authored
Sep 02, 2018
by
Florent Chehab
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug removed and generalization of model config
parent
7427179e
Pipeline
#26852
passed with stages
in 2 minutes and 17 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
15 additions
and
17 deletions
+15
-17
backend/generate/templates/urls.tpl
backend/generate/templates/urls.tpl
+4
-2
backend/models/my_model/myModel.py
backend/models/my_model/myModel.py
+3
-1
backend/models/my_model/myModelSerializer.py
backend/models/my_model/myModelSerializer.py
+1
-1
backend/utils/get_model_config.py
backend/utils/get_model_config.py
+6
-12
general/api/get_api_config.py
general/api/get_api_config.py
+1
-1
No files found.
backend/generate/templates/urls.tpl
View file @
964ee65a
...
...
@@ -53,8 +53,10 @@ router.register(
urlpatterns += [url(r'^api/', include(router.urls))]
for model in ALL_MODELS:
if model.model_config is None:
raise Exception("You forgot to set the moderation_level variable in the model {}".format(str(model)))
for key in model.model_config:
val = model.model_config[key]
if val is None:
raise Exception("You forgot to set the {} config variable in the model {}".format(key, str(model)))
from backend.permissions import DEFAULT_VIEWSET_PERMISSIONS
for viewset in ALL_VIEWSETS:
...
...
backend/models/my_model/myModel.py
View file @
964ee65a
...
...
@@ -24,4 +24,6 @@ class MyModel(models.Model):
class
Meta
:
abstract
=
True
model_config
=
None
model_config
=
{
"moderation_level"
:
None
,
}
backend/models/my_model/myModelSerializer.py
View file @
964ee65a
...
...
@@ -50,7 +50,7 @@ class MyModelSerializer(serializers.ModelSerializer):
model
=
MyModel
def
moderation_required
(
self
):
moderation_level
=
self
.
Meta
.
model
.
model_config
moderation_level
=
self
.
Meta
.
model
.
model_config
[
'moderation_level'
]
user
=
self
.
get_user_in_request
()
if
moderation_level
==
0
:
...
...
backend/utils/get_model_config.py
View file @
964ee65a
import
yaml
from
os.path
import
join
,
realpath
,
dirname
from
general.api
import
get_api_config
def
get_model_config
(
model
):
current_dir
=
dirname
(
realpath
(
__file__
))
api_file_loc
=
join
(
current_dir
,
'../../general/api/api_config.yml'
)
with
open
(
api_file_loc
,
"r"
)
as
file
:
api_config
=
yaml
.
load
(
file
.
read
())
for
obj
in
api_config
:
if
obj
[
'model'
]
==
model
:
try
:
return
obj
[
"moderation_level"
]
except
KeyError
:
return
2
api_config
=
get_api_config
()
for
obj
in
api_config
:
if
obj
[
'model'
]
==
model
:
return
obj
raise
Exception
(
"Model not found in API configuraiton, cannot process !"
)
general/api/get_api_config.py
View file @
964ee65a
...
...
@@ -11,7 +11,7 @@ def get_api_config():
DEFAULT_SETTINGS
=
{
"ignore_in_admin"
:
False
,
"requires_testing"
:
False
,
"moderation_le
b
el"
:
2
"moderation_le
v
el"
:
2
}
for
obj
in
api_config
:
...
...
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