Commit 7fc417da authored by Florent Chehab's avatar Florent Chehab

SemesterDates Added

parent 97c6be13
......@@ -15,7 +15,7 @@ package UniversityModule{
class SpecialOffer
class OtherStuff
class SemesterDate{
class SemestersDates{
+ autumn_begin : date
+ autumn_end : date
+ spring_begin : date
......@@ -31,7 +31,7 @@ package UniversityModule{
Courses -up-|> BasicModuleCopyUniversity
SpecialOffer -up-|> BasicModuleCopyUniversity
OtherStuff -up-|> BasicModuleCopyUniversity
SemesterDate -up-|> BasicModuleCopyUniversity
SemestersDates -up-|> BasicModuleCopyUniversity
UniversityInfo -up-|> BasicModuleCopyUniversity
PhotoUniversity -left-|> PhotoCopyUniversity
......@@ -47,7 +47,7 @@ package UniversityModule{
OtherStuff "1" -down[bold,#green]- "1" UniversityVirtualCopy
SpecialOffer "1" -down[bold,#green]- "1" UniversityVirtualCopy
UniversityInfo "1" -down[bold,#green]- "1" UniversityVirtualCopy
SemesterDate "1" -down[bold,#green]- "1" UniversityVirtualCopy
SemestersDates "1" -down[bold,#green]- "1" UniversityVirtualCopy
UniversityScholarship "*" -left- "1" UniversityVirtualCopy
}
......
......@@ -3,6 +3,7 @@ from reversion_compare.admin import CompareVersionAdmin
from rex.models.university import University, Campus, UniversityScholarship
from rex.models.university import UniversityInfo
from rex.models.university import SemestersDates
from rex.models.location import Country, City
......@@ -13,3 +14,4 @@ admin.site.register(University, CompareVersionAdmin)
admin.site.register(Campus, CompareVersionAdmin)
admin.site.register(UniversityScholarship, CompareVersionAdmin)
admin.site.register(UniversityInfo, CompareVersionAdmin)
admin.site.register(SemestersDates, CompareVersionAdmin)
# Generated by Django 2.0.3 on 2018-08-20 16:23
from django.db import migrations, models
import django.db.models.deletion
import rex.models.tools.usefullLinksField
class Migration(migrations.Migration):
dependencies = [
('rex', '0008_auto_20180820_1752'),
]
operations = [
migrations.CreateModel(
name='SemestersDates',
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_semesters_dates', serialize=False, to='rex.University')),
('spring_begin', models.DateField(null=True)),
('spring_end', models.DateField(null=True)),
('autumn_begin', models.DateField(null=True)),
('autumn_end', models.DateField(null=True)),
],
options={
'abstract': False,
},
),
]
# Generated by Django 2.0.3 on 2018-08-20 16:30
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('rex', '0009_semestersdates'),
]
operations = [
migrations.AlterField(
model_name='semestersdates',
name='autumn_begin',
field=models.DateField(blank=True, null=True),
),
migrations.AlterField(
model_name='semestersdates',
name='autumn_end',
field=models.DateField(blank=True, null=True),
),
migrations.AlterField(
model_name='semestersdates',
name='spring_begin',
field=models.DateField(blank=True, null=True),
),
migrations.AlterField(
model_name='semestersdates',
name='spring_end',
field=models.DateField(blank=True, null=True),
),
]
......@@ -3,3 +3,4 @@ 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 django.db import models
from rex.models.module import BasicModule
from rex.models.university import University
from rest_framework import serializers, viewsets, permissions
def check_nones(val1, val2):
if val1 is None and val2 is not None:
raise serializers.ValidationError("Check your dates")
if val2 is None and val1 is not None:
raise serializers.ValidationError("Check your dates")
return val1 is None and val2 is None
class SemestersDates(BasicModule):
university = models.OneToOneField(
University, on_delete=models.CASCADE, related_name='university_semesters_dates', primary_key=True, null=False)
spring_begin = models.DateField(null=True, blank=True)
spring_end = models.DateField(null=True, blank=True)
autumn_begin = models.DateField(null=True, blank=True)
autumn_end = models.DateField(null=True, blank=True)
# Need custom validation
# TODO add tests
def clean(self, *args, **kwargs):
spring_ok = check_nones(self.spring_begin, self.spring_end)
autumn_ok = check_nones(self.autumn_begin, self.autumn_end)
if not spring_ok:
spring_ok = self.spring_begin < self.spring_end
if not autumn_ok:
autumn_ok = self.autumn_begin < self.autumn_end
# no check if spring_end < autumn_begin in case info is not available
if not (spring_ok and autumn_ok):
print("ici")
raise serializers.ValidationError("Check your dates !")
super(SemestersDates, self).clean(*args, **kwargs)
def save(self, *args, **kwargs):
self.full_clean()
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 Meta:
model = SemestersDates
fields = ('university', 'autumn_begin', 'autumn_end',
'spring_begin', 'spring_end', 'modified_by', 'modified_date')
class SemestersDatesViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
queryset = SemestersDates.objects.all() # pylint: disable=E1101
serializer_class = SemestersDatesSerializer
......@@ -7,6 +7,7 @@ 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.tools import CurrencyViewSet
from rest_framework.documentation import include_docs_urls
......@@ -24,6 +25,7 @@ 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'semesters_dates', SemestersDatesViewSet)
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