--- /dev/null
+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()
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):
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)
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')
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')
--- /dev/null
+<%inherit file="/base.mako" />
+
+<%def name="title()">Forums</%def>
+
+<ul class="classic-list">
+ % for forum in c.forums:
+ <li><a href="${url(controller='forum', action='threads', forum_id=forum.id)}">${forum.name}</a></li>
+ % endfor
+</ul>
--- /dev/null
+<%inherit file="/base.mako" />
+
+<%def name="title()">${c.thread.subject} - ${c.thread.forum.name} - Forums</%def>
+
+<ul class="classic-list">
+ % for post in c.thread.posts:
+ <li><blockquote>${post.content}</blockquote></li>
+ % endfor
+</ul>
--- /dev/null
+<%inherit file="/base.mako" />
+
+<%def name="title()">${c.forum.name} - Forums</%def>
+
+<ul class="classic-list">
+ % for thread in c.forum.threads:
+ <li><a href="${url(controller='forum', action='posts', forum_id=c.forum.id, thread_id=thread.id)}">${thread.subject}</a></li>
+ % endfor
+</ul>