loadTags.py 668 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1 2 3
import json
import os

4
from base_app.models import User
Florent Chehab's avatar
Florent Chehab committed
5

Florent Chehab's avatar
Florent Chehab committed
6
from backend_app.models.tag import Tag
Florent Chehab's avatar
Florent Chehab committed
7 8 9 10 11

from .loadGeneric import LoadGeneric


class LoadTags(LoadGeneric):
Florent Chehab's avatar
Florent Chehab committed
12 13 14 15 16
    """
    Class to load the tags in the app.
    """

    def __init__(self, admin: User):
Florent Chehab's avatar
Florent Chehab committed
17 18 19 20
        self.admin = admin

    def load(self):

21
        tmp = os.path.join(os.path.realpath(__file__), "../../assets/tags.json")
Florent Chehab's avatar
Florent Chehab committed
22 23 24 25
        tags_path = os.path.abspath(tmp)
        with open(tags_path) as f:
            tags = json.load(f)
            for tag in tags:
26
                t = Tag(name=tag["name"], config=tag["config"])
Florent Chehab's avatar
Florent Chehab committed
27
                t.save()
28
                self.add_info_and_save(t, self.admin)