Commit f9659160 authored by Florent Chehab's avatar Florent Chehab

updating schema in progress

parent 947ab3b6
Pipeline #42339 canceled with stages
in 26 seconds
......@@ -31,9 +31,9 @@ class LoadUniversities(LoadGeneric):
city = City(name=row["city"], country=country)
city.save()
self.add_info_and_save(city, self.admin)
# TODO load utc partner
univ = University.objects.update_or_create(
utc_id=row["utc_id"],
pk=row["utc_id"], # Not perfect but should do the trick
defaults={
"name": row["university"],
"acronym": row["acronym"],
......
......@@ -78,7 +78,7 @@ class LoadUniversityEx(LoadGeneric):
importance_level="++",
)
self.add_info_and_save(univ_tag_1, self.admin)
# todo finish switch to new schema
exchange1 = Exchange.objects.create(
utc_univ_id=EPFL,
utc_departure_id=1,
......@@ -96,7 +96,6 @@ class LoadUniversityEx(LoadGeneric):
)
ExchangeFeedback.objects.create(
university=EPFL,
exchange=exchange1,
general_comment="Very good",
academical_level_appreciation=5,
......@@ -121,7 +120,6 @@ class LoadUniversityEx(LoadGeneric):
)
ExchangeFeedback.objects.create(
university=EPFL,
exchange=exchange2,
general_comment="Very good trop bien",
academical_level_appreciation=4,
......
......@@ -2,13 +2,13 @@ from django.db import models
from backend_app.models.abstract.base import BaseModel
from backend_app.models.shared import SEMESTER_OPTIONS
from backend_app.models.university import University
from backend_app.models.utcPartner import UtcPartner
from base_app.models import User
class Exchange(BaseModel):
# This model should be filled with data from the ENT
utc_univ_id = models.ForeignKey(University, on_delete=models.PROTECT)
utc_partner = models.ForeignKey(UtcPartner, on_delete=models.PROTECT)
utc_departure_id = models.IntegerField()
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
......
from django.db import models
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from backend_app.models.abstract.essentialModule import (
EssentialModule,
......@@ -8,11 +8,9 @@ from backend_app.models.abstract.essentialModule import (
)
from backend_app.models.exchange import Exchange
from backend_app.serializers import ExchangeSerializer
from backend_app.models.university import University
class ExchangeFeedback(EssentialModule):
university = models.ForeignKey(University, on_delete=models.PROTECT, default=0)
exchange = models.OneToOneField(
Exchange,
on_delete=models.CASCADE,
......@@ -47,4 +45,4 @@ class ExchangeFeedbackViewSet(EssentialModuleViewSet):
) # pylint: disable=E1101
serializer_class = ExchangeFeedbackSerializer
end_point_route = "exchangeFeedbacks"
filterset_fields = ("university",)
filterset_fields = ("exchange__utc_partner__university",)
......@@ -22,13 +22,11 @@ class University(EssentialModule):
validators=[PathExtensionValidator(settings.ALLOWED_PHOTOS_EXTENSION)],
)
website = models.URLField(default="", blank=True, max_length=300)
utc_id = models.IntegerField(unique=True)
class UniversitySerializer(EssentialModuleSerializer):
class Meta:
model = University
exclude = ("utc_id",)
class UniversityViewSet(EssentialModuleViewSet):
......
from django.db import models
from backend_app.models.abstract.base import BaseModel
from backend_app.models.university import University
class UtcPartner(BaseModel):
"""
Model that stores raw information from the UTC database regarding university partners.
Some universities in UTC database are present multiple times. To accommodate for this,
We store the data separetly and one REX-DRI university may link to multiple UTC partners.
"""
# fields mapping directly to those of UTC db
utc_id = models.IntegerField(primary_key=True)
univ_name = models.CharField(max_length=100)
address1 = models.CharField(max_length=250, null=True)
......@@ -12,3 +20,7 @@ class UtcPartner(BaseModel):
city = models.CharField(max_length=40, null=True)
country = models.CharField(max_length=50, null=True)
iso_code = models.CharField(max_length=50, null=True)
# field that will have to be added manually
university = models.ForeignKey(University, null=True, on_delete=models.PROTECT,
related_name="corresponding_utc_partners")
......@@ -30,7 +30,6 @@ from backend_app.models.recommendationList import (
RecommendationListViewSet,
RecommendationList,
)
from backend_app.models.specialty import SpecialtyViewSet
from backend_app.models.tag import TagViewSet
from backend_app.models.university import UniversityViewSet
from backend_app.models.universityDri import UniversityDriViewSet
......
......@@ -7,7 +7,6 @@ from backend_app.models.course import Course
from backend_app.models.currency import Currency
from backend_app.models.exchange import Exchange
from backend_app.models.offer import Offer
from backend_app.models.university import University
from backend_app.models.utcPartner import UtcPartner
from external_data.models import ExternalDataUpdateInfo
......@@ -67,9 +66,29 @@ class UtcData(object):
def update(cls):
logger.info("Updating UTC Data")
paged_data_walk("{}/universities".format(cls.UTC_API_ENDPOINT), cls.__import_utc_partner_data)
paged_data_walk("{}/openedDestinations".format(cls.UTC_API_ENDPOINT), cls.__import_opened_destinations)
paged_data_walk("{}/exchanges".format(cls.UTC_API_ENDPOINT), cls.__import_exchange_data)
paged_data_walk("{}/courses".format(cls.UTC_API_ENDPOINT), cls.__import_course_data)
paged_data_walk("{}/openedDestinations".format(cls.UTC_API_ENDPOINT), cls.__import_opened_dest_data)
@classmethod
def __import_utc_partner_data(cls, response_content):
logger.info("Importing university partners")
for univ in response_content:
logger.debug(univ["idEtab"])
UtcPartner.objects.update_or_create(
utc_id=univ["idEtab"],
defaults=dict(
univ_name=univ["nomEtab"],
address1=univ["adr1"],
address2=univ["adr2"],
zipcode=univ["codePostal"],
city=univ["ville"],
country=univ["pays"],
iso_code=univ["codeIso"]
)
)
@classmethod
def __import_exchange_data(cls, response_content):
......@@ -77,17 +96,12 @@ class UtcData(object):
for exchange in response_content:
partner_id = exchange['idEtab']
logger.info("Univ id: {}".format(partner_id))
try:
univ = University.objects.get(utc_id=partner_id)
except University.DoesNotExist:
univ = University.objects.create(utc_id=partner_id)
logger.debug("Univ id: {}".format(partner_id))
Exchange.objects.update_or_create(
utc_departure_id=exchange['idDepart'],
defaults=dict(
utc_univ_id=univ,
utc_partner=UtcPartner.objects.get(pk=partner_id),
semester=exchange["semestreDepart"][0],
year=exchange["semestreDepart"][1:],
duration=exchange["duree"],
......@@ -101,56 +115,7 @@ class UtcData(object):
)
@classmethod
def __import_course_data(cls, response_content):
logger.info("Importing courses data")
for course in response_content:
exchange = Exchange.objects.get_or_create(utc_departure_id=course["idDepart"])[0]
logger.info(course["idCours"])
Course.objects.update_or_create(
course_id=course["idCours"],
defaults=dict(
exchange=exchange,
utc_exchange_id=course["idDepart"],
code=course["code"],
title=course["titre"],
link=course["lien"],
nb_credit=course["ects"],
category=course["categorie"],
profile=course["profil"],
tsh_profile=course["categorieTsh"],
student_login=course["login"],
))
@classmethod
def __import_utc_partner_data(cls, response_content):
logger.info("Importing university partners")
for univ in response_content:
logger.info(univ["idEtab"])
UtcPartner.objects.update_or_create(
utc_id=univ["idEtab"],
defaults=dict(
univ_name=univ["nomEtab"],
address1=univ["adr1"],
address2=univ["adr2"],
zipcode=univ["codePostal"],
city=univ["ville"],
country=univ["pays"],
iso_code=univ["codeIso"]
)
)
for partner in UtcPartner.objects.all():
logger.info("Partenaire : " + str(partner.utc_id))
@classmethod
def __import_opened_dest_data(cls, response_content):
def __import_opened_destinations(cls, response_content):
logger.info("Importing the list of opened destinations")
for destination in response_content:
......@@ -159,7 +124,7 @@ class UtcData(object):
semester = destination["semestre"][:1]
year = destination["semestre"][1:]
utc_partner = UtcPartner.objects.get_or_create(utc_id=destination["idEtab"])[0]
utc_partner = UtcPartner.objects.get(pk=destination["idEtab"])
Offer.objects.update_or_create(
utc_partner=utc_partner,
......@@ -173,3 +138,27 @@ class UtcData(object):
specialties=destination["branches"]
)
)
@classmethod
def __import_course_data(cls, response_content):
logger.info("Importing courses data")
for course in response_content:
logger.debug(course["idCours"])
exchange = Exchange.objects.get(utc_departure_id=course["idDepart"])
Course.objects.update_or_create(
course_id=course["idCours"],
defaults=dict(
exchange=exchange,
utc_exchange_id=course["idDepart"],
code=course["code"],
title=course["titre"],
link=course["lien"],
nb_credit=course["ects"],
category=course["categorie"],
profile=course["profil"],
tsh_profile=course["categorieTsh"],
student_login=course["login"],
))
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