Extremely basic forum tables and browsing.
authorEevee <git@veekun.com>
Tue, 11 May 2010 05:16:08 +0000 (22:16 -0700)
committerEevee <git@veekun.com>
Tue, 11 May 2010 05:16:08 +0000 (22:16 -0700)
migration/manage.py [changed mode: 0644->0755]
migration/versions/001_Create_basic_forum_tables.py [new file with mode: 0644]
spline/plugins/forum/__init__.py
spline/plugins/forum/controllers/forum.py
spline/plugins/forum/model/__init__.py
spline/plugins/forum/templates/forum/forums.mako [new file with mode: 0644]
spline/plugins/forum/templates/forum/posts.mako [new file with mode: 0644]
spline/plugins/forum/templates/forum/threads.mako [new file with mode: 0644]

old mode 100644 (file)
new mode 100755 (executable)
diff --git a/migration/versions/001_Create_basic_forum_tables.py b/migration/versions/001_Create_basic_forum_tables.py
new file mode 100644 (file)
index 0000000..4949fe1
--- /dev/null
@@ -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()
index a3f259e..bd48a20 100644 (file)
@@ -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)
index 6d577fb..bf66618 100644 (file)
@@ -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')
index f7d8a14..5ee242b 100644 (file)
@@ -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 (file)
index 0000000..37c5770
--- /dev/null
@@ -0,0 +1,9 @@
+<%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>
diff --git a/spline/plugins/forum/templates/forum/posts.mako b/spline/plugins/forum/templates/forum/posts.mako
new file mode 100644 (file)
index 0000000..f7eca9c
--- /dev/null
@@ -0,0 +1,9 @@
+<%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>
diff --git a/spline/plugins/forum/templates/forum/threads.mako b/spline/plugins/forum/templates/forum/threads.mako
new file mode 100644 (file)
index 0000000..6a63cbc
--- /dev/null
@@ -0,0 +1,9 @@
+<%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>