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

Basic Modules for university don and SemesterDate model renamed

Photo and UniversityPhoto added
Module => Versionned Module
Versionned Module added
UML update
parent ae80961b
...@@ -3,10 +3,9 @@ ...@@ -3,10 +3,9 @@
package AbstractModels #lightgrey{ package AbstractModels #lightgrey{
abstract class Module{ abstract class VersionnedModule <Will be versionned\n in the app>{
+ icon : string + modified_by : user
+ name : string + modified_date : date
+ description : string
} }
abstract class BasicModule{ abstract class BasicModule{
...@@ -21,13 +20,13 @@ package AbstractModels #lightgrey{ ...@@ -21,13 +20,13 @@ package AbstractModels #lightgrey{
} }
abstract class Photo{ abstract class Photo{
+ file : image + photo : image
+ tile : string + title : string
+ description : MD + description : MD
} }
BasicModule -left-|> Module BasicModule -left-|> VersionnedModule
Photo -right-|> Module Photo -right-|> VersionnedModule
ScholarShip -left-|> BasicModule ScholarShip -left-|> BasicModule
} }
......
...@@ -10,7 +10,7 @@ package UniversityModule{ ...@@ -10,7 +10,7 @@ package UniversityModule{
abstract class ScholarShipCopyUniversity as "Scholarship" #red abstract class ScholarShipCopyUniversity as "Scholarship" #red
class CultureUniversity as "Culture" class CultureUniversity as "Culture"
class PhotoUniversity class UniversityPhoto
class Courses class Courses
class SpecialOffer class SpecialOffer
class OtherStuff class OtherStuff
...@@ -36,15 +36,15 @@ package UniversityModule{ ...@@ -36,15 +36,15 @@ package UniversityModule{
SemestersDates -up-|> BasicModuleCopyUniversity SemestersDates -up-|> BasicModuleCopyUniversity
UniversityInfo -up-|> BasicModuleCopyUniversity UniversityInfo -up-|> BasicModuleCopyUniversity
PhotoUniversity -left-|> PhotoCopyUniversity UniversityPhoto -left-|> PhotoCopyUniversity
UniversityScholarship -right-|> ScholarShipCopyUniversity UniversityScholarship -right-|> ScholarShipCopyUniversity
class UniversityVirtualCopy as "University" < copy for\n cleaner UML> #lightgrey class UniversityVirtualCopy as "University" < copy for\n cleaner UML> #lightgrey
CultureUniversity "1" -down[bold,#green]- "1" UniversityVirtualCopy 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 Courses "1" -down[bold,#green]- "1" UniversityVirtualCopy
OtherStuff "1" -down[bold,#green]- "1" UniversityVirtualCopy OtherStuff "1" -down[bold,#green]- "1" UniversityVirtualCopy
Insurances "1" -down[bold,#green]- "1" UniversityVirtualCopy Insurances "1" -down[bold,#green]- "1" UniversityVirtualCopy
......
from django.contrib import admin from django.contrib import admin
from reversion_compare.admin import CompareVersionAdmin 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 University, Campus, UniversityScholarship
from rex.models.university import UniversityInfo 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.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 = [ CLASSIC_MODELS = [
Country, Country,
City City,
Currency
] ]
VERSIONNED_MODELS = [ VERSIONNED_MODELS = [
...@@ -17,8 +27,13 @@ VERSIONNED_MODELS = [ ...@@ -17,8 +27,13 @@ VERSIONNED_MODELS = [
Campus, Campus,
UniversityScholarship, UniversityScholarship,
UniversityInfo, UniversityInfo,
SemestersDates, UniversitySemestersDates,
UniversityInsurance UniversityInsurance,
UniversityCulture,
UniversityCourses,
UniversityOtherStuff,
UniversitySpecialOffer,
UniversityPhoto,
] ]
for model in CLASSIC_MODELS: 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 .location import location # noqa: F401
from .university import university # 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 .basicModule import BasicModule, BasicModuleSerializer # noqa: F401
from .scholarship import Scholarship # noqa: F401 from .scholarship import Scholarship # noqa: F401
from .photo import Photo # noqa: F401
from django.db import models from django.db import models
from rex.models.tools import UsefullLinksField from rex.models.tools import UsefullLinksField
from rex.models.module import Module from rex.models.module import VersionnedModule, VersionnedModuleSerializer
from rest_framework import serializers
class BasicModule(Module): class BasicModule(VersionnedModule):
comment = models.TextField(blank=True) comment = models.TextField(blank=True)
usefull_links = UsefullLinksField(blank=True) usefull_links = UsefullLinksField(blank=True)
...@@ -13,16 +12,8 @@ class BasicModule(Module): ...@@ -13,16 +12,8 @@ class BasicModule(Module):
abstract = True abstract = True
class BasicModuleSerializer(serializers.ModelSerializer): class BasicModuleSerializer(VersionnedModuleSerializer):
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 = BasicModule 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 django.db import models
from reversion.models import Version from reversion.models import Version
from rest_framework import serializers
class Module(models.Model): class VersionnedModule(models.Model):
def modified_date(self): def modified_date(self):
try: try:
...@@ -23,6 +24,12 @@ class Module(models.Model): ...@@ -23,6 +24,12 @@ class Module(models.Model):
abstract = True abstract = True
""" class VersionnedModuleSerializer(serializers.ModelSerializer):
API RELATED STUFF BELLOW 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 ...@@ -3,5 +3,11 @@ from .campus import Campus, CampusViewSet, CampusSerializer # noqa: F401
from .universityAPI import UniversitySerializer, UniversityViewSet # noqa: F401 from .universityAPI import UniversitySerializer, UniversityViewSet # noqa: F401
from .universityScholarship import UniversityScholarship, UniversityScholarshipViewSet # noqa: F401 from .universityScholarship import UniversityScholarship, UniversityScholarshipViewSet # noqa: F401
from .universityInfo import UniversityInfo, UniversityInfoViewSet # noqa: F401 from .universityInfo import UniversityInfo, UniversityInfoViewSet # noqa: F401
from .semestersDates import SemestersDates, SemestersDatesViewSet # noqa: F401 from .universitySemestersDates import UniversitySemestersDates, UniversitySemestersDatesViewSet # noqa: F401
from .basicModulesUniversity import UniversityInsurance, UniversityInsuranceViewSet # 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 django.db import models
from rex.models.module import Module from rex.models.module import VersionnedModule
from rex.utils.friendly_path import friendly_path from rex.utils.friendly_path import friendly_path
path_and_rename = friendly_path("uploads/universities/logos/", 'name') path_and_rename = friendly_path("uploads/universities/logos/", 'name')
class University(Module): class University(VersionnedModule):
""" """
Model storing information about universities 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
#####################
#####################