Commit 7db3e41d authored by Florent Chehab's avatar Florent Chehab
Browse files

Merge branch 'feature_moderation' into 'frontend'

Feature moderation

See merge request chehabfl/outgoing_rex!13
parents f1c99e79 1a6bb9ab
from django.db import models
from rest_framework import serializers, viewsets, permissions
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
class PendingModeration(models.Model):
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.CharField(max_length=100) # 100 should be ok
referenced_object = GenericForeignKey('content_type', 'object_id')
updated_by = models.ForeignKey(User, on_delete=models.CASCADE)
updated_on = models.DateTimeField(null=True)
new_object = JSONField(default={})
class Meta:
unique_together = ('content_type', 'object_id')
class PendingModerationSerializer(serializers.ModelSerializer):
class Meta:
model = PendingModeration
fields = '__all__'
class PendingModerationViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.IsAdminUser,)
queryset = PendingModeration.objects.all() # pylint: disable=E1101
serializer_class = PendingModerationSerializer
from django.db import models
from rest_framework import serializers, viewsets, permissions
from backend.models.my_model import MyModel, MyModelSerializer, MyModelViewSet
from rest_framework import permissions
class Department(models.Model):
class Department(MyModel):
code = models.CharField(primary_key=True, max_length=6)
name = models.CharField(max_length=100)
active = models.BooleanField()
class DepartmentSerializer(serializers.ModelSerializer):
class DepartmentSerializer(MyModelSerializer):
class Meta:
model = Department
fields = '__all__'
class DepartmentViewSet(viewsets.ModelViewSet):
class DepartmentViewSet(MyModelViewSet):
permission_classes = (permissions.IsAdminUser,)
queryset = Department.objects.all() # pylint: disable=E1101
serializer_class = DepartmentSerializer
from django.db import models
from rest_framework import serializers, viewsets, permissions
from rest_framework import permissions
from backend.models.university import University
from backend.models.otherCore import Semester, Specialty
from backend.models.my_model import MyModel, MyModelSerializer, MyModelViewSet
class Offer(models.Model):
class Offer(MyModel):
semester = models.ForeignKey(Semester, on_delete=models.PROTECT)
university = models.ForeignKey(University, on_delete=models.PROTECT)
......@@ -20,13 +21,13 @@ class Offer(models.Model):
unique_together = ('semester', 'university')
class OfferSerializer(serializers.ModelSerializer):
class OfferSerializer(MyModelSerializer):
class Meta:
model = Offer
fields = '__all__'
class OfferViewSet(viewsets.ModelViewSet):
class OfferViewSet(MyModelViewSet):
permission_classes = (permissions.IsAdminUser,)
queryset = Offer.objects.all() # pylint: disable=E1101
serializer_class = OfferSerializer
from django.db import models
from rest_framework import serializers, viewsets, permissions
from rest_framework import permissions
from backend.models.my_model import MyModel, MyModelSerializer, MyModelViewSet
class Semester(models.Model):
class Semester(MyModel):
code = models.CharField(primary_key=True, max_length=6)
class SemesterSerializer(serializers.ModelSerializer):
class SemesterSerializer(MyModelSerializer):
class Meta:
model = Semester
fields = '__all__'
class SemesterViewSet(viewsets.ModelViewSet):
class SemesterViewSet(MyModelViewSet):
permission_classes = (permissions.IsAdminUser,)
queryset = Semester.objects.all() # pylint: disable=E1101
serializer_class = SemesterSerializer
from django.db import models
from rest_framework import serializers, viewsets, permissions
from rest_framework import permissions
from backend.models.otherCore import Department
from backend.models.my_model import MyModel, MyModelSerializer, MyModelViewSet
class Specialty(models.Model):
class Specialty(MyModel):
code = models.CharField(max_length=6)
department = models.ForeignKey(Department, on_delete=models.PROTECT)
name = models.CharField(max_length=100)
......@@ -14,13 +15,13 @@ class Specialty(models.Model):
# TODO add documentation : you should add departement.
class SpecialtySerializer(serializers.ModelSerializer):
class SpecialtySerializer(MyModelSerializer):
class Meta:
model = Specialty
fields = '__all__'
class SpecialtyViewSet(viewsets.ModelViewSet):
class SpecialtyViewSet(MyModelViewSet):
permission_classes = (permissions.IsAdminUser,)
queryset = Specialty.objects.all() # pylint: disable=E1101
serializer_class = SpecialtySerializer
from .DictModeViewSet import DictModeViewSet # noqa: F401
from .usefullLinksField import UsefullLinksField # noqa: F401
from .validateWithRestFramework import validate_with_rest_framework # noqa: F401
from .noDeleteIfNotAdmin import NoDeleteIfNotAdmin # noqa: F401
from rest_framework.permissions import BasePermission
class NoDeleteIfNotAdmin(BasePermission):
def has_permission(self, request, view):
if (not request.user.is_staff) and request.method == 'DELETE':
return False
return True
from django.db import models
from backend.models.module import BasicModule, BasicModuleSerializer
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.location import City
from backend.models.university import University
from django.core.validators import MinValueValidator, MaxValueValidator
from rest_framework import viewsets, permissions
class Campus(BasicModule):
......@@ -46,7 +45,7 @@ class CampusSerializer(BasicModuleSerializer):
fields = '__all__'
class CampusViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
queryset = Campus.objects.all().prefetch_related('updated_by') # pylint: disable=E1101
class CampusViewSet(BasicModuleViewSet):
queryset = Campus.objects.all().prefetch_related(
'updated_by') # pylint: disable=E1101
serializer_class = CampusSerializer
from django.db import models
from backend.models.module import BasicModule
from backend.models.university import Campus
from rest_framework import viewsets, permissions
from backend.models.module import BasicModuleSerializer
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
####################
# CultureAndStudentLife
......@@ -20,9 +18,7 @@ class CampusCultureAndStudentLifeSerializer(BasicModuleSerializer):
fields = '__all__'
# TODO switch to dict
class CampusCultureAndStudentLifeViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
class CampusCultureAndStudentLifeViewSet(BasicModuleViewSet):
queryset = CampusCultureAndStudentLife.objects.all() # pylint: disable=E1101
serializer_class = CampusCultureAndStudentLifeSerializer
......@@ -45,8 +41,7 @@ class CampusAccommodationSerializer(BasicModuleSerializer):
fields = '__all__'
class CampusAccommodationViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
class CampusAccommodationViewSet(BasicModuleViewSet):
queryset = CampusAccommodation.objects.all() # pylint: disable=E1101
serializer_class = CampusAccommodationSerializer
......@@ -69,8 +64,7 @@ class CampusTransportSerializer(BasicModuleSerializer):
fields = '__all__'
class CampusTransportViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
class CampusTransportViewSet(BasicModuleViewSet):
queryset = CampusTransport.objects.all() # pylint: disable=E1101
serializer_class = CampusTransportSerializer
......@@ -94,8 +88,6 @@ class CampusOtherStuffSerializer(BasicModuleSerializer):
fields = '__all__'
# TODO switch to dict
class CampusOtherStuffViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
class CampusOtherStuffViewSet(BasicModuleViewSet):
queryset = CampusOtherStuff.objects.all() # pylint: disable=E1101
serializer_class = CampusOtherStuffSerializer
from django.db import models
from backend.models.module import VersionnedModule
from backend.models.my_model import MyModel
from backend.utils.friendly_path import friendly_path
path_and_rename = friendly_path("uploads/universities/logos/", 'name')
class University(VersionnedModule):
class University(MyModel):
"""
Model storing information about universities
"""
......
from backend.models.university import University
from rest_framework import serializers, viewsets, permissions
from rest_framework import permissions
from backend.models.university.campus import CampusSerializer
from backend.models.tools import NoDeleteIfNotAdmin
from backend.models.my_model import MyModelSerializer, MyModelViewSet
class UniversitySerializer(serializers.ModelSerializer):
class UniversitySerializer(MyModelSerializer):
univ_campus = CampusSerializer(many=True, read_only=True)
class Meta:
model = University
fields = ('name', 'acronym', 'logo', 'id', 'univ_campus')
fields = '__all__'
class UniversityViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
queryset = University.objects.all().prefetch_related('univ_campus', 'univ_campus__updated_by') # pylint: disable=E1101
class UniversityViewSet(MyModelViewSet):
serializer_class = UniversitySerializer
permission_classes = (
permissions.IsAuthenticated,
NoDeleteIfNotAdmin,
)
queryset = University.objects.all()\
.prefetch_related('univ_campus', 'univ_campus__updated_by') # pylint: disable=E1101
from django.db import models
from backend.models.module import BasicModule
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.university import University
from rest_framework import viewsets, permissions
from backend.models.module import BasicModuleSerializer
####################
# Insurance
......@@ -20,8 +19,7 @@ class UniversityInsuranceSerializer(BasicModuleSerializer):
fields = '__all__'
class UniversityInsuranceViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
class UniversityInsuranceViewSet(BasicModuleViewSet):
queryset = UniversityInsurance.objects.all() # pylint: disable=E1101
serializer_class = UniversityInsuranceSerializer
......@@ -44,8 +42,7 @@ class UniversityCultureSerializer(BasicModuleSerializer):
fields = '__all__'
class UniversityCultureViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
class UniversityCultureViewSet(BasicModuleViewSet):
queryset = UniversityCulture.objects.all() # pylint: disable=E1101
serializer_class = UniversityCultureSerializer
......@@ -68,8 +65,7 @@ class UniversityCoursesSerializer(BasicModuleSerializer):
fields = '__all__'
class UniversityCoursesViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
class UniversityCoursesViewSet(BasicModuleViewSet):
queryset = UniversityCourses.objects.all() # pylint: disable=E1101
serializer_class = UniversityCoursesSerializer
......@@ -94,9 +90,7 @@ class UniversitySpecialOfferSerializer(BasicModuleSerializer):
fields = '__all__'
# TODO switch to dict
class UniversitySpecialOfferViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
class UniversitySpecialOfferViewSet(BasicModuleViewSet):
queryset = UniversitySpecialOffer.objects.all() # pylint: disable=E1101
serializer_class = UniversitySpecialOfferSerializer
......@@ -120,8 +114,6 @@ class UniversityOtherStuffSerializer(BasicModuleSerializer):
fields = '__all__'
# TODO switch to dict
class UniversityOtherStuffViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
class UniversityOtherStuffViewSet(BasicModuleViewSet):
queryset = UniversityOtherStuff.objects.all() # pylint: disable=E1101
serializer_class = UniversityOtherStuffSerializer
from django.db import models
from backend.models.university import University
from backend.models.module import DriRestrictedModule, DriRestrictedModuleSerializer
from rest_framework import viewsets, permissions
from backend.models.module import DriRestrictedModule, DriRestrictedModuleSerializer, DriRestrictedModuleViewSet
class UniversityDri(DriRestrictedModule):
......@@ -16,7 +15,6 @@ class UniversityDriSerializer(DriRestrictedModuleSerializer):
fields = '__all__'
class UniversityDriViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
class UniversityDriViewSet(DriRestrictedModuleViewSet):
queryset = UniversityDri.objects.all() # pylint: disable=E1101
serializer_class = UniversityDriSerializer
from django.db import models
from backend.models.module import BasicModule, BasicModuleSerializer
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.university import University
from backend.models.module import Currency
from django.core.validators import MinValueValidator
from rest_framework import viewsets, permissions
class UniversityInfo(BasicModule):
......@@ -35,7 +34,6 @@ class UniversityInfoSerializer(BasicModuleSerializer):
fields = '__all__'
class UniversityInfoViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
class UniversityInfoViewSet(BasicModuleViewSet):
queryset = UniversityInfo.objects.all() # pylint: disable=E1101
serializer_class = UniversityInfoSerializer
from backend.models.university import University
from rest_framework import serializers, viewsets, permissions
from backend.models.university.campus import CampusSerializer
from backend.models.university import UniversityDriSerializer
from backend.models.my_model import MyModelSerializer, MyModelViewSet
class UniversityModulesSerializer(serializers.ModelSerializer):
class UniversityModulesSerializer(MyModelSerializer):
univ_campus = CampusSerializer(many=True, read_only=True)
university_dri = UniversityDriSerializer(many=True, read_only=True)
......@@ -14,7 +14,7 @@ class UniversityModulesSerializer(serializers.ModelSerializer):
fields = '__all__'
class UniversityModulesViewSet(viewsets.ModelViewSet): # TODO switch to dict
class UniversityModulesViewSet(MyModelViewSet):
serializer_class = UniversityModulesSerializer
......@@ -22,5 +22,4 @@ class UniversityModulesViewSet(viewsets.ModelViewSet): # TODO switch to dict
univ_id = self.kwargs['univ_id']
return University.objects.filter(id=univ_id).prefetch_related('univ_campus', 'university_dri') # pylint: disable=E1101
permission_classes = (permissions.DjangoModelPermissions,)
# queryset = get_queryset()
from django.db import models
from backend.models.university import University
from backend.models.module import VersionnedModuleSerializer
from backend.models.module import Photo
from rest_framework import viewsets, permissions
from backend.models.module import Photo, PhotoSerializer, PhotoViewSet
class UniversityPhoto(Photo):
......@@ -16,14 +14,13 @@ class UniversityPhoto(Photo):
unique_together = ('university', 'photo')
class UniversityPhotoSerializer(VersionnedModuleSerializer):
class UniversityPhotoSerializer(PhotoSerializer):
class Meta:
model = UniversityPhoto
fields = '__all__'
class UniversityPhotoViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
class UniversityPhotoViewSet(PhotoViewSet):
queryset = UniversityPhoto.objects.all() # pylint: disable=E1101
serializer_class = UniversityPhotoSerializer
from django.db import models
from backend.models.university import University
from backend.models.module import Scholarship, BasicModuleSerializer
from rest_framework import viewsets, permissions
from backend.models.module import Scholarship, ScholarshipSerializer, ScholarshipViewSet
class UniversityScholarship(Scholarship):
......@@ -9,14 +8,13 @@ class UniversityScholarship(Scholarship):
University, on_delete=models.PROTECT, null=False, related_name="univScholarship")
class UniversityScholarshipSerializer(BasicModuleSerializer):
class UniversityScholarshipSerializer(ScholarshipSerializer):
class Meta:
model = UniversityScholarship
fields = '__all__'
class UniversityScholarshipViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
class UniversityScholarshipViewSet(ScholarshipViewSet):
queryset = UniversityScholarship.objects.all() # pylint: disable=E1101
serializer_class = UniversityScholarshipSerializer
from django.db import models
from backend.models.module import BasicModule, BasicModuleSerializer
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.university import University
from rest_framework import serializers, viewsets, permissions
from rest_framework import serializers
def check_nones(val1, val2):
......@@ -55,7 +55,6 @@ class UniversitySemestersDatesSerializer(BasicModuleSerializer):
fields = '__all__'
class UniversitySemestersDatesViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
class UniversitySemestersDatesViewSet(BasicModuleViewSet):
queryset = UniversitySemestersDates.objects.all() # pylint: disable=E1101
serializer_class = UniversitySemestersDatesSerializer
from .userRestrictedModule import UserRestrictedModule, UserRestrictedModuleSerializer # noqa: F401
from .userRestrictedModule import UserRestrictedModule, UserRestrictedModuleSerializer, UserRestrictedModuleViewSet # noqa: F401
from .previousDeparture import PreviousDeparture, PreviousDepartureViewSet # noqa: F401
from .previousDepartureFeedback import PreviousDepartureFeedback, PreviousDepartureFeedbackViewSet # noqa: F401
from .recommendationList import RecommendationList, RecommendationListSerializer, RecommendationListViewSet # noqa: F401
......
from django.db import models
from rest_framework import viewsets, permissions, serializers
from rest_framework import permissions
from backend.models.otherCore.specialty import Specialty
from backend.models.otherCore.semester import Semester
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
class PreviousDeparture(models.Model):
class PreviousDeparture(MyModel):
# 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)
......@@ -23,14 +23,14 @@ class PreviousDeparture(models.Model):
# when someone delete the link and relink we can rematch the data
class PreviousDepartureSerializer(serializers.ModelSerializer):
class PreviousDepartureSerializer(MyModelSerializer):
class Meta:
model = PreviousDeparture
fields = '__all__'
class PreviousDepartureViewSet(viewsets.ModelViewSet):
class PreviousDepartureViewSet(MyModelViewSet):
permission_classes = (permissions.IsAdminUser,)
queryset = PreviousDeparture.objects.all() # pylint: disable=E1101
serializer_class = PreviousDepartureSerializer
......
Supports Markdown
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