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

Merge branch 'fusion_campus' into 'master'

Campus handling reformat

See merge request chehabfl/outgoing_rex!10
parents ef93ef29 f43f9776
Pipeline #26290 passed with stages
in 1 minute and 50 seconds
......@@ -16,8 +16,8 @@ package AbstractModels #lightgrey{
abstract class ScholarShip{
+ type : string
+ amount_min : float {}
+ amount_max : float {}
+ amount_min : float {currency}
+ amount_max : float {currency}
}
abstract class Photo{
......@@ -26,39 +26,9 @@ package AbstractModels #lightgrey{
+ description : MD
}
BasicModule -up-|> Module
BasicModule -left-|> Module
Photo -right-|> Module
ScholarShip -right-|> 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
ScholarShip -left-|> BasicModule
}
CultureAndStudentLife -down- Campus
Accomodation -down- Campus
Transport -down- Campus
@enduml
\ No newline at end of file
@startuml
!include AbstractModules.pu
!include Core.pu
!include UniversityModules.pu
!include CountryModules.pu
!include AbstractModules.pu
!include Campus.pu
!include IndiFunctions.pu
@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 {
University "1" .right. "1" City
note on link #white
This link is acheived
through the main campus module
through the campus module
(where is_main = true)
end note
abstract class CampusCopy1 as "Campus" #red
class MainCampus
MainCampus -|> CampusCopy1
MainCampus "1" -[bold,#green]up- "1" University
Class Offer {
+ nb_seats_offered : int
}
......
......@@ -4,6 +4,7 @@ TARGET=\
generated/UniversityModules.svg \
generated/CountryModules.svg \
generated/AbstractModules.svg \
generated/Campus.svg \
generated/IndiFunctions.svg
......
......@@ -8,16 +8,13 @@ package UniversityModule{
abstract class PhotoCopyUniversity as "Photo" #red
abstract class BasicModuleCopyUniversity as "BasicModule" #red
abstract class ScholarShipCopyUniversity as "Scholarship" #red
abstract class CampusCopyUniversity as "Campus" #red
class CultureUniversity as "Culture"
class TransportUniversity
class PhotoUniversity
class ScholarshipUniversity
class Courses
class SpecialOffer
class OtherStuff
class OtherCampus
class SemesterDate{
+ autumn_begin : date
......@@ -34,15 +31,12 @@ package UniversityModule{
}
CultureUniversity -up-|> BasicModuleCopyUniversity
TransportUniversity -up-|> BasicModuleCopyUniversity
Courses -up-|> BasicModuleCopyUniversity
SpecialOffer -up-|> BasicModuleCopyUniversity
OtherStuff -up-|> BasicModuleCopyUniversity
SemesterDate -up-|> BasicModuleCopyUniversity
UniversityInfo -up-|> BasicModuleCopyUniversity
OtherCampus -up-|> CampusCopyUniversity
PhotoUniversity -left-|> PhotoCopyUniversity
ScholarshipUniversity -right-|> ScholarShipCopyUniversity
......@@ -51,16 +45,14 @@ package UniversityModule{
CultureUniversity "1" -down[bold,#green]- "1" UniversityModules
TransportUniversity "1" -down[bold,#green]- "1" UniversityModules
PhotoUniversity "1" -right[bold,#green]- "1" UniversityModules
Courses "1" -right[bold,#green]- "1" UniversityModules
OtherStuff "1" -right[bold,#green]- "1" UniversityModules
SpecialOffer "1" -right[bold,#green]- "1" UniversityModules
UniversityInfo "1" -right[bold,#green]- "1" UniversityModules
SemesterDate "1" -right[bold,#green]- "1" UniversityModules
Courses "1" -down[bold,#green]- "1" UniversityModules
OtherStuff "1" -down[bold,#green]- "1" UniversityModules
SpecialOffer "1" -down[bold,#green]- "1" UniversityModules
UniversityInfo "1" -down[bold,#green]- "1" UniversityModules
SemesterDate "1" -down[bold,#green]- "1" UniversityModules
ScholarshipUniversity "*" -left- "1" UniversityModules
OtherCampus "*" -left- "1" UniversityModules
}
UniversityModules -down[bold,#green]- University
......
......@@ -9,6 +9,7 @@ Vue complète :
Vue plus précise :
![Core](UML/generated/Core.svg)
![AbstractModules](UML/generated/UniversityModules.svg)
![Architecture](UML/generated/Campus.svg)
![Architecture](UML/generated/CountryModules.svg)
![Architecture](UML/generated/AbstractModules.svg)
![Architecture](UML/generated/IndiFunctions.svg)
\ No newline at end of file
from django.contrib import admin
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
......@@ -9,4 +9,4 @@ admin.site.register(Country)
admin.site.register(City)
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
from django.db import migrations, models
......@@ -14,6 +14,17 @@ class Migration(migrations.Migration):
]
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(
name='City',
fields=[
......@@ -37,20 +48,6 @@ class Migration(migrations.Migration):
('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(
name='University',
fields=[
......@@ -58,12 +55,29 @@ class Migration(migrations.Migration):
('name', models.CharField(max_length=200)),
('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'))),
('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(
model_name='city',
name='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 .campus import MainCampus, MainCampusViewSet # noqa: F401
from .university import University # noqa: F401
from .campus import Campus, CampusViewSet, CampusSerializer # noqa: F401
from .universityAPI import UniversitySerializer, UniversityViewSet # noqa: F401
from django.db import models
from rex.models.module import Module
from rex.models.location import City
from rex.models.university import University
from django.core.validators import MinValueValidator, MaxValueValidator
from rest_framework import serializers, viewsets, permissions
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)
comment = models.TextField(null=True, blank=True)
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(
max_digits=10,
......@@ -28,16 +36,10 @@ class Campus(Module):
return {'lat': self.lat, 'lon': self.lon}
class Meta:
abstract = True
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é."
unique_together = ('is_main_campus', 'university')
class MainCampusSerializer(serializers.ModelSerializer):
class CampusSerializer(serializers.ModelSerializer):
modified_by = serializers.SerializerMethodField()
modified_date = serializers.SerializerMethodField()
......@@ -48,11 +50,13 @@ class MainCampusSerializer(serializers.ModelSerializer):
return obj.modified_date()
class Meta:
model = MainCampus
fields = ('lat', 'lon', 'name', 'city', 'modified_by', 'modified_date', 'id')
model = Campus
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,)
queryset = MainCampus.objects.all() # pylint: disable=E1101
serializer_class = MainCampusSerializer
queryset = Campus.objects.all() # pylint: disable=E1101
serializer_class = CampusSerializer
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.models.university.campus import MainCampus
path_and_rename = friendly_path("uploads/universities/logos/", 'name')
class University(models.Model):
class University(Module):
"""
Model storing information about universities
"""
......@@ -15,21 +13,7 @@ class University(models.Model):
acronym = models.CharField(max_length=20, null=True, blank=True)
logo = models.ImageField(upload_to=path_and_rename, max_length=250,
default='path/to/my/default/image.jpg') # TODO CHANGE !
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')
website = models.URLField(null=True)
class UniversityViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
queryset = University.objects.all() # pylint: disable=E1101
serializer_class = UniversitySerializer
# Rest API related stuff are in universityAPI.py to prevent circular depedencies
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 @@
var universities_markers = L.markerClusterGroup();
{% for univ in universities %}
L.marker([{{ univ.loc.lat }}, {{ univ.loc.lon }}]).addTo(universities_markers)
.bindPopup("<b>{{ univ.name }}</b>");
{% for camp in campus %}
L.marker([{{ camp.lat }}, {{ camp.lon }}]).addTo(universities_markers)
.bindPopup("<b>{{ camp.university.name }}</b>");
{% endfor %}
......
......@@ -2,7 +2,7 @@ from django.conf.urls import url, include
from rex import views
from rest_framework import routers
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
......@@ -15,7 +15,7 @@ urlpatterns = [
router = routers.DefaultRouter()
router.register(r'country', CountryViewSet)
router.register(r'city', CityViewSet)
router.register(r'main-campus', MainCampusViewSet)
router.register(r'campus', CampusViewSet)
router.register(r'university', UniversityViewSet)
urlpatterns += [url(r'^api/', include(router.urls))]
......@@ -61,15 +61,17 @@ def insert_city(city_name, country):
return inserted_city_cc[city_name + country]
def insert_main_campus(name, city_id, lat, lon):
address = api_address + "/main-campus/"
data = {'name': name, 'city': city_id, 'lat': lat, 'lon': lon}
def insert_university(name):
address = api_address + "/university/"
data = {'name': name}
return make_post(address, data)
def insert_university(name, main_campus_id):
address = api_address + "/university/"
data = {'name': name, 'main_campus': main_campus_id}
def insert_main_campus(name, city_id, univ_id, lat, lon):
address = api_address + "/campus/"
data = {'name': "Campus " + name, 'city': city_id, 'lat': lat,
'lon': lon, 'is_main_campus': True,
'university': univ_id}
return make_post(address, data)
......@@ -78,5 +80,5 @@ for index, row in data.iterrows():
lat = round(float(lat), 6)
lon = round(float(lon), 6)
city_id = insert_city(city, country)
m_c_id = insert_main_campus(univ, city_id, lat, lon)
insert_university(univ, m_c_id)
univ_id = insert_university(univ)
m_c_id = insert_main_campus(univ, city_id, univ_id, lat, lon)
from django.shortcuts import render
from rex.models.university import University
from rex.models.university import Campus
def home(request):
universities = University.objects.all()
for univ in universities:
univ.loc = univ.location()
return render(request, 'rex/home.html', {'universities': universities})
campus = Campus.objects.filter(is_main_campus=True).select_related()
return render(request, 'rex/home.html', {'campus': campus})
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