Commit 1a6bb9ab authored by Florent Chehab's avatar Florent Chehab
Browse files

Moved everything to new models !

parent 7cfe87b2
This diff is collapsed.
from django.db import models
from rest_framework import serializers, permissions
from backend.models.tools import DictModeViewSet
from rest_framework import serializers
from backend.models.location import Country
from backend.models.my_model import MyModel, MyModelSerializer, MyModelVersionnedViewSet
# Data model based on : https://unstats.un.org/unsd/methodology/m49/overview/
class City(models.Model):
class City(MyModel):
name = models.CharField(max_length=200)
local_name = models.CharField(max_length=200, null=True, blank=True)
# We add an area to distinguish similarly named cities
......@@ -21,7 +18,7 @@ API RELATED STUFF BELLOW
"""
class CitySerializer(serializers.ModelSerializer):
class CitySerializer(MyModelSerializer):
country_url = serializers.SerializerMethodField()
def get_country_url(self, obj):
......@@ -36,7 +33,6 @@ class CitySerializer(serializers.ModelSerializer):
fields = '__all__'
class CityViewSet(DictModeViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
class CityViewSet(MyModelVersionnedViewSet):
queryset = City.objects.all() # pylint: disable=E1101
serializer_class = CitySerializer
from django.db import models
from backend.models.module import BasicModule
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.location import City
from rest_framework import viewsets, permissions
from backend.models.module import BasicModuleSerializer
####################
......@@ -20,8 +18,8 @@ class CityTransportSerializer(BasicModuleSerializer):
fields = '__all__'
class CityTransportViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
class CityTransportViewSet(BasicModuleViewSet):
queryset = CityTransport.objects.all() # pylint: disable=E1101
serializer_class = CityTransportSerializer
......@@ -45,8 +43,8 @@ class CityTourismSerializer(BasicModuleSerializer):
fields = '__all__'
class CityTourismViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
class CityTourismViewSet(BasicModuleViewSet):
queryset = CityTourism.objects.all() # pylint: disable=E1101
serializer_class = CityTourismSerializer
......@@ -70,8 +68,7 @@ class CityOtherStuffSerializer(BasicModuleSerializer):
fields = '__all__'
# TODO switch to dict
class CityOtherStuffViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
class CityOtherStuffViewSet(BasicModuleViewSet):
queryset = CityOtherStuff.objects.all() # pylint: disable=E1101
serializer_class = CityOtherStuffSerializer
from django.db import models
from backend.models.location import City
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 CityPhoto(Photo):
......@@ -16,14 +14,13 @@ class CityPhoto(Photo):
unique_together = ('city', 'photo')
class CityPhotoSerializer(VersionnedModuleSerializer):
class CityPhotoSerializer(PhotoSerializer):
class Meta:
model = CityPhoto
fields = '__all__'
class CityPhotoViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
class CityPhotoViewSet(PhotoViewSet):
queryset = CityPhoto.objects.all() # pylint: disable=E1101
serializer_class = CityPhotoSerializer
from django.db import models
from rest_framework import serializers, permissions
from backend.models.tools import DictModeViewSet
from backend.models.my_model import MyModel, MyModelSerializer, MyModelVersionnedViewSet
# Data model based on : https://unstats.un.org/unsd/methodology/m49/overview/
class Country(models.Model):
class Country(MyModel):
name = models.CharField(max_length=200)
iso_alpha2_code = models.CharField(primary_key=True, max_length=2)
iso_alpha3_code = models.CharField(
......@@ -20,19 +19,13 @@ class Country(models.Model):
max_length=3, null=True, blank=True)
"""
API RELATED STUFF BELLOW
"""
class CountrySerializer(serializers.ModelSerializer):
class CountrySerializer(MyModelSerializer):
class Meta:
model = Country
fields = '__all__'
class CountryViewSet(DictModeViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
class CountryViewSet(MyModelVersionnedViewSet):
queryset = Country.objects.all() # pylint: disable=E1101
serializer_class = CountrySerializer
from django.db import models
from backend.models.module import BasicModule
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.location import Country
from rest_framework import viewsets, permissions
from backend.models.module import BasicModuleSerializer
####################
......@@ -20,9 +18,8 @@ class CountryVisaAdministrativeSerializer(BasicModuleSerializer):
fields = '__all__'
# TODO switch to dict
class CountryVisaAdministrativeViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
class CountryVisaAdministrativeViewSet(BasicModuleViewSet):
queryset = CountryVisaAdministrative.objects.all() # pylint: disable=E1101
serializer_class = CountryVisaAdministrativeSerializer
......@@ -47,9 +44,8 @@ class CountryHealthInsuranceSerializer(BasicModuleSerializer):
fields = '__all__'
# TODO switch to dict
class CountryHealthInsuranceViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
class CountryHealthInsuranceViewSet(BasicModuleViewSet):
queryset = CountryHealthInsurance.objects.all() # pylint: disable=E1101
serializer_class = CountryHealthInsuranceSerializer
......@@ -73,9 +69,8 @@ class CountryOtherInsuranceSerializer(BasicModuleSerializer):
fields = '__all__'
# TODO switch to dict
class CountryOtherInsuranceViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
class CountryOtherInsuranceViewSet(BasicModuleViewSet):
queryset = CountryOtherInsurance.objects.all() # pylint: disable=E1101
serializer_class = CountryOtherInsuranceSerializer
......@@ -98,8 +93,8 @@ class CountryCultureSerializer(BasicModuleSerializer):
fields = '__all__'
class CountryCultureViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
class CountryCultureViewSet(BasicModuleViewSet):
queryset = CountryCulture.objects.all() # pylint: disable=E1101
serializer_class = CountryCultureSerializer
......@@ -122,8 +117,8 @@ class CountryTransportSerializer(BasicModuleSerializer):
fields = '__all__'
class CountryTransportViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
class CountryTransportViewSet(BasicModuleViewSet):
queryset = CountryTransport.objects.all() # pylint: disable=E1101
serializer_class = CountryTransportSerializer
......@@ -147,8 +142,8 @@ class CountryTourismSerializer(BasicModuleSerializer):
fields = '__all__'
class CountryTourismViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
class CountryTourismViewSet(BasicModuleViewSet):
queryset = CountryTourism.objects.all() # pylint: disable=E1101
serializer_class = CountryTourismSerializer
......@@ -172,8 +167,7 @@ class CountryOtherStuffSerializer(BasicModuleSerializer):
fields = '__all__'
# TODO switch to dict
class CountryOtherStuffViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
class CountryOtherStuffViewSet(BasicModuleViewSet):
queryset = CountryOtherStuff.objects.all() # pylint: disable=E1101
serializer_class = CountryOtherStuffSerializer
from django.db import models
from backend.models.location import Country
from backend.models.module import DriRestrictedModule, DriRestrictedModuleSerializer
from rest_framework import viewsets, permissions
from backend.models.module import DriRestrictedModule, DriRestrictedModuleSerializer, DriRestrictedModuleViewSet
class CountryDri(DriRestrictedModule):
......@@ -16,7 +15,6 @@ class CountryDriSerializer(DriRestrictedModuleSerializer):
fields = '__all__'
class CountryDriViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
class CountryDriViewSet(DriRestrictedModuleViewSet):
queryset = CountryDri.objects.all() # pylint: disable=E1101
serializer_class = CountryDriSerializer
from django.db import models
from backend.models.location import Country
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 CountryPhoto(Photo):
......@@ -16,14 +14,13 @@ class CountryPhoto(Photo):
unique_together = ('country', 'photo')
class CountryPhotoSerializer(VersionnedModuleSerializer):
class CountryPhotoSerializer(PhotoSerializer):
class Meta:
model = CountryPhoto
fields = '__all__'
class CountryPhotoViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
class CountryPhotoViewSet(PhotoViewSet):
queryset = CountryPhoto.objects.all() # pylint: disable=E1101
serializer_class = CountryPhotoSerializer
from django.db import models
from backend.models.location import Country
from backend.models.module import Scholarship, BasicModuleSerializer
from rest_framework import viewsets, permissions
from backend.models.module import Scholarship, ScholarshipSerializer, ScholarshipViewSet
class CountryScholarship(Scholarship):
......@@ -9,14 +8,13 @@ class CountryScholarship(Scholarship):
Country, related_name="country_scholarhip")
class CountryScholarshipSerializer(BasicModuleSerializer):
class CountryScholarshipSerializer(ScholarshipSerializer):
class Meta:
model = CountryScholarship
fields = '__all__'
class CountryScholarshipViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
class CountryScholarshipViewSet(ScholarshipViewSet):
queryset = CountryScholarship.objects.all() # pylint: disable=E1101
serializer_class = CountryScholarshipSerializer
from .versionnedModule import VersionnedModule, VersionnedModuleSerializer # noqa: F401
from .basicModule import BasicModule, BasicModuleSerializer # noqa: F401
from .scholarship import Scholarship # noqa: F401
from .photo import Photo # noqa: F401
from .driRestrictedModule import DriRestrictedModule, DriRestrictedModuleSerializer # noqa: F401
from .basicModule import BasicModule, BasicModuleSerializer, BasicModuleViewSet # noqa: F401
from .scholarship import Scholarship, ScholarshipSerializer, ScholarshipViewSet # noqa: F401
from .photo import Photo, PhotoSerializer, PhotoViewSet # noqa: F401
from .driRestrictedModule import DriRestrictedModule, DriRestrictedModuleSerializer, DriRestrictedModuleViewSet # noqa: F401
from .currency import Currency, CurrencyViewSet, CurrencySerializer # noqa: F401
# MyModelVersionned, MyModelVersionnedSerializer # noqa: F401
from django.db import models
from backend.models.tools import UsefullLinksField
from backend.models.module import VersionnedModule, VersionnedModuleSerializer
from backend.models.my_model import MyModelVersionned, MyModelVersionnedSerializer, MyModelVersionnedViewSet
class BasicModule(VersionnedModule):
class BasicModule(MyModelVersionned):
comment = models.TextField(blank=True)
usefull_links = UsefullLinksField(blank=True)
......@@ -12,8 +12,12 @@ class BasicModule(VersionnedModule):
abstract = True
class BasicModuleSerializer(VersionnedModuleSerializer):
class BasicModuleSerializer(MyModelVersionnedSerializer):
class Meta:
model = BasicModule
fields = '__all__'
class BasicModuleViewSet(MyModelVersionnedViewSet):
serializer_class = BasicModuleSerializer
from django.db import models
from rest_framework import serializers, viewsets, permissions
from rest_framework import permissions
from django.core.validators import MinValueValidator
from backend.models.my_model import MyModel, MyModelSerializer, MyModelViewSet
class Currency(models.Model):
class Currency(MyModel):
code = models.CharField(primary_key=True, max_length=15)
name = models.CharField(max_length=100)
symbol = models.CharField(max_length=5)
......@@ -14,13 +15,13 @@ class Currency(models.Model):
)
class CurrencySerializer(serializers.ModelSerializer):
class CurrencySerializer(MyModelSerializer):
class Meta:
model = Currency
fields = '__all__'
class CurrencyViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.IsAdminUser,)
class CurrencyViewSet(MyModelViewSet):
permission_classes = (permissions.IsAdminUser,) # TODO : change
queryset = Currency.objects.all() # pylint: disable=E1101
serializer_class = CurrencySerializer
from backend.models.module import BasicModule, BasicModuleSerializer
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
class DriRestrictedModule(BasicModule):
......@@ -8,5 +8,9 @@ class DriRestrictedModule(BasicModule):
class DriRestrictedModuleSerializer(BasicModuleSerializer):
# TODO Check edit restrictions
pass
class Meta:
model = DriRestrictedModule
class DriRestrictedModuleViewSet(BasicModuleViewSet):
serializer_class = DriRestrictedModuleSerializer
from django.db import models
from backend.models.module import VersionnedModule
from backend.models.my_model import MyModelVersionned, MyModelVersionnedSerializer, MyModelVersionnedViewSet
from backend.utils.friendly_path import friendly_path
path_and_rename = friendly_path("uploads/universities/photos/", 'title')
class Photo(VersionnedModule):
class Photo(MyModelVersionned):
photo = models.ImageField(upload_to=path_and_rename, max_length=250,
default='path/to/my/default/image.jpg') # TODO CHANGE !
......@@ -15,3 +15,14 @@ class Photo(VersionnedModule):
class Meta:
abstract = True
class PhotoSerializer(MyModelVersionnedSerializer):
class Meta:
model = Photo
fields = '__all__'
class PhotoViewSet(MyModelVersionnedViewSet):
serializer_class = PhotoSerializer
from django.db import models
from backend.models.module import BasicModule
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from .currency import Currency
from rest_framework import serializers
from django.core.validators import MinValueValidator
......@@ -34,3 +34,14 @@ class Scholarship(BasicModule):
class Meta:
abstract = True
class ScholarshipSerializer(BasicModuleSerializer):
class Meta:
model = Scholarship
fields = '__all__'
class ScholarshipViewSet(BasicModuleViewSet):
serializer_class = ScholarshipSerializer
from django.db import models
from rest_framework import serializers
from django.contrib.auth.models import User
from backend.signals import new_revision_saved
import reversion
class VersionnedModule(models.Model):
updated_at = models.DateTimeField(auto_now=True)
updated_by = models.ForeignKey(
User, null=True, on_delete=models.SET_NULL)
class Meta:
abstract = True
class VersionnedModuleSerializer(serializers.ModelSerializer):
updated_by_username = serializers.SerializerMethodField(read_only=True)
def get_updated_by_username(self, obj):
if obj.updated_by:
return obj.updated_by.username
else:
return None
def save(self, **kwargs):
# Retrieve the user info from the request
user = self.context['request'].user
self.validated_data['updated_by'] = user
# Create a revision for the update or creation
with reversion.create_revision():
super(VersionnedModuleSerializer, self).save(**kwargs)
reversion.set_user(user)
# Signal save to perform concat of revisions
new_revision_saved.send(sender=self.__class__, obj=self.instance)
......@@ -4,7 +4,7 @@ from backend.models.tools import NoDeleteIfNotAdmin
from backend.models.tools import DictModeViewSet
class MyModelViewSet(DictModeViewSet): # TODO switch to dict
class MyModelViewSet(DictModeViewSet):
serializer_class = MyModelSerializer
permission_classes = (
permissions.IsAuthenticated,
......
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
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