2010-01-15 20:55:30 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# ScribeEngine - Open Source Blog Software #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# Copyright (c) 2010 Raoul Snyman #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program 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 General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
"""
|
|
|
|
The application's model objects
|
|
|
|
"""
|
|
|
|
|
|
|
|
from sqlalchemy.orm import mapper, relation
|
|
|
|
|
|
|
|
from scribeengine.model import meta
|
|
|
|
from scribeengine.model.tables import categories_table, comments_table, \
|
|
|
|
pages_table, permissions_table, posts_table, roles_table, tags_table, \
|
|
|
|
users_table, variables_table, categories_posts_table, \
|
|
|
|
permissions_roles_table, posts_tags_table, roles_users_table
|
|
|
|
from scribeengine.model.classes import Category, Comment, Page, Permission, \
|
|
|
|
Post, Role, Tag, User, Variable
|
|
|
|
|
|
|
|
def init_model(engine):
|
|
|
|
"""Call me before using any of the tables or classes in the model"""
|
|
|
|
meta.Session.configure(bind=engine)
|
|
|
|
meta.engine = engine
|
|
|
|
|
|
|
|
mapper(Category, categories_table)
|
|
|
|
mapper(Comment, comments_table)
|
|
|
|
mapper(Page, pages_table)
|
|
|
|
mapper(Permission, permissions_table)
|
|
|
|
mapper(Post, posts_table,
|
|
|
|
properties={
|
|
|
|
u'categories': relation(Category, backref='posts', secondary=categories_posts_table),
|
2010-01-18 20:16:46 +00:00
|
|
|
u'comments': relation(Comment, backref=u'post', order_by=Comment.created.desc()),
|
2010-01-15 20:55:30 +00:00
|
|
|
u'tags': relation(Tag, backref=u'posts', secondary=posts_tags_table)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
mapper(Role, roles_table,
|
|
|
|
properties={
|
|
|
|
u'permissions': relation(Permission, backref=u'roles', secondary=permissions_roles_table)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
mapper(Tag, tags_table)
|
|
|
|
mapper(User, users_table,
|
|
|
|
properties={
|
|
|
|
u'comments': relation(Comment, backref=u'user'),
|
|
|
|
#u'pages': relation(Page, backref=u'user'),
|
|
|
|
u'posts': relation(Post, backref=u'user'),
|
|
|
|
u'roles': relation(Role, backref=u'users', secondary=roles_users_table)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
mapper(Variable, variables_table)
|