# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2014-2015 Anthony Minotti <anthony@minotti.cool>.
#
#
# This file is part of Yameo framework.
#
# Yameo framework is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# Yameo framework is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Yameo framework.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################


from app.context import models
from lib.exceptions import *


def ressourceConstraints(self, value):
    ressource = value.lower().capitalize()
    if not models.get(ressource):
        raise Core400Exception("Ressource '{}' doesn't exist.".format(ressource))
    return ressource

@@ -1237,8 +1237,598 @@
 ssource%0A
+%0A%0Adef write(self):%0A    # Test if ressource is hookable before performing normal process%0A    if models.get(self.ressource)._hookable:%0A        super(self.__class__, self).write()%0A    else:%0A        raise Core400Exception(%22Ressource '%7B%7D' is not hookable.%22.format(self.ressource))%0A%0A%0Adef update(self, data2save, domain):%0A    # Test if ressource is hookable before performing normal process%0A    if models.get(self.ressource)._hookable:%0A        super(self.__class__, self).update(data2save, domain)%0A    else:%0A        raise Core400Exception(%22Ressource '%7B%7D' is not hookable.%22.format(self.ressource))%0A

Test if ressource is hookable before write/update