Commit 7427179e authored by Florent Chehab's avatar Florent Chehab

prepared move to model_config

parent ac56d059
Pipeline #26851 passed with stages
in 2 minutes and 25 seconds
......@@ -53,7 +53,7 @@ router.register(
urlpatterns += [url(r'^api/', include(router.urls))]
for model in ALL_MODELS:
if model.moderation_level is None:
if model.model_config is None:
raise Exception("You forgot to set the moderation_level variable in the model {}".format(str(model)))
from backend.permissions import DEFAULT_VIEWSET_PERMISSIONS
......
......@@ -2,11 +2,11 @@ from django.db import models
from rest_framework import serializers
from backend.models.location import Country
from backend.models.my_model import MyModel, MyModelSerializer, MyModelVersionnedViewSet
from backend.utils import get_moderation_level, get_viewset_permissions
from backend.utils import get_model_config, get_viewset_permissions
class City(MyModel):
moderation_level = get_moderation_level("City")
model_config = get_model_config("City")
name = models.CharField(max_length=200)
local_name = models.CharField(max_length=200, null=True, blank=True)
......
from django.db import models
from backend.models.tag import TaggedItem, TaggedItemSerializer, TaggedItemViewSet
from backend.models.location import City
from backend.utils import get_moderation_level, get_viewset_permissions
from backend.utils import get_model_config, get_viewset_permissions
class CityTaggedItem(TaggedItem):
moderation_level = get_moderation_level("CityTaggedItem")
model_config = get_model_config("CityTaggedItem")
city = models.OneToOneField(
City, on_delete=models.PROTECT, related_name='city_items', primary_key=True)
......
from django.db import models
from backend.models.my_model import MyModel, MyModelSerializer, MyModelVersionnedViewSet
from backend.utils import get_moderation_level, get_viewset_permissions
from backend.utils import get_model_config, get_viewset_permissions
# Data model based on : https://unstats.un.org/unsd/methodology/m49/overview/
class Country(MyModel):
moderation_level = get_moderation_level("Country")
model_config = get_model_config("Country")
name = models.CharField(max_length=200)
iso_alpha2_code = models.CharField(primary_key=True, max_length=2)
......
from django.db import models
from backend.models.location import Country
from backend.models.module import DriRestrictedModule, DriRestrictedModuleSerializer, DriRestrictedModuleViewSet
from backend.utils import get_moderation_level, get_viewset_permissions
from backend.utils import get_model_config, get_viewset_permissions
class CountryDri(DriRestrictedModule):
moderation_level = get_moderation_level("CountryDri")
model_config = get_model_config("CountryDri")
country = models.ManyToManyField(
Country, related_name="country_dri")
......
from django.db import models
from backend.models.location import Country
from backend.models.module import Scholarship, ScholarshipSerializer, ScholarshipViewSet
from backend.utils import get_moderation_level, get_viewset_permissions
from backend.utils import get_model_config, get_viewset_permissions
class CountryScholarship(Scholarship):
moderation_level = get_moderation_level("CountryScholarship")
model_config = get_model_config("CountryScholarship")
country = models.ManyToManyField(
Country, related_name="country_scholarhip")
......
from django.db import models
from backend.models.tag import TaggedItem, TaggedItemSerializer, TaggedItemViewSet
from backend.models.location import Country
from backend.utils import get_moderation_level, get_viewset_permissions
from backend.utils import get_model_config, get_viewset_permissions
class CountryTaggedItem(TaggedItem):
moderation_level = get_moderation_level("CountryTaggedItem")
model_config = get_model_config("CountryTaggedItem")
country = models.OneToOneField(
Country, on_delete=models.PROTECT, related_name='country_items', primary_key=True)
......
from django.db import models
from django.core.validators import MinValueValidator
from backend.models.my_model import MyModel, MyModelSerializer, MyModelViewSet
from backend.utils import get_moderation_level, get_viewset_permissions
from backend.utils import get_model_config, get_viewset_permissions
class Currency(MyModel):
moderation_level = get_moderation_level("Currency")
model_config = get_model_config("Currency")
code = models.CharField(primary_key=True, max_length=3)
name = models.CharField(max_length=100)
......
......@@ -2,14 +2,14 @@ from .myModel import MyModel
from .myModelSerializer import MyModelSerializer
from .myModelViewSet import MyModelViewSet
from django.db import models
from backend.utils import get_moderation_level, get_viewset_permissions
from backend.utils import get_model_config, get_viewset_permissions
class ForTestingModeration(MyModel):
"""
Simple model for testing purposes
"""
moderation_level = get_moderation_level("ForTestingModeration")
model_config = get_model_config("ForTestingModeration")
aaa = models.CharField(max_length=100)
......
from .myModelVersionned import MyModelVersionned, MyModelVersionnedSerializer, MyModelVersionnedViewSet
from django.db import models
import reversion
from backend.utils import get_moderation_level, get_viewset_permissions
from backend.utils import get_model_config, get_viewset_permissions
@reversion.register()
......@@ -9,7 +9,7 @@ class ForTestingVersioning(MyModelVersionned):
"""
Simple model for testing purposes
"""
moderation_level = get_moderation_level("ForTestingVersioning")
model_config = get_model_config("ForTestingVersioning")
bbb = models.CharField(max_length=100)
@classmethod
......
......@@ -24,4 +24,4 @@ class MyModel(models.Model):
class Meta:
abstract = True
moderation_level = None
model_config = None
......@@ -50,7 +50,7 @@ class MyModelSerializer(serializers.ModelSerializer):
model = MyModel
def moderation_required(self):
moderation_level = self.Meta.model.moderation_level
moderation_level = self.Meta.model.model_config
user = self.get_user_in_request()
if moderation_level == 0:
......
......@@ -4,11 +4,11 @@ from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.postgres.fields import JSONField
from django.contrib.auth.models import User
from backend.utils import get_viewset_permissions, get_moderation_level
from backend.utils import get_viewset_permissions, get_model_config
class PendingModeration(models.Model):
moderation_level = get_moderation_level("PendingModeration")
model_config = get_model_config("PendingModeration")
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.CharField(max_length=100) # 100 should be ok
......
from django.db import models
from backend.models.my_model import MyModel, MyModelSerializer, MyModelViewSet
from backend.utils import get_moderation_level, get_viewset_permissions
from backend.utils import get_model_config, get_viewset_permissions
class Department(MyModel):
moderation_level = get_moderation_level("Department")
model_config = get_model_config("Department")
code = models.CharField(primary_key=True, max_length=6)
name = models.CharField(max_length=100)
......
......@@ -2,11 +2,11 @@ from django.db import models
from backend.models.university import University
from backend.models.other_core import Semester, Specialty
from backend.models.my_model import MyModel, MyModelSerializer, MyModelViewSet
from backend.utils import get_moderation_level, get_viewset_permissions
from backend.utils import get_model_config, get_viewset_permissions
class Offer(MyModel):
moderation_level = get_moderation_level("Offer")
model_config = get_model_config("Offer")
semester = models.ForeignKey(Semester, on_delete=models.PROTECT)
university = models.ForeignKey(University, on_delete=models.PROTECT)
......
from django.db import models
from backend.models.my_model import MyModel, MyModelSerializer, MyModelViewSet
from backend.utils import get_moderation_level, get_viewset_permissions
from backend.utils import get_model_config, get_viewset_permissions
class Semester(MyModel):
moderation_level = get_moderation_level("Semester")
model_config = get_model_config("Semester")
code = models.CharField(primary_key=True, max_length=6)
......
from django.db import models
from backend.models.other_core import Department
from backend.models.my_model import MyModel, MyModelSerializer, MyModelViewSet
from backend.utils import get_moderation_level, get_viewset_permissions
from backend.utils import get_model_config, get_viewset_permissions
class Specialty(MyModel):
moderation_level = get_moderation_level("Specialty")
model_config = get_model_config("Specialty")
code = models.CharField(max_length=6)
department = models.ForeignKey(Department, on_delete=models.PROTECT)
name = models.CharField(max_length=100)
......
from django.db import models
from backend.models.my_model import MyModel, MyModelSerializer, MyModelViewSet
from django.contrib.postgres.fields import JSONField
from backend.utils import get_viewset_permissions, get_moderation_level
from backend.utils import get_viewset_permissions, get_model_config
class Tag(MyModel):
"""
TODO description
"""
moderation_level = get_moderation_level("Tag")
model_config = get_model_config("Tag")
name = models.CharField(max_length=100, unique=True)
config = JSONField(blank=True, default=dict)
......
......@@ -3,11 +3,11 @@ from backend.models.module import BasicModule, BasicModuleSerializer, BasicModul
from backend.models.location import City
from backend.models.university import University
from django.core.validators import MinValueValidator, MaxValueValidator
from backend.utils import get_moderation_level, get_viewset_permissions
from backend.utils import get_model_config, get_viewset_permissions
class Campus(BasicModule):
moderation_level = get_moderation_level("Campus")
model_config = get_model_config("Campus")
is_main_campus = models.BooleanField(null=False)
name = models.CharField(max_length=200, null=True)
......
from django.db import models
from backend.models.university import Campus
from backend.models.tag import TaggedItem, TaggedItemSerializer, TaggedItemViewSet
from backend.utils import get_moderation_level, get_viewset_permissions
from backend.utils import get_model_config, get_viewset_permissions
class CampusTaggedItem(TaggedItem):
moderation_level = get_moderation_level("CampusTaggedItem")
model_config = get_model_config("CampusTaggedItem")
campus = models.OneToOneField(
Campus, on_delete=models.PROTECT, related_name='city_items', primary_key=True)
......
from django.db import models
from backend.models.my_model import MyModel
from backend.utils.friendly_path import friendly_path
from backend.utils import get_moderation_level
from backend.utils import get_model_config
path_and_rename = friendly_path("uploads/universities/logos/", 'name')
......@@ -10,7 +10,7 @@ class University(MyModel):
"""
Model storing information about universities
"""
moderation_level = get_moderation_level("University")
model_config = get_model_config("University")
name = models.CharField(max_length=200)
acronym = models.CharField(max_length=20, null=True, blank=True)
......
from django.db import models
from backend.models.university import University
from backend.models.module import DriRestrictedModule, DriRestrictedModuleSerializer, DriRestrictedModuleViewSet
from backend.utils import get_moderation_level, get_viewset_permissions
from backend.utils import get_model_config, get_viewset_permissions
class UniversityDri(DriRestrictedModule):
moderation_level = get_moderation_level("UniversityDri")
model_config = get_model_config("UniversityDri")
university = models.ManyToManyField(
University, related_name="university_dri")
......
......@@ -3,11 +3,11 @@ from backend.models.module import BasicModule, BasicModuleSerializer, BasicModul
from backend.models.university import University
from backend.models.location import Currency
from django.core.validators import MinValueValidator
from backend.utils import get_moderation_level, get_viewset_permissions
from backend.utils import get_model_config, get_viewset_permissions
class UniversityInfo(BasicModule):
moderation_level = get_moderation_level("UniversityInfo")
model_config = get_model_config("UniversityInfo")
university = models.OneToOneField(
University, on_delete=models.CASCADE, related_name='university_info', primary_key=True, null=False)
......
from django.db import models
from backend.models.university import University
from backend.models.module import Scholarship, ScholarshipSerializer, ScholarshipViewSet
from backend.utils import get_moderation_level, get_viewset_permissions
from backend.utils import get_model_config, get_viewset_permissions
class UniversityScholarship(Scholarship):
moderation_level = get_moderation_level("UniversityScholarship")
model_config = get_model_config("UniversityScholarship")
university = models.ForeignKey(
University, on_delete=models.PROTECT, null=False, related_name="univScholarship")
......
......@@ -2,7 +2,7 @@ from django.db import models
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.university import University
from rest_framework import serializers
from backend.utils import get_moderation_level, get_viewset_permissions
from backend.utils import get_model_config, get_viewset_permissions
def check_nones(val1, val2):
......@@ -16,7 +16,7 @@ def check_nones(val1, val2):
class UniversitySemestersDates(BasicModule):
moderation_level = get_moderation_level("UniversitySemestersDates")
model_config = get_model_config("UniversitySemestersDates")
university = models.OneToOneField(
University, on_delete=models.CASCADE, related_name='university_semesters_dates', primary_key=True, null=False)
......
from django.db import models
from backend.models.tag import TaggedItem, TaggedItemSerializer, TaggedItemViewSet
from backend.models.university import University
from backend.utils import get_moderation_level, get_viewset_permissions
from backend.utils import get_model_config, get_viewset_permissions
class UniversityTaggedItem(TaggedItem):
moderation_level = get_moderation_level("UniversityTaggedItem")
model_config = get_model_config("UniversityTaggedItem")
university = models.OneToOneField(
University, on_delete=models.PROTECT, related_name='city_items', primary_key=True)
......
......@@ -5,11 +5,11 @@ from backend.models.university import University
from django.contrib.auth.models import User
from django.contrib.postgres.fields import JSONField
from backend.models.my_model import MyModel, MyModelSerializer, MyModelViewSet
from backend.utils import get_moderation_level, get_viewset_permissions
from backend.utils import get_model_config, get_viewset_permissions
class PreviousDeparture(MyModel):
moderation_level = get_moderation_level("PreviousDeparture")
model_config = get_model_config("PreviousDeparture")
# This model should be filled with data from the ENT
semester = models.ForeignKey(Semester, on_delete=models.PROTECT)
university = models.ForeignKey(University, on_delete=models.PROTECT)
......
......@@ -4,11 +4,11 @@ from django.core.validators import MaxValueValidator
from backend.models.user import UserRestrictedModule, UserRestrictedModuleSerializer, UserRestrictedModuleViewSet
from backend.models.user import PreviousDeparture
from django.contrib.postgres.fields import JSONField
from backend.utils import get_moderation_level, get_viewset_permissions
from backend.utils import get_model_config, get_viewset_permissions
class PreviousDepartureFeedback(UserRestrictedModule):
moderation_level = get_moderation_level("Country")
model_config = get_model_config("Country")
departure = models.OneToOneField(
PreviousDeparture, on_delete=models.CASCADE)
......
......@@ -6,11 +6,11 @@ from backend.models.user import UserRestrictedModule, UserRestrictedModuleSerial
from backend.models.other_core import Specialty
from backend.models.user import RecommendationList
from backend.utils import get_moderation_level, get_viewset_permissions
from backend.utils import get_model_config, get_viewset_permissions
class Recommendation(UserRestrictedModule):
moderation_level = get_moderation_level("Recommendation")
model_config = get_model_config("Recommendation")
university = models.ForeignKey(University, on_delete=models.PROTECT)
parent_list = models.ForeignKey(
RecommendationList, on_delete=models.PROTECT, related_name='recommendations')
......
from django.db import models
from backend.models.user import UserRestrictedModule, UserRestrictedModuleSerializer, UserRestrictedModuleViewSet
from backend.utils import get_moderation_level, get_viewset_permissions
from backend.utils import get_model_config, get_viewset_permissions
class RecommendationList(UserRestrictedModule):
moderation_level = get_moderation_level("RecommendationList")
model_config = get_model_config("RecommendationList")
public = models.BooleanField()
title = models.CharField(max_length=200)
......
......@@ -4,11 +4,11 @@ from backend.models.university import University
from django.contrib.postgres.fields import JSONField
from backend.models.my_model import MyModel, MyModelSerializer, MyModelViewSet
from django.contrib.auth.models import User
from backend.utils import get_viewset_permissions, get_moderation_level
from backend.utils import get_viewset_permissions, get_model_config
class UserData(MyModel):
moderation_level = get_moderation_level("UserData")
model_config = get_model_config("UserData")
owner = models.OneToOneField(User, on_delete=models.CASCADE)
contact_info = JSONField(default=dict)
......
from .is_member import is_member # noqa: F401
from .file import read_file, write_file # noqa: F401
from .find_api_end_point_for_viewset import find_api_end_point_for_viewset # noqa: F401
from .get_moderation_level import get_moderation_level # noqa: F401
from .get_model_config import get_model_config # noqa: F401
from .get_viewset_permissions import get_viewset_permissions # noqa: F401
from .does_user_have_moderation_rights import does_user_have_moderation_rights # noqa: F401
......@@ -2,7 +2,7 @@ import yaml
from os.path import join, realpath, dirname
def get_moderation_level(model):
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:
......
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