Commit a0dc489b authored by Florent Chehab's avatar Florent Chehab

Basic Modules for university don and SemesterDate model renamed

Photo and UniversityPhoto added
Module => Versionned Module
Versionned Module added
UML update
parent ae80961b
Pipeline #26359 passed with stages
in 1 minute and 27 seconds
......@@ -3,10 +3,9 @@
package AbstractModels #lightgrey{
abstract class Module{
+ icon : string
+ name : string
+ description : string
abstract class VersionnedModule <Will be versionned\n in the app>{
+ modified_by : user
+ modified_date : date
}
abstract class BasicModule{
......@@ -21,13 +20,13 @@ package AbstractModels #lightgrey{
}
abstract class Photo{
+ file : image
+ tile : string
+ photo : image
+ title : string
+ description : MD
}
BasicModule -left-|> Module
Photo -right-|> Module
BasicModule -left-|> VersionnedModule
Photo -right-|> VersionnedModule
ScholarShip -left-|> BasicModule
}
......
......@@ -10,7 +10,7 @@ package UniversityModule{
abstract class ScholarShipCopyUniversity as "Scholarship" #red
class CultureUniversity as "Culture"
class PhotoUniversity
class UniversityPhoto
class Courses
class SpecialOffer
class OtherStuff
......@@ -36,15 +36,15 @@ package UniversityModule{
SemestersDates -up-|> BasicModuleCopyUniversity
UniversityInfo -up-|> BasicModuleCopyUniversity
PhotoUniversity -left-|> PhotoCopyUniversity
UniversityPhoto -left-|> PhotoCopyUniversity
UniversityScholarship -right-|> ScholarShipCopyUniversity
class UniversityVirtualCopy as "University" < copy for\n cleaner UML> #lightgrey
CultureUniversity "1" -down[bold,#green]- "1" UniversityVirtualCopy
PhotoUniversity "1" -right[bold,#green]- "1" UniversityVirtualCopy
UniversityPhoto "*" -right- "1" UniversityVirtualCopy
Courses "1" -down[bold,#green]- "1" UniversityVirtualCopy
OtherStuff "1" -down[bold,#green]- "1" UniversityVirtualCopy
Insurances "1" -down[bold,#green]- "1" UniversityVirtualCopy
......
from django.contrib import admin
from reversion_compare.admin import CompareVersionAdmin
from rex.models.location import Country, City
from rex.models.university import University, Campus, UniversityScholarship
from rex.models.university import UniversityInfo
from rex.models.university import SemestersDates
from rex.models.university import UniversitySemestersDates
from rex.models.university import UniversityInsurance
from rex.models.location import Country, City
from rex.models.university import UniversityCourses
from rex.models.university import UniversityCulture
from rex.models.university import UniversityOtherStuff
from rex.models.university import UniversitySpecialOffer
from rex.models.university import UniversityPhoto
from rex.models.tools import Currency
CLASSIC_MODELS = [
Country,
City
City,
Currency
]
VERSIONNED_MODELS = [
......@@ -17,8 +27,13 @@ VERSIONNED_MODELS = [
Campus,
UniversityScholarship,
UniversityInfo,
SemestersDates,
UniversityInsurance
UniversitySemestersDates,
UniversityInsurance,
UniversityCulture,
UniversityCourses,
UniversityOtherStuff,
UniversitySpecialOffer,
UniversityPhoto,
]
for model in CLASSIC_MODELS:
......
# Generated by Django 2.0.3 on 2018-08-20 19:48
from django.db import migrations, models
import django.db.models.deletion
import rex.models.tools.usefullLinksField
class Migration(migrations.Migration):
dependencies = [
('rex', '0012_campus_usefull_links'),
]
operations = [
migrations.CreateModel(
name='UniversityCourses',
fields=[
('comment', models.TextField(blank=True)),
('usefull_links', rex.models.tools.usefullLinksField.UsefullLinksField(blank=True, default=[], validators=[rex.models.tools.usefullLinksField.validate_usefull_links])),
('university', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, related_name='university_courses', serialize=False, to='rex.University')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='UniversityCulture',
fields=[
('comment', models.TextField(blank=True)),
('usefull_links', rex.models.tools.usefullLinksField.UsefullLinksField(blank=True, default=[], validators=[rex.models.tools.usefullLinksField.validate_usefull_links])),
('university', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, related_name='university_culture', serialize=False, to='rex.University')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='UniversityOtherStuff',
fields=[
('comment', models.TextField(blank=True)),
('usefull_links', rex.models.tools.usefullLinksField.UsefullLinksField(blank=True, default=[], validators=[rex.models.tools.usefullLinksField.validate_usefull_links])),
('university', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, related_name='university_other_stuff', serialize=False, to='rex.University')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='UniversitySpecialOffer',
fields=[
('comment', models.TextField(blank=True)),
('usefull_links', rex.models.tools.usefullLinksField.UsefullLinksField(blank=True, default=[], validators=[rex.models.tools.usefullLinksField.validate_usefull_links])),
('university', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, related_name='university_special_offer', serialize=False, to='rex.University')),
],
options={
'abstract': False,
},
),
]
# Generated by Django 2.0.3 on 2018-08-20 19:53
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('rex', '0013_universitycourses_universityculture_universityotherstuff_universityspecialoffer'),
]
operations = [
migrations.RenameModel(
old_name='SemestersDates',
new_name='UniversitySemestersDates',
),
]
# Generated by Django 2.0.3 on 2018-08-21 08:41
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import rex.models.tools.usefullLinksField
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('rex', '0014_auto_20180820_2153'),
]
operations = [
migrations.CreateModel(
name='File',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('location', models.CharField(max_length=300)),
('description', models.TextField(blank=True, null=True)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='UniversityPhotos',
fields=[
('comment', models.TextField(blank=True)),
('usefull_links', rex.models.tools.usefullLinksField.UsefullLinksField(blank=True, default=[], validators=[rex.models.tools.usefullLinksField.validate_usefull_links])),
('university', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, related_name='university_photos', serialize=False, to='rex.University')),
('photos', models.ManyToManyField(to='rex.File')),
],
options={
'abstract': False,
},
),
]
# Generated by Django 2.0.3 on 2018-08-21 08:43
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('rex', '0015_file_universityphotos'),
]
operations = [
migrations.RemoveField(
model_name='universityphotos',
name='comment',
),
migrations.RemoveField(
model_name='universityphotos',
name='usefull_links',
),
]
# Generated by Django 2.0.3 on 2018-08-21 08:52
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('rex', '0016_auto_20180821_1043'),
]
operations = [
migrations.RemoveField(
model_name='file',
name='user',
),
]
# Generated by Django 2.0.3 on 2018-08-21 09:27
from django.db import migrations, models
import django.db.models.deletion
import rex.utils.friendly_path
class Migration(migrations.Migration):
dependencies = [
('rex', '0017_remove_file_user'),
]
operations = [
migrations.CreateModel(
name='UniversityPhoto',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('photo', models.ImageField(default='path/to/my/default/image.jpg', max_length=250, upload_to=rex.utils.friendly_path.friendly_path('uploads/universities/photos/', 'name'))),
('title', models.CharField(max_length=200)),
('description', models.TextField(blank=True, null=True)),
('university', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='university_photos', to='rex.University')),
],
),
migrations.RemoveField(
model_name='universityphotos',
name='photos',
),
migrations.RemoveField(
model_name='universityphotos',
name='university',
),
migrations.DeleteModel(
name='File',
),
migrations.DeleteModel(
name='UniversityPhotos',
),
migrations.AlterUniqueTogether(
name='universityphoto',
unique_together={('university', 'photo')},
),
]
from .location import location # noqa: F401
from .university import university # noqa: F401
from .module import module # noqa: F401
from .module import VersionnedModule # noqa: F401
from .module import Module # noqa: F401
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 django.db import models
from rex.models.tools import UsefullLinksField
from rex.models.module import Module
from rest_framework import serializers
from rex.models.module import VersionnedModule, VersionnedModuleSerializer
class BasicModule(Module):
class BasicModule(VersionnedModule):
comment = models.TextField(blank=True)
usefull_links = UsefullLinksField(blank=True)
......@@ -13,16 +12,8 @@ class BasicModule(Module):
abstract = True
class BasicModuleSerializer(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 BasicModuleSerializer(VersionnedModuleSerializer):
class Meta:
model = BasicModule
fields = ('comment', 'usefull_links', 'modified_by', 'modified_date')
fields = '__all__'
from django.db import models
from rex.models.module import VersionnedModule
from rex.utils.friendly_path import friendly_path
path_and_rename = friendly_path("uploads/universities/photos/", 'title')
class Photo(VersionnedModule):
photo = models.ImageField(upload_to=path_and_rename, max_length=250,
default='path/to/my/default/image.jpg') # TODO CHANGE !
title = models.CharField(max_length=200)
description = models.TextField(null=True, blank=True)
class Meta:
abstract = True
from django.db import models
from reversion.models import Version
from rest_framework import serializers
class Module(models.Model):
class VersionnedModule(models.Model):
def modified_date(self):
try:
......@@ -23,6 +24,12 @@ class Module(models.Model):
abstract = True
"""
API RELATED STUFF BELLOW
"""
class VersionnedModuleSerializer(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()
......@@ -3,5 +3,11 @@ from .campus import Campus, CampusViewSet, CampusSerializer # noqa: F401
from .universityAPI import UniversitySerializer, UniversityViewSet # noqa: F401
from .universityScholarship import UniversityScholarship, UniversityScholarshipViewSet # noqa: F401
from .universityInfo import UniversityInfo, UniversityInfoViewSet # noqa: F401
from .semestersDates import SemestersDates, SemestersDatesViewSet # noqa: F401
from .basicModulesUniversity import UniversityInsurance, UniversityInsuranceViewSet # noqa: F401
from .universitySemestersDates import UniversitySemestersDates, UniversitySemestersDatesViewSet # noqa: F401
from .universityBasicModules import UniversityInsurance, UniversityInsuranceViewSet # noqa: F401
from .universityBasicModules import UniversityCourses, UniversityCoursesViewSet # noqa: F401
from .universityBasicModules import UniversityCulture, UniversityCultureViewSet # noqa: F401
from .universityBasicModules import UniversityOtherStuff, UniversityOtherStuffViewSet # noqa: F401
from .universityBasicModules import UniversitySpecialOffer, UniversitySpecialOfferViewSet # noqa: F401
from .universityPhoto import UniversityPhoto, UniversityPhotoViewSet # noqa: F401
from django.db import models
from rex.models.module import Module
from rex.models.module import VersionnedModule
from rex.utils.friendly_path import friendly_path
path_and_rename = friendly_path("uploads/universities/logos/", 'name')
class University(Module):
class University(VersionnedModule):
"""
Model storing information about universities
"""
......
from django.db import models
from rex.models.module import BasicModule
from rex.models.university import University
from rest_framework import viewsets, permissions
from rex.models.module import BasicModuleSerializer
####################
# Insurance
###################
class UniversityInsurance(BasicModule):
university = models.OneToOneField(
University, on_delete=models.CASCADE, related_name='university_insurances', primary_key=True)
class UniversityInsuranceSerializer(BasicModuleSerializer):
class Meta:
model = UniversityInsurance
fields = '__all__'
class UniversityInsuranceViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
queryset = UniversityInsurance.objects.all() # pylint: disable=E1101
serializer_class = UniversityInsuranceSerializer
#####################
#####################
####################
# Culture
###################
class UniversityCulture(BasicModule):
university = models.OneToOneField(
University, on_delete=models.CASCADE, related_name='university_culture', primary_key=True)
class UniversityCultureSerializer(BasicModuleSerializer):
class Meta:
model = UniversityCulture
fields = '__all__'
class UniversityCultureViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
queryset = UniversityCulture.objects.all() # pylint: disable=E1101
serializer_class = UniversityCultureSerializer
#####################
#####################
####################
# Courses
###################
class UniversityCourses(BasicModule):
university = models.OneToOneField(
University, on_delete=models.CASCADE, related_name='university_courses', primary_key=True)
class UniversityCoursesSerializer(BasicModuleSerializer):
class Meta:
model = UniversityCourses
fields = '__all__'
class UniversityCoursesViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
queryset = UniversityCourses.objects.all() # pylint: disable=E1101
serializer_class = UniversityCoursesSerializer
#####################
#####################
####################
# SpecialOffer
###################
# TODO clarify this
class UniversitySpecialOffer(BasicModule):
university = models.OneToOneField(
University, on_delete=models.CASCADE, related_name='university_special_offer', primary_key=True)
class UniversitySpecialOfferSerializer(BasicModuleSerializer):
class Meta:
model = UniversitySpecialOffer
fields = '__all__'
# TODO switch to dict
class UniversitySpecialOfferViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
queryset = UniversitySpecialOffer.objects.all() # pylint: disable=E1101
serializer_class = UniversitySpecialOfferSerializer
#####################
#####################
####################
# OtherStuff
###################
class UniversityOtherStuff(BasicModule):
university = models.OneToOneField(
University, on_delete=models.CASCADE, related_name='university_other_stuff', primary_key=True)
class UniversityOtherStuffSerializer(BasicModuleSerializer):
class Meta:
model = UniversityOtherStuff
fields = '__all__'
# TODO switch to dict
class UniversityOtherStuffViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
queryset = UniversityOtherStuff.objects.all() # pylint: disable=E1101
serializer_class = UniversityOtherStuffSerializer
from django.db import models
from rex.models.module import BasicModule
from rex.models.university import University
from rex.models.module import VersionnedModuleSerializer
from rex.models.module import Photo
from rest_framework import viewsets, permissions
from rex.models.module import BasicModuleSerializer
class UniversityInsurance(BasicModule):
class UniversityPhoto(Photo):
university = models.OneToOneField(
University, on_delete=models.CASCADE, related_name='university_insurances', primary_key=True)
University,
on_delete=models.CASCADE,
related_name='university_photos')
class Meta:
unique_together = ('university', 'photo')
class UniversityInsuranceSerializer(BasicModuleSerializer):
class UniversityPhotoSerializer(VersionnedModuleSerializer):
class Meta:
model = UniversityInsurance
model = UniversityPhoto
fields = '__all__'
class UniversityInsuranceViewSet(viewsets.ModelViewSet): # TODO switch to dict
class UniversityPhotoViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
queryset = UniversityInsurance.objects.all() # pylint: disable=E1101
serializer_class = UniversityInsuranceSerializer
#####################
queryset = UniversityPhoto.objects.all() # pylint: disable=E1101
serializer_class = UniversityPhotoSerializer
......@@ -14,7 +14,7 @@ def check_nones(val1, val2):
return val1 is None and val2 is None
class SemestersDates(BasicModule):
class UniversitySemestersDates(BasicModule):
university = models.OneToOneField(
University, on_delete=models.CASCADE, related_name='university_semesters_dates', primary_key=True, null=False)
......@@ -41,21 +41,21 @@ class SemestersDates(BasicModule):
if not (spring_ok and autumn_ok):
print("ici")
raise serializers.ValidationError("Check your dates !")
super(SemestersDates, self).clean(*args, **kwargs)
super(UniversitySemestersDates, self).clean(*args, **kwargs)
def save(self, *args, **kwargs):
self.full_clean()
super(SemestersDates, self).save(*args, **kwargs)
super(UniversitySemestersDates, self).save(*args, **kwargs)
class SemestersDatesSerializer(BasicModuleSerializer):
class UniversitySemestersDatesSerializer(BasicModuleSerializer):
class Meta:
model = SemestersDates
model = UniversitySemestersDates
fields = '__all__'
class SemestersDatesViewSet(viewsets.ModelViewSet): # TODO switch to dict
class UniversitySemestersDatesViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
queryset = SemestersDates.objects.all() # pylint: disable=E1101
serializer_class = SemestersDatesSerializer
queryset = UniversitySemestersDates.objects.all() # pylint: disable=E1101
serializer_class = UniversitySemestersDatesSerializer
......@@ -7,9 +7,16 @@ from rex.models.university import UniversityViewSet
from rex.models.university import CampusViewSet
from rex.models.university import UniversityScholarshipViewSet
from rex.models.university import UniversityInfoViewSet
from rex.models.university import SemestersDatesViewSet
from rex.models.university import UniversitySemestersDatesViewSet
from rex.models.university import UniversityInsuranceViewSet
from rex.models.university import UniversityCoursesViewSet
from rex.models.university import UniversityCultureViewSet
from rex.models.university import UniversityOtherStuffViewSet
from rex.models.university import UniversitySpecialOfferViewSet
from rex.models.university import UniversityPhotoViewSet
from rex.models.tools import CurrencyViewSet
from rest_framework.documentation import include_docs_urls
......@@ -24,10 +31,18 @@ router.register(r'country', CountryViewSet)
router.register(r'city', CityViewSet)
router.register(r'campus', CampusViewSet)
router.register(r'university', UniversityViewSet)
router.register(r'university_scholarship', UniversityScholarshipViewSet)
router.register(r'university_info', UniversityInfoViewSet)
router.register(r'university_insurance', UniversityInsuranceViewSet)
router.register(r'semesters_dates', SemestersDatesViewSet)
router.register(r'university_more/scholarship', UniversityScholarshipViewSet)
router.register(r'university_more/info', UniversityInfoViewSet)
router.register(r'university_more/insurance', UniversityInsuranceViewSet)
router.register(r'university_more/semesters_dates', UniversitySemestersDatesViewSet)
router.register(r'university_more/courses', UniversityCoursesViewSet)
router.register(r'university_more/culture', UniversityCultureViewSet)
router.register(r'university_more/other_stuff', UniversityOtherStuffViewSet)
router.register(r'university_more/photos', UniversityPhotoViewSet)
router.register(r'university_more/special_offer',
UniversitySpecialOfferViewSet)
router.register(r'currency', CurrencyViewSet)
urlpatterns += [url(r'^api/', include(router.urls))]
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