Commit 9936114a authored by Florent Chehab's avatar Florent Chehab
Browse files

Merge branch 'clean_university_model' into 'master'

Updated University model and related

See merge request chehabfl/outgoing_rex!28
parents 44a6c5fc 9895a8ab
Pipeline #26866 canceled with stages
in 10 seconds
"university","city","country","lat","lon"
"Technische Universitat Ilmenau","Ilmenau","DE",50.68386845,10.9329051768032
"Universidad Del Salvador","Buenos Aires","AR",-34.5562653,-58.730053914754
"Swinburne University Of Technology","Victoria","AU",-37.85240845,144.99182255
"Technische Universitat Graz","Graz","AT",47.05821,15.460195677136
"Universiteit Gent","Gent","BE",51.0450413,3.7255573
"Universidade Federal De Minas Gerais","Belo Horizonte","BR",-19.8718898,-43.9630925706377
"Universidade Federal De Campina Grande","Campina Grande","BR",-6.76287395,-38.2281578339701
"Universidade Estadual De Campinas (Unicamp)","Campinas-Sao Paulo","BR",-22.8224781,-47.0642599309425
"Universidade Caxias Do Sul","Caxias Do Sul","BR",-29.16253545,-51.1483650151909
"Pontificia Universidade Catolica Do Parana","Curitiba","BR",-23.29907785,-51.2102693622486
"Universidade Federal Do Parana","Curitiba","BR",-23.5984464,-51.6732887712978
"Universidade Tecnologica Federal Do Parana","Curitiba","BR",-25.0521636,-50.131186381692
"Universidade Federal De Santa Catarina","Florianópolis","BR",-27.6033738,-48.5224633956674
"Universidade Federal De Itajuba","Itajuba","BR",-22.4137971,-45.4502726
"Universidade Federal Da Paraiba","João Pessoa","BR",-6.7505593,-35.6454502176197
"Universidade Federal Juiz De Fora","Juiz De Fora","BR",-21.7768942,-43.3691810386558
"Universidad Estadual De Maringa","Maringa","BR",-23.77903,-53.3252683935028
"Universidade Federal De Pernambuco","Recife","BR",-8.05254345,-34.9510286675945
"Universidade Federal De Rio De Janeiro","Rio De Janeiro","BR",-22.2459542,-42.5232866424185
"Escola Politecnica Da Universidade De Sao Paulo","Sao Paulo","BR",-23.5552106,-46.7310401128074
"Universidade Federal De Uberlandia","Uberlandia","BR",-18.941683,-48.2148699674138
"Technical University Of Sofia","Sofia","BG",42.6559773,23.35512261205
"Universidad Arturo Prat","Iquique","CL",-23.6455954,-70.394657443203
"Pontificia Universidad Catolica De Valparaiso","Valparaiso","CL",-33.0449276,-71.6067964701924
"Universidad De Valparaiso","Valparaiso","CL",-32.7414062,-70.7024233560544
"Universidad Tecnica Federico Santa Maria","Valparaiso","CL",-33.03510935,-71.5952505079485
"Escuela Colombiana De Ingenieria","Bogota","CO",4.78305195,-74.0442040297156
"Universidad Autonoma De Bucaramanga","Bucaramanga","CO",7.1168832,-73.1051629
"Universidad Eafit","Medellin","CO",6.10464025,-75.4557833087589
"Pohang University Of Science And Technology","Pohang","KR",36.0172898,129.323920997982
"Hanyang University","Seoul","KR",37.5558418,127.0438918
"Kookmin University","Seoul","KR",37.61147915,126.996468815557
"Seoul National University Of Science And Technology Seoultech","Seoul","KR",37.6324854,127.079487800846
"Escuela Politecnica Nacional De Quito","Quito","EC",-0.21033215,-78.4900641291908
"Universidad De Murcia","Murcia","ES",38.0147121,-1.1676358
"Universidad De Zaragoza","Zaragoza","ES",41.6836311,-0.885944249252812
"Oulu University Of Applied Sciences","Oulu","FI",65.00861805,25.4726477466852
"Tampere University Of Technology","Tampere","FI",61.44964205,23.8587746189096
"Universita Della Calabria","Arcavacata","IT",39.3614022,16.2263106
"Universita Di Bologna","Bologna","IT",44.50134225,11.3591361693006
"Universita Degli Studi Di Salerno","Fisciano","IT",40.75586365,14.7804889453213
"Universita Degli Studi Di Genova","Genova","IT",44.4148861,8.9266707
"Politecnico Di Milano","Milan","IT",45.4790288,9.23221040387672
"Universita Degli Studi Di Napoli Federico Ii","Napoli","IT",40.84526205,14.2512487738249
"Chiba Institute Of Technology","Chiba","JP",35.6888667,140.02117559587
"Chiba University","Chiba","JP",35.62786925,140.103465749158
"Tohoku University","Sendai","JP",38.2530945,140.8736593
"Universite Libanaise","Beyrouth","LB",33.8724848,35.5194311623001
"Université Saint-Esprit De Kaslik","Kaslik","LB",33.98265035,35.620356742624
"Universidad Autonoma De Aguascalientes","Aguascalientes","MX",21.9142883,-102.32028877891
"Universidad De Guanajuato","Guanajuato","MX",19.7242185,-101.2440472
"Universidad Anahuac Mayab","Merida Yucatan","MX",21.11060445,-89.6123220044136
"Instituto Politecnico Nacional","Mexico","MX",19.4724472,-99.1373193
"Universidad Iberoamericana","Mexico","MX",25.445818,-101.0056267
"Upaep","Pueblar, Pue","MX",19.2818385,-98.4397356
"Instituto Tecnologico De Zacatepec","Zacatepec De Hidalgo","MX",18.65203335,-99.1833987516266
"Norwegian University Of Science And Technology","Trondheim","NO",63.4103583,10.4087418620805
"University Twente","Enschede","NL",52.2233862,6.88542315997116
"Agh - University Of Science And Technology","Cracovie","PL",50.0657033,19.9189586670586
"Politechnika Krakowska","Cracovie","PL",50.0754784,19.9089536
"Universidade Da Beira Interior","Covilhã","PT",40.2780936,-7.50834821105263
"City University Of Hong Kong","Hong Kong","HK",22.34000115,114.169702912423
"Technical University Of Kosice","Kosice","SK",48.73280395,21.244194264458
"Chalmers University Of Technology","Goteborg","SE",57.6896523,11.9766811023544
"Lulea University Of Technology","Lulea","SE",65.6170445,22.1370606335398
"Ecole Polytechnique Federale De Lausanne","Lausanne","CH",46.5186594,6.566561505148
"National Chiao Tung University","Hsinchu","TW",24.78676765,120.997244116807
"National Taiwan University Of Science And Technology","Taipei","TW",25.01350785,121.541707560048
"utc_id","university","city","country","lat","lon","acronyme","website","logo"
1,"Technische Universitat Ilmenau","Ilmenau","DE","50.68386845","10.9329051768032",,,
2,"Universidad Del Salvador","Buenos Aires","AR","-34.5562653","-58.730053914754",,,
3,"Swinburne University Of Technology","Victoria","AU","-37.85240845","144.99182255",,,
4,"Technische Universitat Graz","Graz","AT","47.05821","15.460195677136",,,
5,"Universiteit Gent","Gent","BE","51.0450413","3.7255573",,,
6,"Universidade Federal De Minas Gerais","Belo Horizonte","BR","-19.8718898","-43.9630925706377",,,
7,"Universidade Federal De Campina Grande","Campina Grande","BR","-6.76287395","-38.2281578339701",,,
8,"Universidade Estadual De Campinas (Unicamp)","Campinas-Sao Paulo","BR","-22.8224781","-47.0642599309425",,,
9,"Universidade Caxias Do Sul","Caxias Do Sul","BR","-29.16253545","-51.1483650151909",,,
10,"Pontificia Universidade Catolica Do Parana","Curitiba","BR","-23.29907785","-51.2102693622486",,,
11,"Universidade Federal Do Parana","Curitiba","BR","-23.5984464","-51.6732887712978",,,
12,"Universidade Tecnologica Federal Do Parana","Curitiba","BR","-25.0521636","-50.131186381692",,,
13,"Universidade Federal De Santa Catarina","Florianópolis","BR","-27.6033738","-48.5224633956674",,,
14,"Universidade Federal De Itajuba","Itajuba","BR","-22.4137971","-45.4502726",,,
15,"Universidade Federal Da Paraiba","João Pessoa","BR","-6.7505593","-35.6454502176197",,,
16,"Universidade Federal Juiz De Fora","Juiz De Fora","BR","-21.7768942","-43.3691810386558",,,
17,"Universidad Estadual De Maringa","Maringa","BR","-23.77903","-53.3252683935028",,,
18,"Universidade Federal De Pernambuco","Recife","BR","-8.05254345","-34.9510286675945",,,
19,"Universidade Federal De Rio De Janeiro","Rio De Janeiro","BR","-22.2459542","-42.5232866424185",,,
20,"Escola Politecnica Da Universidade De Sao Paulo","Sao Paulo","BR","-23.5552106","-46.7310401128074",,,
21,"Universidade Federal De Uberlandia","Uberlandia","BR","-18.941683","-48.2148699674138",,,
22,"Technical University Of Sofia","Sofia","BG","42.6559773","23.35512261205",,,
23,"Universidad Arturo Prat","Iquique","CL","-23.6455954","-70.394657443203",,,
24,"Pontificia Universidad Catolica De Valparaiso","Valparaiso","CL","-33.0449276","-71.6067964701924",,,
25,"Universidad De Valparaiso","Valparaiso","CL","-32.7414062","-70.7024233560544",,,
26,"Universidad Tecnica Federico Santa Maria","Valparaiso","CL","-33.03510935","-71.5952505079485",,,
27,"Escuela Colombiana De Ingenieria","Bogota","CO","4.78305195","-74.0442040297156",,,
28,"Universidad Autonoma De Bucaramanga","Bucaramanga","CO","7.1168832","-73.1051629",,,
29,"Universidad Eafit","Medellin","CO","6.10464025","-75.4557833087589",,,
30,"Pohang University Of Science And Technology","Pohang","KR","36.0172898","129.323920997982",,,
31,"Hanyang University","Seoul","KR","37.5558418","127.0438918",,,
32,"Kookmin University","Seoul","KR","37.61147915","126.996468815557",,,
33,"Seoul National University Of Science And Technology Seoultech","Seoul","KR","37.6324854","127.079487800846",,,
34,"Escuela Politecnica Nacional De Quito","Quito","EC","-0.21033215","-78.4900641291908",,,
35,"Universidad De Murcia","Murcia","ES","38.0147121","-1.1676358",,,
36,"Universidad De Zaragoza","Zaragoza","ES","41.6836311","-0.885944249252812",,,
37,"Oulu University Of Applied Sciences","Oulu","FI","65.00861805","25.4726477466852",,,
38,"Tampere University Of Technology","Tampere","FI","61.44964205","23.8587746189096",,,
39,"Universita Della Calabria","Arcavacata","IT","39.3614022","16.2263106",,,
40,"Universita Di Bologna","Bologna","IT","44.50134225","11.3591361693006",,,
41,"Universita Degli Studi Di Salerno","Fisciano","IT","40.75586365","14.7804889453213",,,
42,"Universita Degli Studi Di Genova","Genova","IT","44.4148861","8.9266707",,,
43,"Politecnico Di Milano","Milan","IT","45.4790288","9.23221040387672",,,
44,"Universita Degli Studi Di Napoli Federico Ii","Napoli","IT","40.84526205","14.2512487738249",,,
45,"Chiba Institute Of Technology","Chiba","JP","35.6888667","140.02117559587",,,
46,"Chiba University","Chiba","JP","35.62786925","140.103465749158",,,
47,"Tohoku University","Sendai","JP","38.2530945","140.8736593",,,
48,"Universite Libanaise","Beyrouth","LB","33.8724848","35.5194311623001",,,
49,"Université Saint-Esprit De Kaslik","Kaslik","LB","33.98265035","35.620356742624",,,
50,"Universidad Autonoma De Aguascalientes","Aguascalientes","MX","21.9142883","-102.32028877891",,,
51,"Universidad De Guanajuato","Guanajuato","MX","19.7242185","-101.2440472",,,
52,"Universidad Anahuac Mayab","Merida Yucatan","MX","21.11060445","-89.6123220044136",,,
53,"Instituto Politecnico Nacional","Mexico","MX","19.4724472","-99.1373193",,,
54,"Universidad Iberoamericana","Mexico","MX","25.445818","-101.0056267",,,
55,"Upaep","Pueblar, Pue","MX","19.2818385","-98.4397356",,,
56,"Instituto Tecnologico De Zacatepec","Zacatepec De Hidalgo","MX","18.65203335","-99.1833987516266",,,
57,"Norwegian University Of Science And Technology","Trondheim","NO","63.4103583","10.4087418620805",,,
58,"University Twente","Enschede","NL","52.2233862","6.88542315997116",,,
59,"Agh - University Of Science And Technology","Cracovie","PL","50.0657033","19.9189586670586",,,
60,"Politechnika Krakowska","Cracovie","PL","50.0754784","19.9089536",,,
61,"Universidade Da Beira Interior","Covilhã","PT","40.2780936","-7.50834821105263",,,
62,"City University Of Hong Kong","Hong Kong","HK","22.34000115","114.169702912423",,,
63,"Technical University Of Kosice","Kosice","SK","48.73280395","21.244194264458",,,
64,"Chalmers University Of Technology","Goteborg","SE","57.6896523","11.9766811023544",,,
65,"Lulea University Of Technology","Lulea","SE","65.6170445","22.1370606335398",,,
66,"Ecole Polytechnique Federale De Lausanne","Lausanne","CH","46.5186594","6.566561505148","EPFL","https://www.epfl.ch/","https://www.epfl.ch/img/epfl_small.png"
67,"National Chiao Tung University","Hsinchu","TW","24.78676765","120.997244116807",,,
68,"National Taiwan University Of Science And Technology","Taipei","TW","25.01350785","121.541707560048",,,
......@@ -21,11 +21,11 @@ class LoadUniversities(LoadGeneric):
dtype=object)
for index, row in data.iterrows():
univ_name, city_name, country_code, lat, lon = row
utc_id, univ_name, city_name, country_code, lat, lon, acronym, website, logo = row
lat = round(float(lat), 6)
lon = round(float(lon), 6)
country = Country.objects.filter(pk=country_code)[0]
country = Country.objects.get(pk=country_code)
city = City(
name=city_name,
country=country
......@@ -33,10 +33,15 @@ class LoadUniversities(LoadGeneric):
city.save()
self.add_info(city, self.admin)
univ = University(
name=univ_name
)
univ.save()
univ = University.objects.update_or_create(
utc_id=utc_id,
defaults={
"name": univ_name,
"acronym": acronym,
"website": website,
"logo": logo
}
)[0]
self.add_info(univ, self.admin)
main_campus = Campus(
......
# Generated by Django 2.0.3 on 2018-09-03 07:53
import backend.models.university.university
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('backend', '0002_auto_20180902_1716'),
]
operations = [
migrations.AddField(
model_name='university',
name='utc_id',
field=models.IntegerField(default=1, unique=True),
preserve_default=False,
),
migrations.AlterField(
model_name='university',
name='logo',
field=models.URLField(blank=True, null=True, validators=[backend.models.university.university.validate_extension_django]),
),
migrations.AlterField(
model_name='university',
name='website',
field=models.URLField(blank=True, null=True),
),
]
from django.conf import settings
PHOTOS_TAG_GONFIG = {
"type": "array",
"required": True,
......@@ -6,12 +8,7 @@ PHOTOS_TAG_GONFIG = {
"type": "url",
"required": True,
"validators": {
"extension": [
"jpg",
"jpeg",
"png",
"svg"
]
"extension": settings.ALLOWED_PHOTOS_EXTENSION
}
},
"title": {
......
from .university import University # noqa: F401
from .university import University, UniversitySerializer, UniversityViewSet # noqa: F401
from .universityAPI import UniversitySerializer, UniversityViewSet # noqa: F401
from .universityScholarship import UniversityScholarship, UniversityScholarshipSerializer, UniversityScholarshipViewSet # noqa: F401
from .universityDri import UniversityDri, UniversityDriSerializer, UniversityDriViewSet # noqa: F401
from .universityInfo import UniversityInfo, UniversityInfoSerializer, UniversityInfoViewSet # noqa: F401
......
from django.db import models
from backend.models.my_model import MyModel
from backend.utils.friendly_path import friendly_path
from backend.utils import get_model_config
from django.core.exceptions import ValidationError
from rest_framework.validators import ValidationError as RFValidationError
from backend.models.tag.validators.url import validate_extension
from django.conf import settings
from backend.models.my_model import MyModelSerializer, MyModelViewSet
from backend.utils import get_viewset_permissions
path_and_rename = friendly_path("uploads/universities/logos/", 'name')
def validate_extension_django(url):
try:
validate_extension(settings.ALLOWED_PHOTOS_EXTENSION, url)
except RFValidationError:
raise ValidationError(
"Extension in URL doesn't correspond to an image")
class University(MyModel):
......@@ -14,9 +25,20 @@ class University(MyModel):
name = models.CharField(max_length=200)
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 !
website = models.URLField(null=True)
logo = models.URLField(null=True, blank=True, validators=[
validate_extension_django])
website = models.URLField(null=True, blank=True)
utc_id = models.IntegerField(unique=True)
class UniversitySerializer(MyModelSerializer):
class Meta:
model = University
exclude = ('utc_id',)
# Rest API related stuff are in universityAPI.py to prevent circular depedencies
class UniversityViewSet(MyModelViewSet):
permission_classes = get_viewset_permissions("UniversityViewSet")
serializer_class = UniversitySerializer
queryset = University.objects.all() # pylint: disable=E1101
from backend.models.university import University
from backend.models.my_model import MyModelSerializer, MyModelViewSet
from backend.utils import get_viewset_permissions
class UniversitySerializer(MyModelSerializer):
class Meta:
model = University
fields = '__all__'
class UniversityViewSet(MyModelViewSet):
permission_classes = get_viewset_permissions("UniversityViewSet")
serializer_class = UniversitySerializer
queryset = University.objects.all() # pylint: disable=E1101
......@@ -216,7 +216,7 @@ class ModerationTestCase(WithUserTestCase):
Test to check that when moderation IS activated
no error regarding saving occures with foreing key
"""
c = University(name="Univ de test")
c = University(name="Univ de test", utc_id=100)
c.save()
data = {
......
......@@ -52,6 +52,7 @@ MIDDLEWARE = [
# If we want to activate the moderation functionnalities
MODERATION_ACTIVATED = True
TESTING = "pytest" in sys.modules
ALLOWED_PHOTOS_EXTENSION = ["jpg", "jpeg", "png", "svg"]
INTERNAL_IPS = ['127.0.0.1']
......
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