# Path: beavy/models/object.py
# class Object(db.Model):
#     """
#     This is the primary base class for all kind of objects
#     we know of inside the system
#     """
#     @unique
#     class Capabilities(Enum):
#         # This type is to be shown in default lists
#         # like 'top', 'latest' etc
#         listed = 'listed'
# 
#         # If the type isn't listed but has `listed_for_activity`
#         # it can show up in lists about activitys, for example
#         # when an object got liked
#         listed_for_activity = 'a_listable'
# 
#         # This can be searched for
#         searchable = 'searchable'
# 
#     __tablename__ = "objects"
#     query_class = ObjectQuery
# 
#     id = db.Column(db.Integer, primary_key=True)
#     discriminator = db.Column('type', db.String(100), nullable=False)
#     created_at = db.Column('created_at', db.DateTime(), nullable=False,
#                            server_default=func.now())
#     payload = db.Column('payload', JSONB, nullable=True)
#     owner_id = db.Column(db.Integer, db.ForeignKey(User.id), nullable=False)
#     belongs_to = db.Column(db.Integer, db.ForeignKey("objects.id"),
#                            nullable=True)
#     # children = db.relationship("Object", backref=db.backref('belongs_to',
#     #                                                         remote_side=id))
# 
#     __mapper_args__ = {'polymorphic_on': discriminator}
# 
#     owner = db.relationship(User, backref=db.backref('objects'))
# 
# Path: beavy/models/object.py
# class ObjectQuery(AccessQuery):
# class Object(db.Model):
#     class Capabilities(Enum):
#     def by_capability(self, aborting=True, abort_code=404, *caps):
#     def with_my_activities(self):
# 
# Path: beavy/common/payload_property.py
# class PayloadProperty(object):
# 
#     def __init__(self, key, path=[], attribute='payload', force=True):
#         self.key = key
#         self.attribute = attribute
#         self.force = force
#         self.path = isinstance(path, str) and path.split('.') or path
#         self.flag_modified = sa_flag_modified
# 
#     def _findBase(self, obj):
#         base = getattr(obj, self.attribute)
#         if base is None and self.force:
#             base = {}
#             setattr(obj, self.attribute, base)
#             self.flag_modified(obj, self.attribute)
# 
#         items = self.path[:]
#         while items:
#             cur = items.pop(0)
#             try:
#                 base = base[cur]
#             except KeyError:
#                 base[cur] = {}
#                 base = base[cur]
#                 while items:
#                     cur = items.pop(0)
#                     base[cur] = {}
#                     base = base[cur]
# 
#                 self.flag_modified(obj, self.attribute)
#                 break
# 
#         return base
# 
#     def __get__(self, obj, _):
#         if not obj:
#             # someone asked on the class
#             return self
#         base = self._findBase(obj)
#         key = self.key
# 
#         return base.get(key, None)
# 
#     def __set__(self, obj, value):
#         self._findBase(obj)[self.key] = value
#         self.flag_modified(obj, self.attribute)
# 
#     def __delete__(self, obj):
#         raise NotImplemented()
# 
# Path: beavy/utils/url_converters.py
# class ModelConverter(BaseConverter):
#     __OBJECTS__ = {
#         'user': User,
#         'object': Object,
#         'activity': Activity
#     }
# 
#     def __init__(self, url_map, obj="object"):
#         super(ModelConverter, self).__init__(url_map)
#         # match ID or string
#         self.regex = '-?\d+|\S+'
#         self.cls = self.__OBJECTS__[obj]
# 
#     def to_python(self, value):
#         cls = self.cls
#         try:
#             return cls.query.get_or_404(int(value))
#         except ValueError:
#             pass
# 
#         if not getattr(cls, "__LOOKUP_ATTRS__", False):
#             abort(404)
# 
#         return cls.query.filter(or_(*[getattr(cls, key) == value
#                                       for key in cls.__LOOKUP_ATTRS__])
#                                 ).first_or_404()
# 
# Path: beavy/app.py
# BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# STATIC_FOLDER = os.path.join(BASE_DIR, '..', 'assets')
#     _FLBLPRE = "flask_social_blueprint.providers.{}"
# def make_env(app):
# def setup_statics(app):
#     def injnect_manifest():
# def make_celery(app):
#         def __call__(self, *args, **kwargs):
#     def login_failed_redirect(self, profile, provider):
#     def is_accessible(self):
# def _limiter_key():
# def inject_messages():
# def get_locale():
#     def ensure_users():
#     def print_routes():
#     class ContextTask(TaskBase):
# class SocialBlueprint(SocialBp):
# class BeavyAdminIndexView(AdminIndexView):


from beavy.models.object import Object
from beavy.models.object import User
from beavy.common.payload_property import PayloadProperty
from beavy.utils.url_converters import ModelConverter
from beavy.app import db


PM_ID = "private_message"


