Commit 3a5a0f12 authored by Florent Chehab's avatar Florent Chehab
Browse files

Merge branch 'fusion_campus' into 'master'

Campus handling reformat

See merge request chehabfl/outgoing_rex!10
parents ef93ef29 f43f9776
...@@ -16,8 +16,8 @@ package AbstractModels #lightgrey{ ...@@ -16,8 +16,8 @@ package AbstractModels #lightgrey{
abstract class ScholarShip{ abstract class ScholarShip{
+ type : string + type : string
+ amount_min : float {} + amount_min : float {currency}
+ amount_max : float {} + amount_max : float {currency}
} }
abstract class Photo{ abstract class Photo{
...@@ -26,39 +26,9 @@ package AbstractModels #lightgrey{ ...@@ -26,39 +26,9 @@ package AbstractModels #lightgrey{
+ description : MD + description : MD
} }
BasicModule -up-|> Module BasicModule -left-|> Module
Photo -right-|> Module Photo -right-|> Module
ScholarShip -right-|> BasicModule ScholarShip -left-|> BasicModule
abstract class Campus{
+ name : string
+ Comment : MD
+ longitude : float
+ latitude : float
}
Campus -left|> Module
class CityCopy1 as "City" #red
Campus "*" -right[bold,#green]- "1" CityCopy1
}
package CampusExtra {
abstract class BasicModuleCopyCampusExtra as "BasicModule" #red
class CultureAndStudentLife
class Accomodation
class Transport
CultureAndStudentLife -up-|> BasicModuleCopyCampusExtra
Accomodation -up-|> BasicModuleCopyCampusExtra
Transport -up-|> BasicModuleCopyCampusExtra
} }
CultureAndStudentLife -down- Campus
Accomodation -down- Campus
Transport -down- Campus
@enduml @enduml
\ No newline at end of file
@startuml @startuml
!include AbstractModules.pu
!include Core.pu !include Core.pu
!include UniversityModules.pu !include UniversityModules.pu
!include CountryModules.pu !include CountryModules.pu
!include AbstractModules.pu !include Campus.pu
!include IndiFunctions.pu !include IndiFunctions.pu
@enduml @enduml
@startuml
package Campus {
abstract class Campus{
+ is_main_campus : bool
+ name : string
+ Comment : MD
+ longitude : float
+ latitude : float
}
class CityCopy1 as "City" #red
Campus "*" -left[bold,#green]- "1" CityCopy1
abstract class ModuleCopyCampusExtra as "Module" #red
Campus -down|> ModuleCopyCampusExtra
abstract class BasicModuleCopyCampusExtra as "BasicModule" #red
class CultureAndStudentLife
class Accomodation
class Transport
CultureAndStudentLife -up-|> BasicModuleCopyCampusExtra
Accomodation -up-|> BasicModuleCopyCampusExtra
Transport -up-|> BasicModuleCopyCampusExtra
CultureAndStudentLife -- Campus
Accomodation -- Campus
Transport -- Campus
}
Campus "1..n" -- "1" University
@enduml
\ No newline at end of file
...@@ -41,18 +41,10 @@ class University #wheat { ...@@ -41,18 +41,10 @@ class University #wheat {
University "1" .right. "1" City University "1" .right. "1" City
note on link #white note on link #white
This link is acheived This link is acheived
through the main campus module through the campus module
(where is_main = true)
end note end note
abstract class CampusCopy1 as "Campus" #red
class MainCampus
MainCampus -|> CampusCopy1
MainCampus "1" -[bold,#green]up- "1" University
Class Offer { Class Offer {
+ nb_seats_offered : int + nb_seats_offered : int
} }
......
...@@ -4,6 +4,7 @@ TARGET=\ ...@@ -4,6 +4,7 @@ TARGET=\
generated/UniversityModules.svg \ generated/UniversityModules.svg \
generated/CountryModules.svg \ generated/CountryModules.svg \
generated/AbstractModules.svg \ generated/AbstractModules.svg \
generated/Campus.svg \
generated/IndiFunctions.svg generated/IndiFunctions.svg
......
...@@ -8,16 +8,13 @@ package UniversityModule{ ...@@ -8,16 +8,13 @@ package UniversityModule{
abstract class PhotoCopyUniversity as "Photo" #red abstract class PhotoCopyUniversity as "Photo" #red
abstract class BasicModuleCopyUniversity as "BasicModule" #red abstract class BasicModuleCopyUniversity as "BasicModule" #red
abstract class ScholarShipCopyUniversity as "Scholarship" #red abstract class ScholarShipCopyUniversity as "Scholarship" #red
abstract class CampusCopyUniversity as "Campus" #red
class CultureUniversity as "Culture" class CultureUniversity as "Culture"
class TransportUniversity
class PhotoUniversity class PhotoUniversity
class ScholarshipUniversity class ScholarshipUniversity
class Courses class Courses
class SpecialOffer class SpecialOffer
class OtherStuff class OtherStuff
class OtherCampus
class SemesterDate{ class SemesterDate{
+ autumn_begin : date + autumn_begin : date
...@@ -34,15 +31,12 @@ package UniversityModule{ ...@@ -34,15 +31,12 @@ package UniversityModule{
} }
CultureUniversity -up-|> BasicModuleCopyUniversity CultureUniversity -up-|> BasicModuleCopyUniversity
TransportUniversity -up-|> BasicModuleCopyUniversity
Courses -up-|> BasicModuleCopyUniversity Courses -up-|> BasicModuleCopyUniversity
SpecialOffer -up-|> BasicModuleCopyUniversity SpecialOffer -up-|> BasicModuleCopyUniversity
OtherStuff -up-|> BasicModuleCopyUniversity OtherStuff -up-|> BasicModuleCopyUniversity
SemesterDate -up-|> BasicModuleCopyUniversity SemesterDate -up-|> BasicModuleCopyUniversity
UniversityInfo -up-|> BasicModuleCopyUniversity UniversityInfo -up-|> BasicModuleCopyUniversity
OtherCampus -up-|> CampusCopyUniversity
PhotoUniversity -left-|> PhotoCopyUniversity PhotoUniversity -left-|> PhotoCopyUniversity
ScholarshipUniversity -right-|> ScholarShipCopyUniversity ScholarshipUniversity -right-|> ScholarShipCopyUniversity
...@@ -51,16 +45,14 @@ package UniversityModule{ ...@@ -51,16 +45,14 @@ package UniversityModule{
CultureUniversity "1" -down[bold,#green]- "1" UniversityModules CultureUniversity "1" -down[bold,#green]- "1" UniversityModules
TransportUniversity "1" -down[bold,#green]- "1" UniversityModules
PhotoUniversity "1" -right[bold,#green]- "1" UniversityModules PhotoUniversity "1" -right[bold,#green]- "1" UniversityModules
Courses "1" -right[bold,#green]- "1" UniversityModules Courses "1" -down[bold,#green]- "1" UniversityModules
OtherStuff "1" -right[bold,#green]- "1" UniversityModules OtherStuff "1" -down[bold,#green]- "1" UniversityModules
SpecialOffer "1" -right[bold,#green]- "1" UniversityModules SpecialOffer "1" -down[bold,#green]- "1" UniversityModules
UniversityInfo "1" -right[bold,#green]- "1" UniversityModules UniversityInfo "1" -down[bold,#green]- "1" UniversityModules
SemesterDate "1" -right[bold,#green]- "1" UniversityModules SemesterDate "1" -down[bold,#green]- "1" UniversityModules
ScholarshipUniversity "*" -left- "1" UniversityModules ScholarshipUniversity "*" -left- "1" UniversityModules
OtherCampus "*" -left- "1" UniversityModules
} }
UniversityModules -down[bold,#green]- University UniversityModules -down[bold,#green]- University
......
...@@ -9,6 +9,7 @@ Vue complète : ...@@ -9,6 +9,7 @@ Vue complète :
Vue plus précise : Vue plus précise :
![Core](UML/generated/Core.svg) ![Core](UML/generated/Core.svg)
![AbstractModules](UML/generated/UniversityModules.svg) ![AbstractModules](UML/generated/UniversityModules.svg)
![Architecture](UML/generated/Campus.svg)
![Architecture](UML/generated/CountryModules.svg) ![Architecture](UML/generated/CountryModules.svg)
![Architecture](UML/generated/AbstractModules.svg) ![Architecture](UML/generated/AbstractModules.svg)
![Architecture](UML/generated/IndiFunctions.svg) ![Architecture](UML/generated/IndiFunctions.svg)
\ No newline at end of file
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.university import University, MainCampus from rex.models.university import University, Campus
from rex.models.location import Country, City from rex.models.location import Country, City
...@@ -9,4 +9,4 @@ admin.site.register(Country) ...@@ -9,4 +9,4 @@ admin.site.register(Country)
admin.site.register(City) admin.site.register(City)
admin.site.register(University, CompareVersionAdmin) admin.site.register(University, CompareVersionAdmin)
admin.site.register(MainCampus, CompareVersionAdmin) admin.site.register(Campus, CompareVersionAdmin)
# Generated by Django 2.0.3 on 2018-08-18 08:44 # Generated by Django 2.0.3 on 2018-08-19 16:39
import django.core.validators import django.core.validators
from django.db import migrations, models from django.db import migrations, models
...@@ -14,6 +14,17 @@ class Migration(migrations.Migration): ...@@ -14,6 +14,17 @@ class Migration(migrations.Migration):
] ]
operations = [ operations = [
migrations.CreateModel(
name='Campus',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('is_main_campus', models.BooleanField()),
('name', models.CharField(max_length=200, null=True)),
('comment', models.TextField(blank=True, null=True)),
('lat', models.DecimalField(decimal_places=6, max_digits=10, validators=[django.core.validators.MinValueValidator(-85.05112878), django.core.validators.MaxValueValidator(85.05112878)])),
('lon', models.DecimalField(decimal_places=6, max_digits=10, validators=[django.core.validators.MinValueValidator(-180), django.core.validators.MaxValueValidator(180)])),
],
),
migrations.CreateModel( migrations.CreateModel(
name='City', name='City',
fields=[ fields=[
...@@ -37,20 +48,6 @@ class Migration(migrations.Migration): ...@@ -37,20 +48,6 @@ class Migration(migrations.Migration):
('intermediate_region_un_code', models.CharField(blank=True, max_length=3, null=True)), ('intermediate_region_un_code', models.CharField(blank=True, max_length=3, null=True)),
], ],
), ),
migrations.CreateModel(
name='MainCampus',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200, null=True)),
('comment', models.TextField(blank=True, null=True)),
('lat', models.DecimalField(decimal_places=6, max_digits=10, validators=[django.core.validators.MinValueValidator(-85.05112878), django.core.validators.MaxValueValidator(85.05112878)])),
('lon', models.DecimalField(decimal_places=6, max_digits=10, validators=[django.core.validators.MinValueValidator(-180), django.core.validators.MaxValueValidator(180)])),
('city', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='rex.City')),
],
options={
'abstract': False,
},
),
migrations.CreateModel( migrations.CreateModel(
name='University', name='University',
fields=[ fields=[
...@@ -58,12 +55,29 @@ class Migration(migrations.Migration): ...@@ -58,12 +55,29 @@ class Migration(migrations.Migration):
('name', models.CharField(max_length=200)), ('name', models.CharField(max_length=200)),
('acronym', models.CharField(blank=True, max_length=20, null=True)), ('acronym', models.CharField(blank=True, max_length=20, null=True)),
('logo', models.ImageField(default='path/to/my/default/image.jpg', max_length=250, upload_to=rex.utils.friendly_path.friendly_path('uploads/universities/logos/', 'name'))), ('logo', models.ImageField(default='path/to/my/default/image.jpg', max_length=250, upload_to=rex.utils.friendly_path.friendly_path('uploads/universities/logos/', 'name'))),
('main_campus', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, related_name='main_campus_of', to='rex.MainCampus')), ('website', models.URLField(null=True)),
], ],
options={
'abstract': False,
},
), ),
migrations.AddField( migrations.AddField(
model_name='city', model_name='city',
name='country', name='country',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='rex.Country'), field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='rex.Country'),
), ),
migrations.AddField(
model_name='campus',
name='city',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='rex.City'),
),
migrations.AddField(
model_name='campus',
name='university',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='univCampus', to='rex.University'),
),
migrations.AlterUniqueTogether(
name='campus',
unique_together={('is_main_campus', 'university')},
),
] ]
from .university import University, UniversityViewSet # noqa: F401 from .university import University # noqa: F401
from .campus import MainCampus, MainCampusViewSet # noqa: F401 from .campus import Campus, CampusViewSet, CampusSerializer # noqa: F401
from .universityAPI import UniversitySerializer, UniversityViewSet # noqa: F401
from django.db import models from django.db import models
from rex.models.module import Module from rex.models.module import Module
from rex.models.location import City from rex.models.location import City
from rex.models.university import University
from django.core.validators import MinValueValidator, MaxValueValidator from django.core.validators import MinValueValidator, MaxValueValidator
from rest_framework import serializers, viewsets, permissions from rest_framework import serializers, viewsets, permissions
class Campus(Module): class Campus(Module):
module_icon = "You forget to override the icon in the sub-class : I know"
module_name = "Campus principal"
module_description = "Campus de l'université."
is_main_campus = models.BooleanField(null=False)
name = models.CharField(max_length=200, null=True) name = models.CharField(max_length=200, null=True)
comment = models.TextField(null=True, blank=True) comment = models.TextField(null=True, blank=True)
city = models.ForeignKey(City, on_delete=models.PROTECT, null=False) city = models.ForeignKey(City, on_delete=models.PROTECT, null=False)
university = models.ForeignKey(
University, on_delete=models.PROTECT, null=False, related_name="univCampus")
lat = models.DecimalField( lat = models.DecimalField(
max_digits=10, max_digits=10,
...@@ -28,16 +36,10 @@ class Campus(Module): ...@@ -28,16 +36,10 @@ class Campus(Module):
return {'lat': self.lat, 'lon': self.lon} return {'lat': self.lat, 'lon': self.lon}
class Meta: class Meta:
abstract = True unique_together = ('is_main_campus', 'university')
class MainCampus(Campus):
module_icon = "You forget to override the icon in the sub-class : I know"
module_name = "Campus principal"
module_description = "Campus principal de l'université."
class MainCampusSerializer(serializers.ModelSerializer): class CampusSerializer(serializers.ModelSerializer):
modified_by = serializers.SerializerMethodField() modified_by = serializers.SerializerMethodField()
modified_date = serializers.SerializerMethodField() modified_date = serializers.SerializerMethodField()
...@@ -48,11 +50,13 @@ class MainCampusSerializer(serializers.ModelSerializer): ...@@ -48,11 +50,13 @@ class MainCampusSerializer(serializers.ModelSerializer):
return obj.modified_date() return obj.modified_date()
class Meta: class Meta:
model = MainCampus model = Campus
fields = ('lat', 'lon', 'name', 'city', 'modified_by', 'modified_date', 'id') fields = ('is_main_campus', 'university', 'lat', 'lon',
'name', 'city', 'modified_by', 'modified_date',
'id')
class MainCampusViewSet(viewsets.ModelViewSet): # TODO switch to dict class CampusViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,) permission_classes = (permissions.DjangoModelPermissions,)
queryset = MainCampus.objects.all() # pylint: disable=E1101 queryset = Campus.objects.all() # pylint: disable=E1101
serializer_class = MainCampusSerializer serializer_class = CampusSerializer
from django.db import models from django.db import models
from rest_framework import serializers, viewsets, permissions from rex.models.module import Module
from rex.utils.friendly_path import friendly_path from rex.utils.friendly_path import friendly_path
from rex.models.university.campus import MainCampus
path_and_rename = friendly_path("uploads/universities/logos/", 'name') path_and_rename = friendly_path("uploads/universities/logos/", 'name')
class University(models.Model): class University(Module):
""" """
Model storing information about universities Model storing information about universities
""" """
...@@ -15,21 +13,7 @@ class University(models.Model): ...@@ -15,21 +13,7 @@ class University(models.Model):
acronym = models.CharField(max_length=20, null=True, blank=True) acronym = models.CharField(max_length=20, null=True, blank=True)
logo = models.ImageField(upload_to=path_and_rename, max_length=250, logo = models.ImageField(upload_to=path_and_rename, max_length=250,
default='path/to/my/default/image.jpg') # TODO CHANGE ! default='path/to/my/default/image.jpg') # TODO CHANGE !
website = models.URLField(null=True)
main_campus = models.OneToOneField(
MainCampus, on_delete=models.PROTECT, related_name='main_campus_of')
def location(self):
return self.main_campus.location() # pylint: disable=E1101
class UniversitySerializer(serializers.ModelSerializer):
class Meta:
model = University
fields = ('name', 'acronym', 'logo', 'main_campus', 'id')
class UniversityViewSet(viewsets.ModelViewSet): # TODO switch to dict # Rest API related stuff are in universityAPI.py to prevent circular depedencies
permission_classes = (permissions.DjangoModelPermissions,)
queryset = University.objects.all() # pylint: disable=E1101
serializer_class = UniversitySerializer
from rex.models.university import University
from rest_framework import serializers, viewsets, permissions
from rex.models.university.campus import CampusSerializer
class UniversitySerializer(serializers.ModelSerializer):
univCampus = CampusSerializer(many=True, read_only=True)
class Meta:
model = University
fields = ('name', 'acronym', 'logo', 'id', 'univCampus')
class UniversityViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
queryset = University.objects.all() # pylint: disable=E1101
serializer_class = UniversitySerializer
...@@ -53,9 +53,9 @@ ...@@ -53,9 +53,9 @@
var universities_markers = L.markerClusterGroup(); var universities_markers = L.markerClusterGroup();
{% for univ in universities %} {% for camp in campus %}
L.marker([{{ univ.loc.lat }}, {{ univ.loc.lon }}]).addTo(universities_markers) L.marker([{{ camp.lat }}, {{ camp.lon }}]).addTo(universities_markers)
.bindPopup("<b>{{ univ.name }}</b>"); .bindPopup("<b>{{ camp.university.name }}</b>");
{% endfor %} {% endfor %}
......
...@@ -2,7 +2,7 @@ from django.conf.urls import url, include ...@@ -2,7 +2,7 @@ from django.conf.urls import url, include
from rex import views from rex import views
from rest_framework import routers from rest_framework import routers
from rex.models.location import CountryViewSet, CityViewSet from rex.models.location import CountryViewSet, CityViewSet
from rex.models.university import MainCampusViewSet, UniversityViewSet from rex.models.university import CampusViewSet, UniversityViewSet
from rest_framework.documentation import include_docs_urls from rest_framework.documentation import include_docs_urls
...@@ -15,7 +15,7 @@ urlpatterns = [ ...@@ -15,7 +15,7 @@ urlpatterns = [
router = routers.DefaultRouter() router = routers.DefaultRouter()
router.register(r'country', CountryViewSet) router.register(r'country', CountryViewSet)
router.register(r'city', CityViewSet) router.register(r'city', CityViewSet)
router.register(r'main-campus', MainCampusViewSet) router.register(r'campus', CampusViewSet)
router.register(r'university', UniversityViewSet) router.register(r'university', UniversityViewSet)
urlpatterns += [url(r'^api/', include(router.urls))] urlpatterns += [url(r'^api/', include(router.urls))]
...@@ -61,15 +61,17 @@ def insert_city(city_name, country): ...@@ -61,15 +61,17 @@ def insert_city(city_name, country):
return inserted_city_cc[city_name + country] return inserted_city_cc[city_name + country]
def insert_main_campus(name, city_id, lat, lon): def insert_university(name):
address = api_address + "/main-campus/" address = api_address + "/university/"
data = {'name': name, 'city': city_id, 'lat': lat, 'lon': lon} data = {'name': name}
return make_post(address, data) return make_post(address, data)
def insert_university(name, main_campus_id): def insert_main_campus(name, city_id, univ_id, lat, lon):
address = api_address + "/university/" address = api_address + "/campus/"
data = {'name': name, 'main_campus': main_campus_id} data = {'name': "Campus " + name, 'city': city_id, 'lat': lat,
'lon': lon, 'is_main_campus': True,
'university': univ_id}
return make_post(address, data) return make_post(address, data)