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

import csv 

from decimal import Decimal 

from os.path import abspath, join 

 

from backend_app.load_data.utils import ASSETS_PATH 

from backend_app.models.currency import Currency 

from base_app.models import User 

 

from .loadGeneric import LoadGeneric 

 

 

class LoadCurrencies(LoadGeneric): 

""" 

Load currencies in the app 

""" 

 

def __init__(self, admin: User): 

self.admin = admin 

 

def load(self): 

currencies_file_loc = abspath(join(ASSETS_PATH, "currencies.csv")) 

 

with open(currencies_file_loc) as csvfile: 

reader = csv.reader(csvfile, quotechar='"') 

next(reader) 

for r in reader: 

currency = Currency( 

code=r[0], 

name=r[1], 

symbol="", 

one_EUR_in_this_currency=Decimal(r[2]), 

) 

currency.save() 

self.add_info_and_save(currency, self.admin)