# Path: ziggurat_foundations/exc.py
# class ZigguratException(Exception):
#     def __init__(self, msg, value=None):
#         self.msg = msg
#         self.value = value
# 
#     def __str__(self):
#         return self.msg.format(self.value)
# 
# Path: ziggurat_foundations/models/base.py
# class BaseModel(object):
#     """ Basic class that all other classes inherit from that supplies some
#     basic methods useful for interaction with packages like:
#     deform, colander or wtforms """
# 
#     @classmethod
#     def _get_keys(cls):
#         """ returns column names for this model """
#         return sa.orm.class_mapper(cls).c.keys()
# 
#     @classmethod
#     def get_primary_key(cls):
#         return sa.orm.class_mapper(cls).primary_key
# 
#     def get_dict(self, exclude_keys=None, include_keys=None):
#         """
#         return dictionary of keys and values corresponding to this model's
#         data - if include_keys is null the function will return all keys
# 
#         :param exclude_keys: (optional) is a list of columns from model that
#         should not be returned by this function
#         :param include_keys: (optional) is a list of columns from model that
#         should be returned by this function
#         :return:
#         """
#         d = {}
#         exclude_keys_list = exclude_keys or []
#         include_keys_list = include_keys or []
#         for k in self._get_keys():
#             if k not in exclude_keys_list and (
#                 k in include_keys_list or not include_keys
#             ):
#                 d[k] = getattr(self, k)
#         return d
# 
#     def get_appstruct(self):
#         """ return list of tuples keys and values corresponding to this model's
#         data """
#         result = []
#         for k in self._get_keys():
#             result.append((k, getattr(self, k)))
#         return result
# 
#     def populate_obj(self, appstruct, exclude_keys=None, include_keys=None):
#         """
#         updates instance properties *for column names that exist*
#         for this model and are keys present in passed dictionary
# 
#         :param appstruct: (dictionary)
#         :param exclude_keys: (optional) is a list of columns from model that
#         should not be updated by this function
#         :param include_keys: (optional) is a list of columns from model that
#         should be updated by this function
#         :return:
#         """
#         exclude_keys_list = exclude_keys or []
#         include_keys_list = include_keys or []
#         for k in self._get_keys():
#             if (
#                 k in appstruct
#                 and k not in exclude_keys_list
#                 and (k in include_keys_list or not include_keys)
#             ):
#                 setattr(self, k, appstruct[k])
# 
#     def populate_obj_from_obj(self, instance, exclude_keys=None, include_keys=None):
#         """
#         updates instance properties *for column names that exist*
#         for this model and are properties present in passed dictionary
# 
#         :param instance:
#         :param exclude_keys: (optional) is a list of columns from model that
#         should not be updated by this function
#         :param include_keys: (optional) is a list of columns from model that
#         should be updated by this function
#         :return:
#         """
#         exclude_keys_list = exclude_keys or []
#         include_keys_list = include_keys or []
#         for k in self._get_keys():
#             if (
#                 hasattr(instance, k)
#                 and k not in exclude_keys_list
#                 and (k in include_keys_list or not include_keys)
#             ):
#                 setattr(self, k, getattr(instance, k))
# 
#     def get_db_session(self, session=None):
#         """
#         Attempts to return session via get_db_session utility function
#         :meth:`~ziggurat_foundations.models.get_db_session`
# 
#         :param session:
#         :return:
#         """
#         return get_db_session(session, self)
# 
#     def persist(self, flush=False, db_session=None):
#         """
# 
#         Adds object to session, if the object was freshly created this will
#         persist the object in the storage on commit
# 
#         :param flush: boolean - if true then the session will be flushed
#             instantly
#         :param db_session:
#         :return:
#         """
#         db_session = get_db_session(db_session)
#         db_session.add(self)
#         if flush:
#             db_session.flush()
# 
#     def delete(self, db_session=None):
#         """
#         Deletes the object via session, this will permanently delete the
#         object from storage on commit
# 
#         :param db_session:
#         :return:
#         """
#         db_session = get_db_session(db_session, self)
#         db_session.delete(self)


import sqlalchemy as sa
from sqlalchemy.ext.declarative import declared_attr
from ziggurat_foundations.exc import ZigguratException
from ziggurat_foundations.models.base import BaseModel
        return sa.orm.relationship(
            "Group",
            secondary="groups_resources_permissions",
            passive_deletes=True,
            passive_updates=True,
        )

    @declared_attr
    def users(self):
        """ returns all users that have permissions for this resource"""
        return sa.orm.relationship(
            "User",
            secondary="users_resources_permissions",
            passive_deletes=True,
            passive_updates=True,
        )

    __mapper_args__ = {"polymorphic_on": resource_type}
    __table_args__ = {"mysql_engine": "InnoDB", "mysql_charset": "utf8"}

    def __repr__(self):
        return "<Resource: %s, %s, id: %s position: %s>" % (
            self.resource_type,
            self.resource_name,
            self.resource_id,
            self.ordering,
        )

    @property
    def __acl__(self):

