Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

from os.path import abspath, join 

 

from backend_app.load_data.utils import ASSETS_PATH, csv_2_dict_list 

from backend_app.models.country import Country 

from backend_app.models.partner import Partner 

from backend_app.models.university import University 

from base_app.models import User 

from .loadGeneric import LoadGeneric 

 

 

class LoadUniversities(LoadGeneric): 

""" 

Load the universities in the app 

""" 

 

def __init__(self, admin: User): 

self.admin = admin 

 

@staticmethod 

def get_destination_data(): 

destinations_path = abspath(join(ASSETS_PATH, "destinations_extracted.csv")) 

return csv_2_dict_list(destinations_path) 

 

def load(self): 

for row in self.get_destination_data(): 

lat = round(float(row["lat"]), 6) 

lon = round(float(row["lon"]), 6) 

 

country = Country.objects.get(pk=row["country"]) 

 

univ = University.objects.update_or_create( 

pk=row["utc_id"], # Not perfect but should do the trick 

defaults={ 

"name": row["university"], 

"acronym": row["acronym"], 

"website": row["website"], 

"city": row["city"], 

"country": country, 

"main_campus_lat": lat, 

"main_campus_lon": lon, 

# "logo": row["logo"], # WARNING FIX BETA not ok 

}, 

)[0] 

self.add_info_and_save(univ, self.admin) 

 

Partner.objects.update_or_create( 

utc_id=row["utc_id"], 

defaults=dict( 

univ_name=row["university"], 

city=row["city"], 

country=row["country"], 

iso_code=row["country"], 

university=univ, 

), 

)