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