Commit 9e62f092 authored by Florent Chehab's avatar Florent Chehab
Browse files

Merge branch 'work_on_backend' into 'master'

Work on backend

See merge request chehabfl/outgoing_rex!34
parents 9c099cdf 2303c5bd
Pipeline #27075 passed with stages
in 2 minutes and 42 seconds
from .basicModule import BasicModule, BasicModuleSerializer, BasicModuleViewSet # noqa: F401
from .scholarship import Scholarship, ScholarshipSerializer, ScholarshipViewSet # noqa: F401
from .driRestrictedModule import DriRestrictedModule, DriRestrictedModuleSerializer, DriRestrictedModuleViewSet # noqa: F401
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
......@@ -28,6 +28,7 @@ class Scholarship(BasicModule):
class ScholarshipSerializer(BasicModuleSerializer):
def my_validate(self, attrs):
attrs = super(ScholarshipSerializer, self).my_validate(attrs)
if attrs['amount_max'] < attrs['amount_min']:
raise serializers.ValidationError(
"Amount_max should be greater or equal than amount_min")
......
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
......@@ -29,6 +29,8 @@ class UniversitySemestersDates(BasicModule):
class UniversitySemestersDatesSerializer(BasicModuleSerializer):
def my_validate(self, attrs):
attrs = super(UniversitySemestersDatesSerializer, self).my_validate(attrs)
s_b, s_e = attrs['spring_begin'], attrs['spring_end']
a_b, a_e = attrs['autumn_begin'], attrs['autumn_end']
......
......@@ -14,7 +14,7 @@ class UniversityTaggedItem(TaggedItem):
return UniversityTaggedItemSerializer
class Meta:
unique_together = ('university', 'tag')
unique_together = ('university', 'tag', 'importance_level')
class UniversityTaggedItemSerializer(TaggedItemSerializer):
......
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
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