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

Model get_serializer added everywhere

parent 73f73809
Pipeline #26661 passed with stages
in 3 minutes
...@@ -18,7 +18,9 @@ from backend.models.location import CityTransport ...@@ -18,7 +18,9 @@ from backend.models.location import CityTransport
from backend.models.location import CityTourism from backend.models.location import CityTourism
from backend.models.location import CityOtherStuff from backend.models.location import CityOtherStuff
from backend.models.university import University, Campus, UniversityScholarship from backend.models.university import University
from backend.models.university import Campus
from backend.models.university import UniversityScholarship
from backend.models.university import UniversityInfo from backend.models.university import UniversityInfo
from backend.models.university import UniversitySemestersDates from backend.models.university import UniversitySemestersDates
...@@ -102,3 +104,6 @@ for model in CLASSIC_MODELS: ...@@ -102,3 +104,6 @@ for model in CLASSIC_MODELS:
for model in VERSIONNED_MODELS: for model in VERSIONNED_MODELS:
admin.site.register(model, CompareVersionAdmin) admin.site.register(model, CompareVersionAdmin)
if (model.get_serializer().Meta.model != model):
raise Exception(
"Get_serializer configuration incorrect in", str(model))
...@@ -11,7 +11,8 @@ class CityTransport(BasicModule): ...@@ -11,7 +11,8 @@ class CityTransport(BasicModule):
city = models.OneToOneField( city = models.OneToOneField(
City, on_delete=models.CASCADE, related_name='city_transport', primary_key=True) City, on_delete=models.CASCADE, related_name='city_transport', primary_key=True)
def get_serializer(self): @classmethod
def get_serializer(cls):
return CityTransportSerializer return CityTransportSerializer
...@@ -39,6 +40,10 @@ class CityTourism(BasicModule): ...@@ -39,6 +40,10 @@ class CityTourism(BasicModule):
city = models.OneToOneField( city = models.OneToOneField(
City, on_delete=models.CASCADE, related_name='city_tourism', primary_key=True) City, on_delete=models.CASCADE, related_name='city_tourism', primary_key=True)
@classmethod
def get_serializer(cls):
return CityTourismSerializer
class CityTourismSerializer(BasicModuleSerializer): class CityTourismSerializer(BasicModuleSerializer):
class Meta: class Meta:
...@@ -64,6 +69,10 @@ class CityOtherStuff(BasicModule): ...@@ -64,6 +69,10 @@ class CityOtherStuff(BasicModule):
city = models.OneToOneField( city = models.OneToOneField(
City, on_delete=models.CASCADE, related_name='city_other_stuff', primary_key=True) City, on_delete=models.CASCADE, related_name='city_other_stuff', primary_key=True)
@classmethod
def get_serializer(cls):
return CityOtherStuffSerializer
class CityOtherStuffSerializer(BasicModuleSerializer): class CityOtherStuffSerializer(BasicModuleSerializer):
class Meta: class Meta:
......
...@@ -10,6 +10,10 @@ class CityPhoto(Photo): ...@@ -10,6 +10,10 @@ class CityPhoto(Photo):
on_delete=models.CASCADE, on_delete=models.CASCADE,
related_name='city_photos') related_name='city_photos')
@classmethod
def get_serializer(cls):
return CityPhotoSerializer
class Meta: class Meta:
unique_together = ('city', 'photo') unique_together = ('city', 'photo')
......
...@@ -11,6 +11,10 @@ class CountryVisaAdministrative(BasicModule): ...@@ -11,6 +11,10 @@ class CountryVisaAdministrative(BasicModule):
country = models.OneToOneField( country = models.OneToOneField(
Country, on_delete=models.CASCADE, related_name='country_visa_administrative', primary_key=True) Country, on_delete=models.CASCADE, related_name='country_visa_administrative', primary_key=True)
@classmethod
def get_serializer(cls):
return CountryVisaAdministrativeSerializer
class CountryVisaAdministrativeSerializer(BasicModuleSerializer): class CountryVisaAdministrativeSerializer(BasicModuleSerializer):
class Meta: class Meta:
...@@ -37,6 +41,10 @@ class CountryHealthInsurance(BasicModule): ...@@ -37,6 +41,10 @@ class CountryHealthInsurance(BasicModule):
country = models.OneToOneField( country = models.OneToOneField(
Country, on_delete=models.CASCADE, related_name='country_health_insurances', primary_key=True) Country, on_delete=models.CASCADE, related_name='country_health_insurances', primary_key=True)
@classmethod
def get_serializer(cls):
return CountryHealthInsuranceSerializer
class CountryHealthInsuranceSerializer(BasicModuleSerializer): class CountryHealthInsuranceSerializer(BasicModuleSerializer):
class Meta: class Meta:
...@@ -62,6 +70,10 @@ class CountryOtherInsurance(BasicModule): ...@@ -62,6 +70,10 @@ class CountryOtherInsurance(BasicModule):
country = models.OneToOneField( country = models.OneToOneField(
Country, on_delete=models.CASCADE, related_name='country_other_insurances', primary_key=True) Country, on_delete=models.CASCADE, related_name='country_other_insurances', primary_key=True)
@classmethod
def get_serializer(cls):
return CountryOtherInsuranceSerializer
class CountryOtherInsuranceSerializer(BasicModuleSerializer): class CountryOtherInsuranceSerializer(BasicModuleSerializer):
class Meta: class Meta:
...@@ -86,6 +98,10 @@ class CountryCulture(BasicModule): ...@@ -86,6 +98,10 @@ class CountryCulture(BasicModule):
country = models.OneToOneField( country = models.OneToOneField(
Country, on_delete=models.CASCADE, related_name='country_culture', primary_key=True) Country, on_delete=models.CASCADE, related_name='country_culture', primary_key=True)
@classmethod
def get_serializer(cls):
return CountryCultureSerializer
class CountryCultureSerializer(BasicModuleSerializer): class CountryCultureSerializer(BasicModuleSerializer):
class Meta: class Meta:
...@@ -110,6 +126,10 @@ class CountryTransport(BasicModule): ...@@ -110,6 +126,10 @@ class CountryTransport(BasicModule):
country = models.OneToOneField( country = models.OneToOneField(
Country, on_delete=models.CASCADE, related_name='country_transport', primary_key=True) Country, on_delete=models.CASCADE, related_name='country_transport', primary_key=True)
@classmethod
def get_serializer(cls):
return CountryTransportSerializer
class CountryTransportSerializer(BasicModuleSerializer): class CountryTransportSerializer(BasicModuleSerializer):
class Meta: class Meta:
...@@ -135,6 +155,10 @@ class CountryTourism(BasicModule): ...@@ -135,6 +155,10 @@ class CountryTourism(BasicModule):
country = models.OneToOneField( country = models.OneToOneField(
Country, on_delete=models.CASCADE, related_name='country_tourism', primary_key=True) Country, on_delete=models.CASCADE, related_name='country_tourism', primary_key=True)
@classmethod
def get_serializer(cls):
return CountryTourismSerializer
class CountryTourismSerializer(BasicModuleSerializer): class CountryTourismSerializer(BasicModuleSerializer):
class Meta: class Meta:
...@@ -160,6 +184,10 @@ class CountryOtherStuff(BasicModule): ...@@ -160,6 +184,10 @@ class CountryOtherStuff(BasicModule):
country = models.OneToOneField( country = models.OneToOneField(
Country, on_delete=models.CASCADE, related_name='country_other_stuff', primary_key=True) Country, on_delete=models.CASCADE, related_name='country_other_stuff', primary_key=True)
@classmethod
def get_serializer(cls):
return CountryOtherStuffSerializer
class CountryOtherStuffSerializer(BasicModuleSerializer): class CountryOtherStuffSerializer(BasicModuleSerializer):
class Meta: class Meta:
......
...@@ -7,6 +7,10 @@ class CountryDri(DriRestrictedModule): ...@@ -7,6 +7,10 @@ class CountryDri(DriRestrictedModule):
country = models.ManyToManyField( country = models.ManyToManyField(
Country, related_name="country_dri") Country, related_name="country_dri")
@classmethod
def get_serializer(cls):
return CountryDriSerializer
class CountryDriSerializer(DriRestrictedModuleSerializer): class CountryDriSerializer(DriRestrictedModuleSerializer):
......
...@@ -10,6 +10,10 @@ class CountryPhoto(Photo): ...@@ -10,6 +10,10 @@ class CountryPhoto(Photo):
on_delete=models.CASCADE, on_delete=models.CASCADE,
related_name='country_photos') related_name='country_photos')
@classmethod
def get_serializer(cls):
return CountryPhotoSerializer
class Meta: class Meta:
unique_together = ('country', 'photo') unique_together = ('country', 'photo')
......
...@@ -7,6 +7,10 @@ class CountryScholarship(Scholarship): ...@@ -7,6 +7,10 @@ class CountryScholarship(Scholarship):
country = models.ManyToManyField( country = models.ManyToManyField(
Country, related_name="country_scholarhip") Country, related_name="country_scholarhip")
@classmethod
def get_serializer(cls):
return CountryScholarshipSerializer
class CountryScholarshipSerializer(ScholarshipSerializer): class CountryScholarshipSerializer(ScholarshipSerializer):
......
...@@ -10,7 +10,8 @@ class ForTestingVersionning(MyModelVersionned): ...@@ -10,7 +10,8 @@ class ForTestingVersionning(MyModelVersionned):
""" """
bbb = models.CharField(max_length=100) bbb = models.CharField(max_length=100)
def get_serializer(self): @classmethod
def get_serializer(cls):
return ForTestingVersionningSerializer return ForTestingVersionningSerializer
......
...@@ -10,13 +10,14 @@ from django.core import serializers as djangoSerializers ...@@ -10,13 +10,14 @@ from django.core import serializers as djangoSerializers
class MyModelVersionned(MyModel): class MyModelVersionned(MyModel):
def get_serializer(self): @classmethod
def get_serializer(cls):
""" """
This function is required for handling This function is required for handling
versionning easily. versionning easily.
You have to put the correct value in each subclass You have to put the correct value in each subclass
""" """
return None raise Exception("Get_serializer must be redifined in subclass")
class Meta: class Meta:
abstract = True abstract = True
......
...@@ -31,6 +31,10 @@ class Campus(BasicModule): ...@@ -31,6 +31,10 @@ class Campus(BasicModule):
def location(self): def location(self):
return {'lat': self.lat, 'lon': self.lon} return {'lat': self.lat, 'lon': self.lon}
@classmethod
def get_serializer(cls):
return CampusSerializer
class Meta: class Meta:
unique_together = ('is_main_campus', 'university') unique_together = ('is_main_campus', 'university')
......
...@@ -11,6 +11,10 @@ class CampusCultureAndStudentLife(BasicModule): ...@@ -11,6 +11,10 @@ class CampusCultureAndStudentLife(BasicModule):
campus = models.OneToOneField( campus = models.OneToOneField(
Campus, on_delete=models.CASCADE, related_name='campus_culture_and_sl', primary_key=True) Campus, on_delete=models.CASCADE, related_name='campus_culture_and_sl', primary_key=True)
@classmethod
def get_serializer(cls):
return CampusCultureAndStudentLifeSerializer
class CampusCultureAndStudentLifeSerializer(BasicModuleSerializer): class CampusCultureAndStudentLifeSerializer(BasicModuleSerializer):
class Meta: class Meta:
...@@ -34,6 +38,10 @@ class CampusAccommodation(BasicModule): ...@@ -34,6 +38,10 @@ class CampusAccommodation(BasicModule):
campus = models.OneToOneField( campus = models.OneToOneField(
Campus, on_delete=models.CASCADE, related_name='campus_accomodation', primary_key=True) Campus, on_delete=models.CASCADE, related_name='campus_accomodation', primary_key=True)
@classmethod
def get_serializer(cls):
return CampusAccommodationSerializer
class CampusAccommodationSerializer(BasicModuleSerializer): class CampusAccommodationSerializer(BasicModuleSerializer):
class Meta: class Meta:
...@@ -57,6 +65,10 @@ class CampusTransport(BasicModule): ...@@ -57,6 +65,10 @@ class CampusTransport(BasicModule):
campus = models.OneToOneField( campus = models.OneToOneField(
Campus, on_delete=models.CASCADE, related_name='campus_transport', primary_key=True) Campus, on_delete=models.CASCADE, related_name='campus_transport', primary_key=True)
@classmethod
def get_serializer(cls):
return CampusTransportSerializer
class CampusTransportSerializer(BasicModuleSerializer): class CampusTransportSerializer(BasicModuleSerializer):
class Meta: class Meta:
...@@ -81,6 +93,10 @@ class CampusOtherStuff(BasicModule): ...@@ -81,6 +93,10 @@ class CampusOtherStuff(BasicModule):
campus = models.OneToOneField( campus = models.OneToOneField(
Campus, on_delete=models.CASCADE, related_name='campus_other_stuff', primary_key=True) Campus, on_delete=models.CASCADE, related_name='campus_other_stuff', primary_key=True)
@classmethod
def get_serializer(cls):
return CampusOtherStuffSerializer
class CampusOtherStuffSerializer(BasicModuleSerializer): class CampusOtherStuffSerializer(BasicModuleSerializer):
class Meta: class Meta:
......
...@@ -12,6 +12,10 @@ class UniversityInsurance(BasicModule): ...@@ -12,6 +12,10 @@ class UniversityInsurance(BasicModule):
university = models.OneToOneField( university = models.OneToOneField(
University, on_delete=models.CASCADE, related_name='university_insurances', primary_key=True) University, on_delete=models.CASCADE, related_name='university_insurances', primary_key=True)
@classmethod
def get_serializer(cls):
return UniversityInsuranceSerializer
class UniversityInsuranceSerializer(BasicModuleSerializer): class UniversityInsuranceSerializer(BasicModuleSerializer):
class Meta: class Meta:
...@@ -35,6 +39,10 @@ class UniversityCulture(BasicModule): ...@@ -35,6 +39,10 @@ class UniversityCulture(BasicModule):
university = models.OneToOneField( university = models.OneToOneField(
University, on_delete=models.CASCADE, related_name='university_culture', primary_key=True) University, on_delete=models.CASCADE, related_name='university_culture', primary_key=True)
@classmethod
def get_serializer(cls):
return UniversityCultureSerializer
class UniversityCultureSerializer(BasicModuleSerializer): class UniversityCultureSerializer(BasicModuleSerializer):
class Meta: class Meta:
...@@ -58,6 +66,10 @@ class UniversityCourses(BasicModule): ...@@ -58,6 +66,10 @@ class UniversityCourses(BasicModule):
university = models.OneToOneField( university = models.OneToOneField(
University, on_delete=models.CASCADE, related_name='university_courses', primary_key=True) University, on_delete=models.CASCADE, related_name='university_courses', primary_key=True)
@classmethod
def get_serializer(cls):
return UniversityCoursesSerializer
class UniversityCoursesSerializer(BasicModuleSerializer): class UniversityCoursesSerializer(BasicModuleSerializer):
class Meta: class Meta:
...@@ -83,6 +95,10 @@ class UniversitySpecialOffer(BasicModule): ...@@ -83,6 +95,10 @@ class UniversitySpecialOffer(BasicModule):
university = models.OneToOneField( university = models.OneToOneField(
University, on_delete=models.CASCADE, related_name='university_special_offer', primary_key=True) University, on_delete=models.CASCADE, related_name='university_special_offer', primary_key=True)
@classmethod
def get_serializer(cls):
return UniversitySpecialOfferSerializer
class UniversitySpecialOfferSerializer(BasicModuleSerializer): class UniversitySpecialOfferSerializer(BasicModuleSerializer):
class Meta: class Meta:
...@@ -107,6 +123,10 @@ class UniversityOtherStuff(BasicModule): ...@@ -107,6 +123,10 @@ class UniversityOtherStuff(BasicModule):
university = models.OneToOneField( university = models.OneToOneField(
University, on_delete=models.CASCADE, related_name='university_other_stuff', primary_key=True) University, on_delete=models.CASCADE, related_name='university_other_stuff', primary_key=True)
@classmethod
def get_serializer(cls):
return UniversityOtherStuffSerializer
class UniversityOtherStuffSerializer(BasicModuleSerializer): class UniversityOtherStuffSerializer(BasicModuleSerializer):
class Meta: class Meta:
......
...@@ -7,6 +7,10 @@ class UniversityDri(DriRestrictedModule): ...@@ -7,6 +7,10 @@ class UniversityDri(DriRestrictedModule):
university = models.ManyToManyField( university = models.ManyToManyField(
University, related_name="university_dri") University, related_name="university_dri")
@classmethod
def get_serializer(cls):
return UniversityDriSerializer
class UniversityDriSerializer(DriRestrictedModuleSerializer): class UniversityDriSerializer(DriRestrictedModuleSerializer):
......
...@@ -26,6 +26,10 @@ class UniversityInfo(BasicModule): ...@@ -26,6 +26,10 @@ class UniversityInfo(BasicModule):
costs_currency = models.ForeignKey(Currency, on_delete=models.PROTECT) costs_currency = models.ForeignKey(Currency, on_delete=models.PROTECT)
@classmethod
def get_serializer(cls):
return UniversityInfoSerializer
class UniversityInfoSerializer(BasicModuleSerializer): class UniversityInfoSerializer(BasicModuleSerializer):
......
...@@ -10,6 +10,10 @@ class UniversityPhoto(Photo): ...@@ -10,6 +10,10 @@ class UniversityPhoto(Photo):
on_delete=models.CASCADE, on_delete=models.CASCADE,
related_name='university_photos') related_name='university_photos')
@classmethod
def get_serializer(cls):
return UniversityPhotoSerializer
class Meta: class Meta:
unique_together = ('university', 'photo') unique_together = ('university', 'photo')
......
...@@ -7,6 +7,10 @@ class UniversityScholarship(Scholarship): ...@@ -7,6 +7,10 @@ class UniversityScholarship(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")
@classmethod
def get_serializer(cls):
return UniversityScholarshipSerializer
class UniversityScholarshipSerializer(ScholarshipSerializer): class UniversityScholarshipSerializer(ScholarshipSerializer):
......
...@@ -24,6 +24,9 @@ class UniversitySemestersDates(BasicModule): ...@@ -24,6 +24,9 @@ class UniversitySemestersDates(BasicModule):
autumn_begin = models.DateField(null=True, blank=True) autumn_begin = models.DateField(null=True, blank=True)
autumn_end = models.DateField(null=True, blank=True) autumn_end = models.DateField(null=True, blank=True)
@classmethod
def get_serializer(cls):
return UniversitySemestersDatesSerializer
# Need custom validation # Need custom validation
# TODO add tests # TODO add tests
......
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