loadCurrencies.py 851 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from backend_app.models.currency import Currency
Florent Chehab's avatar
Florent Chehab committed
2 3 4 5 6 7 8 9 10 11 12
import os
import csv
from .loadGeneric import LoadGeneric
from decimal import Decimal


class LoadCurrencies(LoadGeneric):
    def __init__(self, admin):
        self.admin = admin

    def load(self):
13
        tmp = os.path.join(os.path.realpath(__file__), "../../assets/currencies.csv")
Florent Chehab's avatar
Florent Chehab committed
14 15 16 17 18 19 20 21 22 23
        currencies_file_loc = os.path.abspath(tmp)

        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="",
24
                    one_EUR_in_this_currency=Decimal(r[2]),
Florent Chehab's avatar
Florent Chehab committed
25 26
                )
                currency.save()
27
                self.add_info_and_save(currency, self.admin)