# 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/category.py
# class Category:
#     def __init__(self, id=None, name=''):
#     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 from_row(row):
#     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 category
from helper import hint
from helper import translator

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

            if is_delete:
                entity.delete(self.db)
                hint_text = _('Category "{}" 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 = _('Category "{}" has been updated.').format(name)
                    self.hints.append(hint.Hint(hint_text))

        # Load content.
        return category.Category.find_all(self.db)

    def __name_ok(self, name, language):
        """ Validates the name. Returns True if ok. """
        _ = translator.Translator.instance(language)

        if not name:
            hint_text = _('Name must not be empty.').format(name)
            self.hints.append(hint.Hint(hint_text))
            return False


# 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/category.py
# class Category:
#     def __init__(self, id=None, name=''):
#     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 from_row(row):
#     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/category_manager.py
from action import base_manager
from entity import category
from helper import hint
from helper import translator


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

            if is_delete:
                entity.delete(self.db)
                hint_text = _('Category "{}" 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 = _('Category "{}" has been updated.').format(name)
                    self.hints.append(hint.Hint(hint_text))

        # Load content.
        return category.Category.find_all(self.db)

    def __name_ok(self, name, language):
        """ Validates the name. Returns True if ok. """
        _ = translator.Translator.instance(language)

        if not name:
            hint_text = _('Name must not be empty.').format(name)
            self.hints.append(hint.Hint(hint_text))
            return False


        exists = category.Category.name_exists(self.db, name)