Commit 86ee2fdf authored by Florent Chehab's avatar Florent Chehab
Browse files

Models simplification

parent 0b4867c0
...@@ -43,7 +43,7 @@ MIDDLEWARE = [ ...@@ -43,7 +43,7 @@ MIDDLEWARE = [
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',
'general.middleware.LoginRequiredMiddleware', #'general.middleware.LoginRequiredMiddleware',
] ]
LOGIN_URL = '/user/login' LOGIN_URL = '/user/login'
......
# Generated by Django 2.0.3 on 2018-08-20 17:12
from django.db import migrations
import rex.models.tools.usefullLinksField
class Migration(migrations.Migration):
dependencies = [
('rex', '0011_universityinsurance'),
]
operations = [
migrations.AddField(
model_name='campus',
name='usefull_links',
field=rex.models.tools.usefullLinksField.UsefullLinksField(blank=True, default=[], validators=[rex.models.tools.usefullLinksField.validate_usefull_links]),
),
]
from django.db import models from django.db import models
from rex.models.module import Module from rex.models.module import BasicModule, BasicModuleSerializer
from rex.models.location import City from rex.models.location import City
from rex.models.university import University from rex.models.university import University
from django.core.validators import MinValueValidator, MaxValueValidator from django.core.validators import MinValueValidator, MaxValueValidator
from rest_framework import serializers, viewsets, permissions from rest_framework import viewsets, permissions
class Campus(Module): class Campus(BasicModule):
module_icon = "You forget to override the icon in the sub-class : I know" module_icon = "You forget to override the icon in the sub-class : I know"
module_name = "Campus principal" module_name = "Campus principal"
module_description = "Campus de l'université." module_description = "Campus de l'université."
...@@ -39,21 +39,11 @@ class Campus(Module): ...@@ -39,21 +39,11 @@ class Campus(Module):
unique_together = ('is_main_campus', 'university') unique_together = ('is_main_campus', 'university')
class CampusSerializer(serializers.ModelSerializer): class CampusSerializer(BasicModuleSerializer):
modified_by = serializers.SerializerMethodField()
modified_date = serializers.SerializerMethodField()
def get_modified_by(self, obj):
return obj.modified_by()
def get_modified_date(self, obj):
return obj.modified_date()
class Meta: class Meta:
model = Campus model = Campus
fields = ('is_main_campus', 'university', 'lat', 'lon', fields = '__all__'
'name', 'city', 'modified_by', 'modified_date',
'id')
class CampusViewSet(viewsets.ModelViewSet): # TODO switch to dict class CampusViewSet(viewsets.ModelViewSet): # TODO switch to dict
......
from django.db import models from django.db import models
from rex.models.module import BasicModule from rex.models.module import BasicModule, BasicModuleSerializer
from rex.models.university import University from rex.models.university import University
from rest_framework import serializers, viewsets, permissions from rest_framework import serializers, viewsets, permissions
...@@ -48,22 +48,11 @@ class SemestersDates(BasicModule): ...@@ -48,22 +48,11 @@ class SemestersDates(BasicModule):
super(SemestersDates, self).save(*args, **kwargs) super(SemestersDates, self).save(*args, **kwargs)
class SemestersDatesSerializer(serializers.ModelSerializer): class SemestersDatesSerializer(BasicModuleSerializer):
# TODO generalize below
modified_by = serializers.SerializerMethodField()
modified_date = serializers.SerializerMethodField()
def get_modified_by(self, obj):
return obj.modified_by()
def get_modified_date(self, obj):
return obj.modified_date()
class Meta: class Meta:
model = SemestersDates model = SemestersDates
fields = ('university', 'autumn_begin', 'autumn_end', fields = '__all__'
'spring_begin', 'spring_end', 'modified_by', 'modified_date')
class SemestersDatesViewSet(viewsets.ModelViewSet): # TODO switch to dict class SemestersDatesViewSet(viewsets.ModelViewSet): # TODO switch to dict
......
from django.db import models from django.db import models
from rex.models.module import BasicModule from rex.models.module import BasicModule, BasicModuleSerializer
from rex.models.university import University from rex.models.university import University
from rex.models.tools import Currency from rex.models.tools import Currency
from django.core.validators import MinValueValidator from django.core.validators import MinValueValidator
from rest_framework import serializers, viewsets, permissions from rest_framework import viewsets, permissions
class UniversityInfo(BasicModule): class UniversityInfo(BasicModule):
...@@ -28,22 +28,11 @@ class UniversityInfo(BasicModule): ...@@ -28,22 +28,11 @@ class UniversityInfo(BasicModule):
costs_currency = models.ForeignKey(Currency, on_delete=models.PROTECT) costs_currency = models.ForeignKey(Currency, on_delete=models.PROTECT)
class UniversityInfoSerializer(serializers.ModelSerializer): class UniversityInfoSerializer(BasicModuleSerializer):
# TODO generalize below
modified_by = serializers.SerializerMethodField()
modified_date = serializers.SerializerMethodField()
def get_modified_by(self, obj):
return obj.modified_by()
def get_modified_date(self, obj):
return obj.modified_date()
class Meta: class Meta:
model = UniversityInfo model = UniversityInfo
fields = ('university', 'cost_exchange', 'cost_double_degree', fields = '__all__'
'costs_currency', 'modified_by', 'modified_date')
class UniversityInfoViewSet(viewsets.ModelViewSet): # TODO switch to dict class UniversityInfoViewSet(viewsets.ModelViewSet): # TODO switch to dict
......
from django.db import models from django.db import models
from rex.models.university import University from rex.models.university import University
from rex.models.module import Scholarship from rex.models.module import Scholarship, BasicModuleSerializer
from rest_framework import serializers, viewsets, permissions from rest_framework import viewsets, permissions
class UniversityScholarship(Scholarship): class UniversityScholarship(Scholarship):
module_name = "University Scholarship"
university = models.ForeignKey( university = models.ForeignKey(
University, on_delete=models.PROTECT, null=False, related_name="univScholarship") University, on_delete=models.PROTECT, null=False, related_name="univScholarship")
# API # API
class UniversityScholarshipSerializer(serializers.ModelSerializer): class UniversityScholarshipSerializer(BasicModuleSerializer):
modified_by = serializers.SerializerMethodField()
modified_date = serializers.SerializerMethodField()
def get_modified_by(self, obj):
return obj.modified_by()
def get_modified_date(self, obj):
return obj.modified_date()
class Meta: class Meta:
model = UniversityScholarship model = UniversityScholarship
fields = ('university', 'modified_by', 'modified_date', 'comment', 'usefull_links', fields = '__all__'
'type', 'currency', 'amount_min', 'amount_max', 'id')
class UniversityScholarshipViewSet(viewsets.ModelViewSet): class UniversityScholarshipViewSet(viewsets.ModelViewSet):
......
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