From: Eevee Date: Tue, 11 May 2010 05:16:08 +0000 (-0700) Subject: Extremely basic forum tables and browsing. X-Git-Tag: veekun-promotions/2010051501~1 X-Git-Url: http://git.veekun.com/zzz-spline-forum.git/commitdiff_plain/e24696628dac6692cf27fbda910f10522dae7759 Extremely basic forum tables and browsing. --- diff --git a/migration/manage.py b/migration/manage.py old mode 100644 new mode 100755 diff --git a/migration/versions/001_Create_basic_forum_tables.py b/migration/versions/001_Create_basic_forum_tables.py new file mode 100644 index 0000000..4949fe1 --- /dev/null +++ b/migration/versions/001_Create_basic_forum_tables.py @@ -0,0 +1,35 @@ +from sqlalchemy import * +from migrate import * + +from sqlalchemy.ext.declarative import declarative_base +TableBase = declarative_base(bind=migrate_engine) + + +class Forum(TableBase): + __tablename__ = 'forums' + id = Column(Integer, primary_key=True, autoincrement=True, nullable=False) + name = Column(Unicode(133), nullable=False) + +class Thread(TableBase): + __tablename__ = 'threads' + id = Column(Integer, primary_key=True, autoincrement=True, nullable=False) + forum_id = Column(Integer, ForeignKey('forums.id'), nullable=False) + subject = Column(Unicode(133), nullable=False) + +class Post(TableBase): + __tablename__ = 'posts' + id = Column(Integer, primary_key=True, autoincrement=True, nullable=False) + thread_id = Column(Integer, ForeignKey('threads.id'), nullable=False) + posted_time = Column(DateTime, nullable=False) + content = Column(Unicode(5120), nullable=False) + + +def upgrade(): + Forum.__table__.create() + Thread.__table__.create() + Post.__table__.create() + +def downgrade(): + Post.__table__.drop() + Thread.__table__.drop() + Forum.__table__.drop() diff --git a/spline/plugins/forum/__init__.py b/spline/plugins/forum/__init__.py index a3f259e..bd48a20 100644 --- a/spline/plugins/forum/__init__.py +++ b/spline/plugins/forum/__init__.py @@ -12,7 +12,9 @@ import spline.plugins.forum.model def add_routes_hook(map, *args, **kwargs): """Hook to inject some of our behavior into the routes configuration.""" - map.connect('/forum', controller='forum', action='index') + map.connect('/forums', controller='forum', action='forums') + map.connect('/forums/{forum_id}', controller='forum', action='threads') + map.connect('/forums/{forum_id}/threads/{thread_id}', controller='forum', action='posts') class ForumPlugin(PluginBase): @@ -21,6 +23,13 @@ class ForumPlugin(PluginBase): forum = spline.plugins.forum.controllers.forum.ForumController, ) + def model(self): + return [ + model.Forum, + model.Thread, + model.Post, + ] + def template_dirs(self): return [ (resource_filename(__name__, 'templates'), Priority.NORMAL) diff --git a/spline/plugins/forum/controllers/forum.py b/spline/plugins/forum/controllers/forum.py index 6d577fb..bf66618 100644 --- a/spline/plugins/forum/controllers/forum.py +++ b/spline/plugins/forum/controllers/forum.py @@ -14,8 +14,23 @@ log = logging.getLogger(__name__) class ForumController(BaseController): - def index(self): - # Return a rendered template - # return render('/template.mako') - # or, Return a response - return 'stub' + def forums(self): + c.forums = meta.Session.query(model.Forum).order_by(model.Forum.id.asc()) + return render('/forum/forums.mako') + + def threads(self, forum_id): + try: + c.forum = meta.Session.query(model.Forum).get(forum_id) + except NoResultFound: + abort(404) + + return render('/forum/threads.mako') + + def posts(self, forum_id, thread_id): + try: + c.thread = meta.Session.query(model.Thread) \ + .filter_by(id=thread_id, forum_id=forum_id).one() + except NoResultFound: + abort(404) + + return render('/forum/threads.mako') diff --git a/spline/plugins/forum/model/__init__.py b/spline/plugins/forum/model/__init__.py index f7d8a14..5ee242b 100644 --- a/spline/plugins/forum/model/__init__.py +++ b/spline/plugins/forum/model/__init__.py @@ -1,7 +1,29 @@ from sqlalchemy import Column, ForeignKey from sqlalchemy.orm import relation -from sqlalchemy.types import Integer, Unicode +from sqlalchemy.types import DateTime, Integer, Unicode from spline.model.meta import TableBase -pass +class Forum(TableBase): + __tablename__ = 'forums' + id = Column(Integer, primary_key=True, autoincrement=True, nullable=False) + name = Column(Unicode(133), nullable=False) + +class Thread(TableBase): + __tablename__ = 'threads' + id = Column(Integer, primary_key=True, autoincrement=True, nullable=False) + forum_id = Column(Integer, ForeignKey('forums.id'), nullable=False) + subject = Column(Unicode(133), nullable=False) + +class Post(TableBase): + __tablename__ = 'posts' + id = Column(Integer, primary_key=True, autoincrement=True, nullable=False) + thread_id = Column(Integer, ForeignKey('threads.id'), nullable=False) + posted_time = Column(DateTime, nullable=False) + content = Column(Unicode(5120), nullable=False) + + +# XXX sort by time, how? +Forum.threads = relation(Thread, order_by=Thread.id.desc(), backref='forum') + +Thread.posts = relation(Post, order_by=Post.posted_time.desc(), backref='thread') diff --git a/spline/plugins/forum/templates/forum/forums.mako b/spline/plugins/forum/templates/forum/forums.mako new file mode 100644 index 0000000..37c5770 --- /dev/null +++ b/spline/plugins/forum/templates/forum/forums.mako @@ -0,0 +1,9 @@ +<%inherit file="/base.mako" /> + +<%def name="title()">Forums + + diff --git a/spline/plugins/forum/templates/forum/posts.mako b/spline/plugins/forum/templates/forum/posts.mako new file mode 100644 index 0000000..f7eca9c --- /dev/null +++ b/spline/plugins/forum/templates/forum/posts.mako @@ -0,0 +1,9 @@ +<%inherit file="/base.mako" /> + +<%def name="title()">${c.thread.subject} - ${c.thread.forum.name} - Forums + + diff --git a/spline/plugins/forum/templates/forum/threads.mako b/spline/plugins/forum/templates/forum/threads.mako new file mode 100644 index 0000000..6a63cbc --- /dev/null +++ b/spline/plugins/forum/templates/forum/threads.mako @@ -0,0 +1,9 @@ +<%inherit file="/base.mako" /> + +<%def name="title()">${c.forum.name} - Forums + +