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

Models simplification

parent 0b4867c0
......@@ -43,7 +43,7 @@ MIDDLEWARE = [
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'general.middleware.LoginRequiredMiddleware',
#'general.middleware.LoginRequiredMiddleware',
]
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 rex.models.module import Module
from rex.models.module import BasicModule, BasicModuleSerializer
from rex.models.location import City
from rex.models.university import University
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_name = "Campus principal"
module_description = "Campus de l'université."
......@@ -39,21 +39,11 @@ class Campus(Module):
unique_together = ('is_main_campus', 'university')
class CampusSerializer(serializers.ModelSerializer):
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 CampusSerializer(BasicModuleSerializer):
class Meta:
model = Campus
fields = ('is_main_campus', 'university', 'lat', 'lon',
'name', 'city', 'modified_by', 'modified_date',
'id')
fields = '__all__'
class CampusViewSet(viewsets.ModelViewSet): # TODO switch to dict
......
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 rest_framework import serializers, viewsets, permissions
......@@ -48,22 +48,11 @@ class SemestersDates(BasicModule):
super(SemestersDates, self).save(*args, **kwargs)
class SemestersDatesSerializer(serializers.ModelSerializer):
# 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 SemestersDatesSerializer(BasicModuleSerializer):
class Meta:
model = SemestersDates
fields = ('university', 'autumn_begin', 'autumn_end',
'spring_begin', 'spring_end', 'modified_by', 'modified_date')
fields = '__all__'
class SemestersDatesViewSet(viewsets.ModelViewSet): # TODO switch to dict
......
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.tools import Currency
from django.core.validators import MinValueValidator
from rest_framework import serializers, viewsets, permissions
from rest_framework import viewsets, permissions
class UniversityInfo(BasicModule):
......@@ -28,22 +28,11 @@ class UniversityInfo(BasicModule):
costs_currency = models.ForeignKey(Currency, on_delete=models.PROTECT)
class UniversityInfoSerializer(serializers.ModelSerializer):
# 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 UniversityInfoSerializer(BasicModuleSerializer):
class Meta:
model = UniversityInfo
fields = ('university', 'cost_exchange', 'cost_double_degree',
'costs_currency', 'modified_by', 'modified_date')
fields = '__all__'
class UniversityInfoViewSet(viewsets.ModelViewSet): # TODO switch to dict
......
from django.db import models
from rex.models.university import University
from rex.models.module import Scholarship
from rest_framework import serializers, viewsets, permissions
from rex.models.module import Scholarship, BasicModuleSerializer
from rest_framework import viewsets, permissions
class UniversityScholarship(Scholarship):
module_name = "University Scholarship"
university = models.ForeignKey(
University, on_delete=models.PROTECT, null=False, related_name="univScholarship")
# API
class UniversityScholarshipSerializer(serializers.ModelSerializer):
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 UniversityScholarshipSerializer(BasicModuleSerializer):
class Meta:
model = UniversityScholarship
fields = ('university', 'modified_by', 'modified_date', 'comment', 'usefull_links',
'type', 'currency', 'amount_min', 'amount_max', 'id')
fields = '__all__'
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