# Define models
PMParticipants = db.Table('{}_participants'.format(PM_ID),
                          db.Column('user_id',
                                    db.Integer(),

# Path: beavy/models/object.py
# class Object(db.Model):
#     """
#     This is the primary base class for all kind of objects
#     we know of inside the system
#     """
#     @unique
#     class Capabilities(Enum):
#         # This type is to be shown in default lists
#         # like 'top', 'latest' etc
#         listed = 'listed'
# 
#         # If the type isn't listed but has `listed_for_activity`
#         # it can show up in lists about activitys, for example
#         # when an object got liked
#         listed_for_activity = 'a_listable'
# 
#         # This can be searched for
#         searchable = 'searchable'
# 
#     __tablename__ = "objects"
#     query_class = ObjectQuery
# 
#     id = db.Column(db.Integer, primary_key=True)
#     discriminator = db.Column('type', db.String(100), nullable=False)
#     created_at = db.Column('created_at', db.DateTime(), nullable=False,
#                            server_default=func.now())
#     payload = db.Column('payload', JSONB, nullable=True)
#     owner_id = db.Column(db.Integer, db.ForeignKey(User.id), nullable=False)
#     belongs_to = db.Column(db.Integer, db.ForeignKey("objects.id"),
#                            nullable=True)
#     # children = db.relationship("Object", backref=db.backref('belongs_to',
#     #                                                         remote_side=id))
# 
#     __mapper_args__ = {'polymorphic_on': discriminator}
# 
#     owner = db.relationship(User, backref=db.backref('objects'))
# 
# Path: beavy/models/object.py
# class ObjectQuery(AccessQuery):
# class Object(db.Model):
#     class Capabilities(Enum):
#     def by_capability(self, aborting=True, abort_code=404, *caps):
#     def with_my_activities(self):
# 
# Path: beavy/common/payload_property.py
# class PayloadProperty(object):
# 
#     def __init__(self, key, path=[], attribute='payload', force=True):
#         self.key = key
#         self.attribute = attribute
#         self.force = force
#         self.path = isinstance(path, str) and path.split('.') or path
#         self.flag_modified = sa_flag_modified
# 
#     def _findBase(self, obj):
#         base = getattr(obj, self.attribute)
#         if base is None and self.force:
#             base = {}
#             setattr(obj, self.attribute, base)
#             self.flag_modified(obj, self.attribute)
# 
#         items = self.path[:]
#         while items:
#             cur = items.pop(0)
#             try:
#                 base = base[cur]
#             except KeyError:
#                 base[cur] = {}
#                 base = base[cur]
#                 while items:
#                     cur = items.pop(0)
#                     base[cur] = {}
#                     base = base[cur]
# 
#                 self.flag_modified(obj, self.attribute)
#                 break
# 
#         return base
# 
#     def __get__(self, obj, _):
#         if not obj:
#             # someone asked on the class
#             return self
#         base = self._findBase(obj)
#         key = self.key
# 
#         return base.get(key, None)
# 
#     def __set__(self, obj, value):
#         self._findBase(obj)[self.key] = value
#         self.flag_modified(obj, self.attribute)
# 
#     def __delete__(self, obj):
#         raise NotImplemented()
# 
# Path: beavy/utils/url_converters.py
# class ModelConverter(BaseConverter):
#     __OBJECTS__ = {
#         'user': User,
#         'object': Object,
#         'activity': Activity
#     }
# 
#     def __init__(self, url_map, obj="object"):
#         super(ModelConverter, self).__init__(url_map)
#         # match ID or string
#         self.regex = '-?\d+|\S+'
#         self.cls = self.__OBJECTS__[obj]
# 
#     def to_python(self, value):
#         cls = self.cls
#         try:
#             return cls.query.get_or_404(int(value))
#         except ValueError:
#             pass
# 
#         if not getattr(cls, "__LOOKUP_ATTRS__", False):
#             abort(404)
# 
#         return cls.query.filter(or_(*[getattr(cls, key) == value
#                                       for key in cls.__LOOKUP_ATTRS__])
#                                 ).first_or_404()
# 
# Path: beavy/app.py
# BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# STATIC_FOLDER = os.path.join(BASE_DIR, '..', 'assets')
#     _FLBLPRE = "flask_social_blueprint.providers.{}"
# def make_env(app):
# def setup_statics(app):
#     def injnect_manifest():
# def make_celery(app):
#         def __call__(self, *args, **kwargs):
#     def login_failed_redirect(self, profile, provider):
#     def is_accessible(self):
# def _limiter_key():
# def inject_messages():
# def get_locale():
#     def ensure_users():
#     def print_routes():
#     class ContextTask(TaskBase):
# class SocialBlueprint(SocialBp):
# class BeavyAdminIndexView(AdminIndexView):


# Path: beavy_modules/private_messaging/models.py
from beavy.models.object import Object
from beavy.models.object import User
from beavy.common.payload_property import PayloadProperty
from beavy.utils.url_converters import ModelConverter
from beavy.app import db



PM_ID = "private_message"


# Define models
PMParticipants = db.Table('{}_participants'.format(PM_ID),
                          db.Column('user_id',
                                    db.Integer(),

                                    db.ForeignKey(User.id),