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

Merge branch 'clean_backend' into 'master'

Clean backend

See merge request chehabfl/outgoing_rex!35
parents 9e62f092 92f591e0
from django.db import models
from backend.models.my_model import MyModel, MyModelSerializer, MyModelViewSet
from backend.models.abstract.my_model import MyModel, MyModelSerializer, MyModelViewSet
from backend.utils import get_model_config, get_viewset_permissions
......
from django.db import models
from backend.models.other_core import Department
from backend.models.my_model import MyModel, MyModelSerializer, MyModelViewSet
from backend.models.abstract.my_model import MyModel, MyModelSerializer, MyModelViewSet
from backend.utils import get_model_config, get_viewset_permissions
......
from .tag import Tag, TagSerializer, TagViewSet # noqa: F401
from .taggedItem import TaggedItem, TaggedItemSerializer, TaggedItemViewSet # noqa: F401
from django.db import models
from backend.models.my_model import MyModel, MyModelSerializer, MyModelViewSet
from backend.models.tools import JSONField
from backend.models.abstract.my_model import MyModel, MyModelSerializer, MyModelViewSet
from backend.fields import JSONField
from backend.utils import get_viewset_permissions, get_model_config
......
......@@ -4,5 +4,5 @@ from .universityScholarship import UniversityScholarship, UniversityScholarshipS
from .universityDri import UniversityDri, UniversityDriSerializer, UniversityDriViewSet # noqa: F401
from .universityInfo import UniversityInfo, UniversityInfoSerializer, UniversityInfoViewSet # noqa: F401
from .universitySemestersDates import UniversitySemestersDates, UniversitySemestersDatesSerializer, UniversitySemestersDatesViewSet # noqa: F401
from .universityModulesAPI import UniversityModulesViewSet # noqa: F401
from .universityTaggedItem import UniversityTaggedItem, UniversityTaggedItemSerializer, UniversityTaggedItemViewSet # noqa: F401
from .universityModulesAPI import UniversityModulesViewSet # noqa: F401
from django.db import models
from backend.models.my_model import MyModel
from backend.models.abstract.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.validators.tag.url import validate_extension
from django.conf import settings
from backend.models.my_model import MyModelSerializer, MyModelViewSet
from backend.models.abstract.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.basic_module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.abstract.basic_module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.utils import get_model_config, get_viewset_permissions
......
from django.db import models
from backend.models.basic_module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.abstract.basic_module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.university import University
from backend.models.currency import Currency
from django.core.validators import MinValueValidator
......
......@@ -2,13 +2,25 @@ from backend.models.university import University
from backend.models.campus import CampusSerializer
from backend.models.university import UniversityDriSerializer
from backend.models.my_model import MyModelSerializer, MyModelViewSet
from backend.models.university import UniversityInfoSerializer
from backend.models.university import UniversityScholarshipSerializer
from backend.models.university import UniversitySemestersDatesSerializer
from backend.models.university import UniversityTaggedItemSerializer
from backend.models.abstract.my_model import MyModelSerializer, MyModelViewSet
from backend.utils import get_viewset_permissions
class UniversityModulesSerializer(MyModelSerializer):
univ_campus = CampusSerializer(many=True, read_only=True)
university_campuses = CampusSerializer(many=True, read_only=True)
university_scholarships = UniversityScholarshipSerializer(
many=True, read_only=True)
university_tagged_items = UniversityTaggedItemSerializer(
many=True, read_only=True)
university_dri = UniversityDriSerializer(many=True, read_only=True)
university_info = UniversityInfoSerializer(read_only=True)
university_semesters_dates = UniversitySemestersDatesSerializer(
read_only=True)
class Meta:
model = University
......@@ -18,9 +30,16 @@ class UniversityModulesSerializer(MyModelSerializer):
class UniversityModulesViewSet(MyModelViewSet):
permission_classes = get_viewset_permissions("UniversityModulesViewSet")
serializer_class = UniversityModulesSerializer
queryset = University.objects.all()
LIST_SHOULD_BE_DETAIL = True
def get_queryset(self):
def extend_queryset(self):
univ_id = self.kwargs['univ_id']
return University.objects.filter(id=univ_id).prefetch_related('univ_campus', 'university_dri') # pylint: disable=E1101
# queryset = get_queryset()
return self.my_model_queryset.filter(pk=univ_id).prefetch_related(
'university_campuses',
'university_dri',
'university_info',
'university_scholarships',
'university_semesters_dates',
'university_tagged_items'
) # pylint: disable=E1101
from django.db import models
from backend.models.university import University
from backend.models.scholarship import Scholarship, ScholarshipSerializer, ScholarshipViewSet
from backend.models.abstract.scholarship import Scholarship, ScholarshipSerializer, ScholarshipViewSet
from backend.utils import get_model_config, get_viewset_permissions
class UniversityScholarship(Scholarship):
model_config = get_model_config("UniversityScholarship")
university = models.ForeignKey(
University, on_delete=models.PROTECT, null=False, related_name="univScholarship")
university = models.ManyToManyField(University, related_name="university_scholarships")
@classmethod
def get_serializer(cls):
......
from django.db import models
from backend.models.basic_module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.abstract.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.db import models
from backend.models.tag import TaggedItem, TaggedItemSerializer, TaggedItemViewSet
from backend.models.abstract.taggedItem import TaggedItem, TaggedItemSerializer, TaggedItemViewSet
from backend.models.university import University
from backend.utils import get_model_config, get_viewset_permissions
class UniversityTaggedItem(TaggedItem):
model_config = get_model_config("UniversityTaggedItem")
university = models.OneToOneField(
University, on_delete=models.PROTECT, related_name='city_items', primary_key=True)
university = models.ForeignKey(
University, on_delete=models.PROTECT, related_name='university_tagged_items')
@classmethod
def get_serializer(cls):
......
......@@ -3,8 +3,8 @@ from backend.models.other_core.specialty import Specialty
from backend.models.other_core.semester import Semester
from backend.models.university import University
from django.contrib.auth.models import User
from backend.models.tools import JSONField
from backend.models.my_model import MyModel, MyModelSerializer, MyModelViewSet
from backend.fields import JSONField
from backend.models.abstract.my_model import MyModel, MyModelSerializer, MyModelViewSet
from backend.utils import get_model_config, get_viewset_permissions
......
......@@ -3,7 +3,7 @@ from django.core.validators import MaxValueValidator
from backend.models.user import UserRestrictedModule, UserRestrictedModuleSerializer, UserRestrictedModuleViewSet
from backend.models.user import PreviousDeparture
from backend.models.tools import JSONField
from backend.fields import JSONField
from backend.utils import get_model_config, get_viewset_permissions
......
from django.db import models
from rest_framework import serializers
from backend.models.university import University
from backend.models.tools import JSONField
from backend.models.my_model import MyModel, MyModelSerializer, MyModelViewSet
from backend.fields import JSONField
from backend.models.abstract.my_model import MyModel, MyModelSerializer, MyModelViewSet
from django.contrib.auth.models import User
from backend.utils import get_viewset_permissions, get_model_config
......
from django.db import models
from rest_framework import serializers
from django.contrib.auth.models import User
from backend.models.my_model import MyModel, MyModelSerializer, MyModelViewSet
from backend.models.abstract.my_model import MyModel, MyModelSerializer, MyModelViewSet
class UserRestrictedModule(MyModel):
"""
TODO move to abstract folder ?
"""
# RGPD made easy with CASCADE
owner = models.ForeignKey(User, on_delete=models.CASCADE)
......
......@@ -2,6 +2,7 @@ from .noDeleteIfNotStaff import NoDeleteIfNotStaff # noqa: F401
from .isOwner import IsOwner # noqa: F401
from .noDelete import NoDelete # noqa: F401
from .isStaffOrReadOnly import IsStaffOrReadOnly # noqa: F401
from .readOnly import ReadOnly # noqa: F401
from .isDriOrReadOnly import IsDriOrReadOnly # noqa: F401
from .default_viewset_permissions import DEFAULT_VIEWSET_PERMISSIONS # noqa: F401
from .obj_moderation_permission import OBJ_MODERATION_PERMISSIONS # noqa: F401
......
from rest_framework import permissions
class ReadOnly(permissions.BasePermission):
def has_permission(self, request, view):
if request.method in permissions.SAFE_METHODS:
return True
else:
return False
from django.test import override_settings
from .withUserTestCase import WithUserTestCase
from backend.models.my_model import ForTestingModeration
from backend.models.my_model import PendingModeration
from backend.models.abstract.my_model import ForTestingModeration
from backend.models.abstract.my_model import PendingModeration
from django.contrib.contenttypes.models import ContentType
from django.conf import settings
from backend.models.university import University
......
from django.test import TestCase
from backend.models.my_model.myModel import validate_obj_model_lv
from backend.models.abstract.my_model.myModel import validate_obj_model_lv
import pytest
from django.core.exceptions import ValidationError
from backend.permissions import OBJ_MODERATION_PERMISSIONS
......
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