Commit 42992788 authored by Florent Chehab's avatar Florent Chehab
Browse files

Backend completely reorganized to limit cyclic imports

parent c776e24f
Pipeline #27073 passed with stages
in 2 minutes and 27 seconds
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
class DriRestrictedModule(BasicModule):
class Meta:
abstract = True
class DriRestrictedModuleSerializer(BasicModuleSerializer):
class Meta:
model = DriRestrictedModule
class DriRestrictedModuleViewSet(BasicModuleViewSet):
serializer_class = DriRestrictedModuleSerializer
from .scholarship import Scholarship, ScholarshipSerializer, ScholarshipViewSet # noqa: F401
from django.db import models
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.location import Currency
from backend.models.basic_module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.currency import Currency
from rest_framework import serializers
from django.core.validators import MinValueValidator
......
from .tag import Tag, TagSerializer, TagViewSet # noqa: F401
from .taggedItem import TaggedItem, TaggedItemSerializer, TaggedItemViewSet # noqa: F401
from .tagged_item_validation import validate_content_against_config # noqa: F401
from django.db import models
from backend.models.my_model import MyModelVersionned, MyModelVersionnedSerializer, MyModelVersionnedViewSet
from backend.models.basic_module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from .tag import Tag
from .tagged_item_validation import tagged_item_validation
from backend.validators.tag import tagged_item_validation
from backend.models.tools import JSONField
class TaggedItem(MyModelVersionned):
class TaggedItem(BasicModule):
tag = models.ForeignKey(Tag, related_name='+', on_delete=models.PROTECT)
custom_content = JSONField(default=dict)
......@@ -13,13 +13,13 @@ class TaggedItem(MyModelVersionned):
abstract = True
class TaggedItemSerializer(MyModelVersionnedSerializer):
class TaggedItemSerializer(BasicModuleSerializer):
def my_validate(self, attrs):
tagged_item_validation(attrs)
return attrs
class TaggedItemViewSet(MyModelVersionnedViewSet):
class TaggedItemViewSet(BasicModuleViewSet):
def extend_queryset(self):
return self.mymodel_queryset.prefetch_related('tag')
......@@ -6,6 +6,3 @@ from .universityInfo import UniversityInfo, UniversityInfoSerializer, University
from .universitySemestersDates import UniversitySemestersDates, UniversitySemestersDatesSerializer, UniversitySemestersDatesViewSet # noqa: F401
from .universityModulesAPI import UniversityModulesViewSet # noqa: F401
from .universityTaggedItem import UniversityTaggedItem, UniversityTaggedItemSerializer, UniversityTaggedItemViewSet # noqa: F401
from .campus import Campus, CampusViewSet, CampusSerializer, MainCampusViewSet # noqa: F401
from .campusTaggedItem import CampusTaggedItem, CampusTaggedItemSerializer, CampusTaggedItemViewSet # noqa: F401
......@@ -3,7 +3,7 @@ from backend.models.my_model import MyModel
from backend.utils import get_model_config
from django.core.exceptions import ValidationError
from rest_framework.validators import ValidationError as RFValidationError
from backend.models.tag.validators.url import validate_extension
from backend.validators.tag.url import validate_extension
from django.conf import settings
from backend.models.my_model import MyModelSerializer, MyModelViewSet
from backend.utils import get_viewset_permissions
......
from django.db import models
from backend.models.university import University
from backend.models.module import DriRestrictedModule, DriRestrictedModuleSerializer, DriRestrictedModuleViewSet
from backend.models.basic_module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.utils import get_model_config, get_viewset_permissions
class UniversityDri(DriRestrictedModule):
class UniversityDri(BasicModule):
model_config = get_model_config("UniversityDri")
university = models.ManyToManyField(
University, related_name="university_dri")
......@@ -14,14 +14,14 @@ class UniversityDri(DriRestrictedModule):
return UniversityDriSerializer
class UniversityDriSerializer(DriRestrictedModuleSerializer):
class UniversityDriSerializer(BasicModuleSerializer):
class Meta:
model = UniversityDri
fields = '__all__'
class UniversityDriViewSet(DriRestrictedModuleViewSet):
class UniversityDriViewSet(BasicModuleViewSet):
permission_classes = get_viewset_permissions("UniversityDriViewSet")
queryset = UniversityDri.objects.all() # pylint: disable=E1101
serializer_class = UniversityDriSerializer
from django.db import models
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.basic_module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.university import University
from backend.models.location import Currency
from backend.models.currency import Currency
from django.core.validators import MinValueValidator
from backend.utils import get_model_config, get_viewset_permissions
......
from backend.models.university import University
from backend.models.university.campus import CampusSerializer
from backend.models.campus import CampusSerializer
from backend.models.university import UniversityDriSerializer
from backend.models.my_model import MyModelSerializer, MyModelViewSet
......
from django.db import models
from backend.models.university import University
from backend.models.module import Scholarship, ScholarshipSerializer, ScholarshipViewSet
from backend.models.scholarship import Scholarship, ScholarshipSerializer, ScholarshipViewSet
from backend.utils import get_model_config, get_viewset_permissions
......
from django.db import models
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.basic_module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.university import University
from rest_framework import serializers
from backend.utils import get_model_config, get_viewset_permissions
......
from django.test import TestCase
from backend.models.module.scholarship import ScholarshipSerializer
from backend.models.scholarship import ScholarshipSerializer
import pytest
from rest_framework.validators import ValidationError
......@@ -8,15 +8,15 @@ class ScholarshipTestCase(TestCase):
def test_scholarhip_validation(self):
ser = ScholarshipSerializer()
attrs = {
'usefull_links': [],
'comment': ''
}
with pytest.raises(ValidationError):
attrs = {
'amount_max': 100,
'amount_min': 200
}
attrs['amount_min'] = 200
attrs['amount_max'] = 100
ser.my_validate(attrs)
attrs = {
'amount_max': 200,
'amount_min': 100
}
attrs['amount_min'] = 100
attrs['amount_max'] = 200
ser.my_validate(attrs)
......@@ -11,7 +11,10 @@ class SemesterDatesTestCase(TestCase):
def test_validation(self):
def build(l):
return {sem: val for sem, val in zip(semesters, l)}
tmp = {sem: val for sem, val in zip(semesters, l)}
tmp['comment'] = ""
tmp['usefull_links'] = []
return tmp
def _test_attrs_error(attrs):
with pytest.raises(ValidationError):
......
......@@ -2,7 +2,7 @@ from django.test import TestCase
import pytest
from rest_framework.validators import ValidationError as RFValidationError
from django.core.validators import ValidationError as DJValidationError
from backend.models.tag.validators.url import validate_extension, validate_url
from backend.validators.tag.url import validate_extension, validate_url
class ValidationUrlTestCase(TestCase):
......
from .url import validate_url # noqa: F401
from .text import validate_text # noqa: F401
from .tagged_item_validation import validate_content_against_config # noqa: F401
from .checks import check_required
from .validators import validate_url, validate_text
from .url import validate_url
from .text import validate_text
from rest_framework.validators import ValidationError
from .tags_config import PHOTOS_TAG_GONFIG
from .tags_config import PHOTOS_TAG_CONFIG
from .tags_config import USEFULL_LINKS_CONFIG
......@@ -29,7 +30,7 @@ def validate_content_against_config(config, content):
elif field_type == 'text':
validate_text(field_config, field_submitted)
elif field_type == 'photos':
validate_content_against_config({"photos": PHOTOS_TAG_GONFIG}, {
validate_content_against_config({"photos": PHOTOS_TAG_CONFIG}, {
"photos": field_submitted})
elif field_type == 'usefull_links':
validate_content_against_config({"ul": USEFULL_LINKS_CONFIG}, {
......
from .photos import PHOTOS_TAG_GONFIG # noqa: F401
from .photos import PHOTOS_TAG_CONFIG # noqa: F401
from .usefull_links import USEFULL_LINKS_CONFIG # noqa: F401
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