loadTags.py 599 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from backend_app.models.tag import Tag
Florent Chehab's avatar
Florent Chehab committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

import os
import json
from .loadGeneric import LoadGeneric


class LoadTags(LoadGeneric):

    def __init__(self, admin):
        self.admin = admin

    def load(self):

        tmp = os.path.join(os.path.realpath(__file__),
                           '../../assets/tags.json')
        tags_path = os.path.abspath(tmp)
        with open(tags_path) as f:
            tags = json.load(f)
            for tag in tags:
                t = Tag(name=tag['name'], config=tag['config'])
                t.save()
23
                self.add_info_and_save(t, self.admin)