# Path: ziggurat_foundations/exc.py
# class ZigguratException(Exception):
#     def __init__(self, msg, value=None):
#         self.msg = msg
#         self.value = value
# 
#     def __str__(self):
#         return self.msg.format(self.value)
# 
# Path: ziggurat_foundations/models/base.py
# class BaseModel(object):
#     """ Basic class that all other classes inherit from that supplies some
#     basic methods useful for interaction with packages like:
#     deform, colander or wtforms """
# 
#     @classmethod
#     def _get_keys(cls):
#         """ returns column names for this model """
#         return sa.orm.class_mapper(cls).c.keys()
# 
#     @classmethod
#     def get_primary_key(cls):
#         return sa.orm.class_mapper(cls).primary_key
# 
#     def get_dict(self, exclude_keys=None, include_keys=None):
#         """
#         return dictionary of keys and values corresponding to this model's
#         data - if include_keys is null the function will return all keys
# 
#         :param exclude_keys: (optional) is a list of columns from model that
#         should not be returned by this function
#         :param include_keys: (optional) is a list of columns from model that
#         should be returned by this function
#         :return:
#         """
#         d = {}
#         exclude_keys_list = exclude_keys or []
#         include_keys_list = include_keys or []
#         for k in self._get_keys():
#             if k not in exclude_keys_list and (
#                 k in include_keys_list or not include_keys
#             ):
#                 d[k] = getattr(self, k)
#         return d
# 
#     def get_appstruct(self):
#         """ return list of tuples keys and values corresponding to this model's
#         data """
#         result = []
#         for k in self._get_keys():
#             result.append((k, getattr(self, k)))
#         return result
# 
#     def populate_obj(self, appstruct, exclude_keys=None, include_keys=None):
#         """
#         updates instance properties *for column names that exist*
#         for this model and are keys present in passed dictionary
# 
#         :param appstruct: (dictionary)
#         :param exclude_keys: (optional) is a list of columns from model that
#         should not be updated by this function
#         :param include_keys: (optional) is a list of columns from model that
#         should be updated by this function
#         :return:
#         """
#         exclude_keys_list = exclude_keys or []
#         include_keys_list = include_keys or []
#         for k in self._get_keys():
#             if (
#                 k in appstruct
#                 and k not in exclude_keys_list
#                 and (k in include_keys_list or not include_keys)
#             ):
#                 setattr(self, k, appstruct[k])
# 
#     def populate_obj_from_obj(self, instance, exclude_keys=None, include_keys=None):
#         """
#         updates instance properties *for column names that exist*
#         for this model and are properties present in passed dictionary
# 
#         :param instance:
#         :param exclude_keys: (optional) is a list of columns from model that
#         should not be updated by this function
#         :param include_keys: (optional) is a list of columns from model that
#         should be updated by this function
#         :return:
#         """
#         exclude_keys_list = exclude_keys or []
#         include_keys_list = include_keys or []
#         for k in self._get_keys():
#             if (
#                 hasattr(instance, k)
#                 and k not in exclude_keys_list
#                 and (k in include_keys_list or not include_keys)
#             ):
#                 setattr(self, k, getattr(instance, k))
# 
#     def get_db_session(self, session=None):
#         """
#         Attempts to return session via get_db_session utility function
#         :meth:`~ziggurat_foundations.models.get_db_session`
# 
#         :param session:
#         :return:
#         """
#         return get_db_session(session, self)
# 
#     def persist(self, flush=False, db_session=None):
#         """
# 
#         Adds object to session, if the object was freshly created this will
#         persist the object in the storage on commit
# 
#         :param flush: boolean - if true then the session will be flushed
#             instantly
#         :param db_session:
#         :return:
#         """
#         db_session = get_db_session(db_session)
#         db_session.add(self)
#         if flush:
#             db_session.flush()
# 
#     def delete(self, db_session=None):
#         """
#         Deletes the object via session, this will permanently delete the
#         object from storage on commit
# 
#         :param db_session:
#         :return:
#         """
#         db_session = get_db_session(db_session, self)
#         db_session.delete(self)


# Path: ziggurat_foundations/models/resource.py
import sqlalchemy as sa
from sqlalchemy.ext.declarative import declared_attr
from ziggurat_foundations.exc import ZigguratException
from ziggurat_foundations.models.base import BaseModel

        return sa.orm.relationship(
            "Group",
            secondary="groups_resources_permissions",
            passive_deletes=True,
            passive_updates=True,
        )

    @declared_attr
    def users(self):
        """ returns all users that have permissions for this resource"""
        return sa.orm.relationship(
            "User",
            secondary="users_resources_permissions",
            passive_deletes=True,
            passive_updates=True,
        )

    __mapper_args__ = {"polymorphic_on": resource_type}
    __table_args__ = {"mysql_engine": "InnoDB", "mysql_charset": "utf8"}

    def __repr__(self):
        return "<Resource: %s, %s, id: %s position: %s>" % (
            self.resource_type,
            self.resource_name,
            self.resource_id,
            self.ordering,
        )

    @property
    def __acl__(self):

        raise ZigguratException("Model should implement __acl__")