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

Florent Chehab's avatar
Florent Chehab committed
4
from backend_app.models.tag import Tag
5
from base_app.models import User
Florent Chehab's avatar
Florent Chehab committed
6 7 8 9
from .loadGeneric import LoadGeneric


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

    def __init__(self, admin: User):
Florent Chehab's avatar
Florent Chehab committed
15 16 17
        self.admin = admin

    def load(self):
18
        tmp = os.path.join(os.path.realpath(__file__), "../../assets/tags.json")
Florent Chehab's avatar
Florent Chehab committed
19 20 21
        tags_path = os.path.abspath(tmp)
        with open(tags_path) as f:
            tags = json.load(f)
22 23
            for tag_name in tags:
                t = Tag(name=tag_name)
Florent Chehab's avatar
Florent Chehab committed
24
                t.save()
25
                self.add_info_and_save(t, self.admin)