Commit 47ad5e0d authored by Segolene's avatar Segolene

Import opened destinations

parent 516e9ed5
Pipeline #41372 failed with stages
in 9 minutes and 36 seconds
# Generated by Django 2.1.7 on 2019-05-27 14:15
# Generated by Django 2.1.7 on 2019-05-30 16:25
import django.core.validators
from django.db import migrations, models
......@@ -17,11 +17,11 @@ class Migration(migrations.Migration):
fields=[
('utc_id', models.IntegerField(primary_key=True, serialize=False)),
('univ_name', models.CharField(max_length=100)),
('address1', models.CharField(max_length=250)),
('address2', models.CharField(max_length=250)),
('zipcode', models.CharField(max_length=15)),
('iso_code', models.CharField(max_length=50)),
('city', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='backend_app.City')),
('address1', models.CharField(max_length=250, null=True)),
('address2', models.CharField(max_length=250, null=True)),
('zipcode', models.CharField(max_length=15, null=True)),
('iso_code', models.CharField(max_length=50, null=True)),
('city', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='backend_app.City')),
],
options={
'abstract': False,
......@@ -39,6 +39,21 @@ class Migration(migrations.Migration):
model_name='offer',
name='university',
),
migrations.AddField(
model_name='offer',
name='commentary',
field=models.TextField(max_length=500, null=True),
),
migrations.AddField(
model_name='offer',
name='dual_degree',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='offer',
name='is_master_offered',
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name='coursefeedback',
name='adequation',
......@@ -54,6 +69,11 @@ class Migration(migrations.Migration):
name='working_dose',
field=models.IntegerField(default=0, validators=[django.core.validators.MinValueValidator(-5), django.core.validators.MaxValueValidator(5)]),
),
migrations.AlterField(
model_name='exchange',
name='student_minor',
field=models.CharField(max_length=7, null=True),
),
migrations.AlterField(
model_name='exchangefeedback',
name='academical_level_appreciation',
......
# Generated by Django 2.1.7 on 2019-05-27 14:47
# Generated by Django 2.1.7 on 2019-05-30 17:03
from django.db import migrations, models
......@@ -6,13 +6,18 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('backend_app', '0009_auto_20190527_1615'),
('backend_app', '0009_auto_20190530_1825'),
]
operations = [
migrations.AddField(
model_name='utcpartner',
name='country',
field=models.CharField(max_length=50, null=True),
),
migrations.AlterField(
model_name='exchange',
name='student_minor',
field=models.CharField(max_length=7, null=True),
model_name='utcpartner',
name='city',
field=models.CharField(max_length=40, null=True),
),
]
# Generated by Django 2.1.7 on 2019-05-27 15:50
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('backend_app', '0010_auto_20190527_1647'),
]
operations = [
migrations.AlterField(
model_name='utcpartner',
name='address1',
field=models.CharField(max_length=250, null=True),
),
migrations.AlterField(
model_name='utcpartner',
name='address2',
field=models.CharField(max_length=250, null=True),
),
migrations.AlterField(
model_name='utcpartner',
name='city',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='backend_app.City'),
),
migrations.AlterField(
model_name='utcpartner',
name='iso_code',
field=models.CharField(max_length=50, null=True),
),
migrations.AlterField(
model_name='utcpartner',
name='zipcode',
field=models.CharField(max_length=15, null=True),
),
]
......@@ -15,6 +15,10 @@ class Offer(BaseModel):
year = models.PositiveIntegerField(default=2018)
semester = models.CharField(max_length=2, choices=SEMESTER_OPTIONS, default="a")
commentary = models.TextField(max_length=500, null=True)
dual_degree = models.BooleanField(default=False)
is_master_offered = models.BooleanField(default=False)
nb_seats_offered = models.PositiveIntegerField()
# null => exchange not possible
nb_seats_offered_exchange = models.PositiveIntegerField(null=True)
......
......@@ -11,5 +11,6 @@ class UtcPartner(BaseModel):
address1 = models.CharField(max_length=250, null=True)
address2 = models.CharField(max_length=250, null=True)
zipcode = models.CharField(max_length=15, null=True)
city = models.ForeignKey(City, on_delete=models.PROTECT, null=True)
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)
......@@ -6,6 +6,7 @@ from backend_app.models.city import City
from backend_app.models.country import Country
from backend_app.models.exchange import Exchange
from backend_app.models.course import Course
from backend_app.models.offer import Offer
from backend_app.models.university import University
from backend_app.models.utcPartner import UtcPartner
from django.core.management.base import BaseCommand, CommandError
......@@ -19,6 +20,8 @@ class Command(BaseCommand):
def import_exchange_data(self, response):
print("#### Import des échanges ####")
for exchange in response:
try:
univ = University.objects.get(utc_id=exchange['idEtab'])
......@@ -41,19 +44,35 @@ class Command(BaseCommand):
"utc_allow_login": exchange["autorisationTransfertLogin"],
})
def import_utc_partner_data(self, response):
def import_course_data(self, response):
for univ in response:
print("#### Import des cours ####")
try:
country = Country.objects.get(name=univ["pays"].lower().capitalize())
except Country.DoesNotExist:
country = None
for course in response:
exchange = Exchange.objects.get_or_create(utc_departure_id=course["idDepart"])[0]
try:
city = City.objects.get(name=univ["ville"].lower().capitalize(), country=country)
except City.DoesNotExist:
city = None
print(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"],
))
def import_utc_partner_data(self, response):
print("#### Import des universités partenaires ####")
for univ in response:
print(univ["idEtab"])
......@@ -64,7 +83,8 @@ class Command(BaseCommand):
"address1": univ["adr1"],
"address2": univ["adr2"],
"zipcode": univ["codePostal"],
"city": city,
"city": univ["ville"],
"country": univ["pays"],
"iso_code": univ["codeIso"]
}
)
......@@ -72,29 +92,30 @@ class Command(BaseCommand):
for partner in UtcPartner.objects.all():
print("Partenaire : " + str(partner.utc_id))
def import_course_data(self, response):
def import_opened_dest_data(self, response):
for course in response:
exchange = Exchange.objects.get_or_create(utc_departure_id=course["idDepart"])[0]
print("#### Import des destinations ouvertes ####")
print(course["idCours"])
for destination in response:
print(destination["idEtab"])
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"],
# TODO : check if DSI supply number of credit
category=course["categorie"],
profile=course["profil"],
tsh_profile=course["categorieTsh"],
student_login=course["login"],
))
semester = destination["semestre"][:1]
year = destination["semestre"][1:]
utc_partner = UtcPartner.objects.get_or_create(utc_id=destination["idEtab"])[0]
Offer.objects.update_or_create(
utc_parter=utc_partner,
year=year,
semester=semester,
defaults={
"commentary": destination["commentaire"],
"nb_seats_offered": destination["nombrePlaces"],
"dual_degree": destination["doubleDiplome"],
"is_master_offered": destination["master"],
"specialties": destination["branches"]
}
)
def parse_page(self, url, callback):
page = 0
......@@ -112,6 +133,7 @@ class Command(BaseCommand):
os.environ["FIXER_API_TOKEN"]
logger.info(os.environ["FIXER_API_TOKEN"])
self.parse_page("http://192.168.1.22:8082/api/exchanges", self.import_exchange_data)
#self.parse_page("http://192.168.1.22:8082/api/exchanges", self.import_exchange_data)
self.parse_page("http://192.168.1.22:8082/api/universities", self.import_utc_partner_data)
self.parse_page("http://192.168.1.22:8082/api/courses", self.import_course_data)
#self.parse_page("http://192.168.1.22:8082/api/openedDestinations", self.import_opened_dest_data)
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