# Path: action/base_manager.py
# class BaseManager:
#     COOKIE_PATH = '/'
#     def delete_cookie(self, name):
#     def get_cookie(self, name):
#     def get_form(self, name, strip_value=True):
#     def set_cookie(self, name, value, httponly=True, expires=None):
# 
# Path: entity/tag.py
# class Tag:
#     def __init__(self, id=None, name='', synonym_of=None, synonyms=[]):
#     def __str__(self):
#     def delete(self, db):
#     def find_all(db):
#     def find_name(db, name):
#     def find_pk(db, id):
#     def find_recipe(db, recipe):
#     def find_synonyms(self, db):
#     def from_row(db, row, find_synonyms=True):
#     def is_new(self):
#     def name_exists(db, name):
#     def save(self, db):
#     def __generic_find(db, query, params):
# 
# Path: helper/hint.py
# class Hint:
#     def __init__(self, text):
# 
# Path: helper/translator.py
# class TranslatorNotInitializedError(Exception):
# class Translator:
#     def current_language(default_language):
#     def init(language, path):
#     def instance(language):


from action import base_manager
from entity import tag as tag_entity
from helper import hint
from helper import translator
                hint_text = _('New tag "{}" has been created.').format(name)
                self.hints.append(hint.Hint(hint_text))

        elif action == 'new-synonym':
            parent = self.get_form('id')
            name = self.get_form('name')
            if self.__name_ok(name, language):
                tag = tag_entity.Tag(name=name, synonym_of=parent)
                tag.save(self.db)
                hint_text = _('New synonym "{}" has been created.').format(name)
                self.hints.append(hint.Hint(hint_text))

        elif action == 'edit':
            is_delete = self.get_form('delete') is not None
            id = int(self.get_form('id'))
            name = self.get_form('name')
            entity = tag_entity.Tag.find_pk(self.db, id)
            entity.name = name

            if is_delete:
                entity.delete(self.db)
                hint_text = _('Tag "{}" has been removed.').format(name)
                self.hints.append(hint.Hint(hint_text))
            else:
                if self.__name_ok(name, language):
                    entity.save(self.db)
                    hint_text = _('Tag "{}" has been updated.').format(name)
                    self.hints.append(hint.Hint(hint_text))

        # Load content.

# Path: action/base_manager.py
# class BaseManager:
#     COOKIE_PATH = '/'
#     def delete_cookie(self, name):
#     def get_cookie(self, name):
#     def get_form(self, name, strip_value=True):
#     def set_cookie(self, name, value, httponly=True, expires=None):
# 
# Path: entity/tag.py
# class Tag:
#     def __init__(self, id=None, name='', synonym_of=None, synonyms=[]):
#     def __str__(self):
#     def delete(self, db):
#     def find_all(db):
#     def find_name(db, name):
#     def find_pk(db, id):
#     def find_recipe(db, recipe):
#     def find_synonyms(self, db):
#     def from_row(db, row, find_synonyms=True):
#     def is_new(self):
#     def name_exists(db, name):
#     def save(self, db):
#     def __generic_find(db, query, params):
# 
# Path: helper/hint.py
# class Hint:
#     def __init__(self, text):
# 
# Path: helper/translator.py
# class TranslatorNotInitializedError(Exception):
# class Translator:
#     def current_language(default_language):
#     def init(language, path):
#     def instance(language):


# Path: action/tag_manager.py
from action import base_manager
from entity import tag as tag_entity
from helper import hint
from helper import translator

                hint_text = _('New tag "{}" has been created.').format(name)
                self.hints.append(hint.Hint(hint_text))

        elif action == 'new-synonym':
            parent = self.get_form('id')
            name = self.get_form('name')
            if self.__name_ok(name, language):
                tag = tag_entity.Tag(name=name, synonym_of=parent)
                tag.save(self.db)
                hint_text = _('New synonym "{}" has been created.').format(name)
                self.hints.append(hint.Hint(hint_text))

        elif action == 'edit':
            is_delete = self.get_form('delete') is not None
            id = int(self.get_form('id'))
            name = self.get_form('name')
            entity = tag_entity.Tag.find_pk(self.db, id)
            entity.name = name

            if is_delete:
                entity.delete(self.db)
                hint_text = _('Tag "{}" has been removed.').format(name)
                self.hints.append(hint.Hint(hint_text))
            else:
                if self.__name_ok(name, language):
                    entity.save(self.db)
                    hint_text = _('Tag "{}" has been updated.').format(name)
                    self.hints.append(hint.Hint(hint_text))

        # Load content.

        return tag_entity.Tag.find_all(self.db)