Commit 964ee65a authored by Florent Chehab's avatar Florent Chehab
Browse files

bug removed and generalization of model config

parent 7427179e
......@@ -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:
......
......@@ -24,4 +24,6 @@ class MyModel(models.Model):
class Meta:
abstract = True
model_config = None
model_config = {
"moderation_level": None,
}
......@@ -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:
......
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 !")
......@@ -11,7 +11,7 @@ def get_api_config():
DEFAULT_SETTINGS = {
"ignore_in_admin": False,
"requires_testing": False,
"moderation_lebel": 2
"moderation_level": 2
}
for obj in api_config:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment