Browse Source

Added *_id to the forum views args.

sh4nks 11 years ago
parent
commit
6cad06e876

+ 3 - 4
flaskbb/forum/models.py

@@ -89,7 +89,7 @@ class Topic(db.Model):
     locked = db.Column(db.Boolean, default=False)
     important = db.Column(db.Boolean, default=False)
     views = db.Column(db.Integer, default=0)
-    post_count = db.Column(db.Integer, default=0) # bb normalization
+    post_count = db.Column(db.Integer, default=0)
 
     # One-to-one (uselist=False) relationship between first_post and topic
     first_post_id = db.Column(db.Integer, db.ForeignKey("posts.id", ondelete="CASCADE"))
@@ -102,7 +102,6 @@ class Topic(db.Model):
     # One-to-many
     posts = db.relationship("Post", backref="topic", lazy="joined", primaryjoin="Post.topic_id == Topic.id", cascade="all, delete-orphan", post_update=True)
 
-
     def __init__(self, title=None):
         if title:
             self.title = title
@@ -118,8 +117,8 @@ class Topic(db.Model):
         # Updates the topic - Because the thread title (by intention)
         # isn't change able, so we are just going to update the post content
         if self.id:
-            # untested
-            post.save(self)
+            db.session.add(self)
+            db.session.commit()
             return self
 
         # Set the forum and user id

+ 35 - 32
flaskbb/forum/views.py

@@ -41,18 +41,18 @@ def index():
                                   'newest_user': newest_user.username})
 
 
-@forum.route("/category/<int:category>")
-def view_category(category):
-    category = Category.query.filter_by(id=category).first()
+@forum.route("/category/<int:category_id>")
+def view_category(category_id):
+    category = Category.query.filter_by(id=category_id).first()
 
     return render_template("forum/category.html", category=category)
 
 
-@forum.route("/forum/<int:forum>")
-def view_forum(forum):
+@forum.route("/forum/<int:forum_id>")
+def view_forum(forum_id):
     page = request.args.get('page', 1, type=int)
 
-    forum = Forum.query.filter_by(id=forum).first()
+    forum = Forum.query.filter_by(id=forum_id).first()
     topics = Topic.query.filter_by(forum_id=forum.id).\
         order_by(Topic.last_post_id.desc()).\
         paginate(page, current_app.config['TOPICS_PER_PAGE'], False)
@@ -60,16 +60,19 @@ def view_forum(forum):
     return render_template("forum/forum.html", forum=forum, topics=topics)
 
 
-@forum.route("/topic/<int:topic>", methods=["POST", "GET"])
-def view_topic(topic):
+@forum.route("/topic/<int:topic_id>", methods=["POST", "GET"])
+def view_topic(topic_id):
     page = request.args.get('page', 1, type=int)
 
-    form = QuickreplyForm()
-
-    topic = Topic.query.filter_by(id=topic).first()
+    topic = Topic.query.filter_by(id=topic_id).first()
     posts = Post.query.filter_by(topic_id=topic.id).\
         paginate(page, current_app.config['POSTS_PER_PAGE'], False)
 
+    # Count the topic views
+    topic.views += 1
+    topic.save()
+
+    form = QuickreplyForm()
     if form.validate_on_submit():
         post = form.save(current_user, topic)
         return view_post(post.id)
@@ -79,25 +82,25 @@ def view_topic(topic):
                            form=form)
 
 
-@forum.route("/post/<int:post>")
-def view_post(post):
-    post = Post.query.filter_by(id=post).first()
+@forum.route("/post/<int:post_id>")
+def view_post(post_id):
+    post = Post.query.filter_by(id=post_id).first()
     count = post.topic.post_count
     page = math.ceil(count / current_app.config["POSTS_PER_PAGE"])
     if count > 10:
         page += 1
     else:
-       page = 1
+        page = 1
 
-    return redirect(url_for("forum.view_topic", topic=post.topic.id) +
+    return redirect(url_for("forum.view_topic", topic_id=post.topic.id) +
                     "?page=%d#pid%s" % (page, post.id))
 
 
-@forum.route("/forum/<int:forum>/topic/new", methods=["POST", "GET"])
+@forum.route("/forum/<int:forum_id>/topic/new", methods=["POST", "GET"])
 @login_required
-def new_topic(forum):
+def new_topic(forum_id):
     form = NewTopicForm()
-    forum = Forum.query.filter_by(id=forum).first()
+    forum = Forum.query.filter_by(id=forum_id).first()
 
     if form.validate_on_submit():
         topic = form.save(current_user, forum)
@@ -107,21 +110,21 @@ def new_topic(forum):
     return render_template("forum/new_topic.html", forum=forum, form=form)
 
 
-@forum.route("/topic/<int:topic>/delete")
+@forum.route("/topic/<int:topic_id>/delete")
 @login_required
-def delete_topic(topic):
-    topic = Topic.query.filter_by(id=topic).first()
+def delete_topic(topic_id):
+    topic = Topic.query.filter_by(id=topic_id).first()
     involved_users = User.query.filter(Post.topic_id == topic.id,
                                        User.id == Post.user_id).all()
     topic.delete(users=involved_users)
     return redirect(url_for("forum.view_forum", forum=topic.forum_id))
 
 
-@forum.route("/topic/<int:topic>/post/new", methods=["POST", "GET"])
+@forum.route("/topic/<int:topic_id>/post/new", methods=["POST", "GET"])
 @login_required
-def new_post(topic):
+def new_post(topic_id):
     form = ReplyForm()
-    topic = Topic.query.filter_by(id=topic).first()
+    topic = Topic.query.filter_by(id=topic_id).first()
 
     if form.validate_on_submit():
         post = form.save(current_user, topic)
@@ -130,10 +133,10 @@ def new_post(topic):
     return render_template("forum/new_post.html", topic=topic, form=form)
 
 
-@forum.route("/post/<int:post>/edit", methods=["POST", "GET"])
+@forum.route("/post/<int:post_id>/edit", methods=["POST", "GET"])
 @login_required
-def edit_post(post):
-    post = Post.query.filter_by(id=post).first()
+def edit_post(post_id):
+    post = Post.query.filter_by(id=post_id).first()
 
     form = ReplyForm(obj=post)
     if form.validate_on_submit():
@@ -147,10 +150,10 @@ def edit_post(post):
     return render_template("forum/new_post.html", topic=post.topic, form=form)
 
 
-@forum.route("/post/<int:post>/delete")
+@forum.route("/post/<int:post_id>/delete")
 @login_required
-def delete_post(post):
-    post = Post.query.filter_by(id=post).first()
+def delete_post(post_id):
+    post = Post.query.filter_by(id=post_id).first()
     topic_id = post.topic_id
 
     post.delete()
@@ -158,7 +161,7 @@ def delete_post(post):
     # If the post was the first post in the topic, redirect to the forums
     if post.first_post:
         return redirect(url_for('forum.view_forum',
-                                 forum=post.topic.forum_id))
+                                forum=post.topic.forum_id))
     return redirect(url_for('forum.view_topic', topic=topic_id))
 
 

+ 3 - 3
flaskbb/templates/forum/category_layout.html

@@ -2,7 +2,7 @@
     <thead class="categoryhead">
         <tr>
             <td colspan="5">
-                <div><strong><a href="{{ url_for('forum.view_category', category=category.id) }}">{{ category.title }}</a></strong></div>
+                <div><strong><a href="{{ url_for('forum.view_category', category_id=category.id) }}">{{ category.title }}</a></strong></div>
             </td>
         </tr>
     </thead>
@@ -19,7 +19,7 @@
             <td align="center" valign="center" width="1">INSERT IMAGE</td>
 
             <td valign="top">
-                <strong><a href="{{ url_for('forum.view_forum', forum=forum.id) }}">{{ forum.title }}</a></strong>
+                <strong><a href="{{ url_for('forum.view_forum', forum_id=forum.id) }}">{{ forum.title }}</a></strong>
 
                 <div class="forum-description">
                     {{ forum.description }}<br />
@@ -35,7 +35,7 @@
 
             <td valign="top" align="right" style="white-space: nowrap">
                 {% if forum.last_post_id %}
-                <a href="{{ url_for('forum.view_post', post=forum.last_post_id) }}" title="{{ forum.last_post.topic.title }}">
+                <a href="{{ url_for('forum.view_post', post_id=forum.last_post_id) }}" title="{{ forum.last_post.topic.title }}">
                     <strong>{{ forum.last_post.topic.title }}</strong>
                 </a>
                 <br />

+ 5 - 5
flaskbb/templates/forum/forum.html

@@ -7,17 +7,17 @@
 
 <ol class="breadcrumb">
     <li><a href="{{ url_for('forum.index') }}">Forum</a></li>
-    <li><a href="{{ url_for('forum.view_category', category=forum.category_id) }}">{{ forum.category.title }}</a></li>
+    <li><a href="{{ url_for('forum.view_category', category_id=forum.category_id) }}">{{ forum.category.title }}</a></li>
     <li class="active">{{ forum.title }}</li>
 </ol>
 
 <div class="pull-left" style="padding-bottom: 10px">
-    {{ render_pagination(topics, url_for('forum.view_forum', forum=forum.id)) }}
+    {{ render_pagination(topics, url_for('forum.view_forum', forum_id=forum.id)) }}
 </div> <!-- end span pagination -->
 
 {% if current_user.is_authenticated() %}
 <div class="pull-right" style="padding-bottom: 10px">
-    <a href="{{ url_for('forum.new_topic', forum=forum.id) }}" class="btn btn-primary">New Topic</a>
+    <a href="{{ url_for('forum.new_topic', forum_id=forum.id) }}" class="btn btn-primary">New Topic</a>
 </div>
 {% endif %}
 <table class="table table-bordered">
@@ -44,7 +44,7 @@
             <td width="4%"></td>
             <td>
                 <div>
-                    <a href="{{ url_for('forum.view_topic', topic=topic.id) }}">{{ topic.title }}</a> <br />
+                    <a href="{{ url_for('forum.view_topic', topic_id=topic.id) }}">{{ topic.title }}</a> <br />
                     <small>by <a href="{{ url_for('user.profile', username=topic.user.username) }}">{{ topic.user.username }}</a></small>
                 </div>
             </td>
@@ -55,7 +55,7 @@
                 {{ topic.views }}
             </td>
             <td>
-                <a href="{{ url_for('forum.view_post', post=topic.last_post.id) }}">{{ topic.last_post.date_created|time_since }}</a><br />
+                <a href="{{ url_for('forum.view_post', post_id=topic.last_post.id) }}">{{ topic.last_post.date_created|time_since }}</a><br />
                 <small>by <a href="{{ url_for('user.profile', username=topic.last_post.user.username) }}">{{ topic.last_post.user.username }}</a></small>
             </td>
         </tr>

+ 3 - 3
flaskbb/templates/forum/new_post.html

@@ -6,9 +6,9 @@
 
 <ul class="breadcrumb">
     <li><a href="{{ url_for('forum.index') }}">Forum</a></li>
-    <li><a href="{{ url_for('forum.view_category', category=topic.forum.category.id) }}">{{ topic.forum.category.title }}</a></li>
-    <li><a href="{{ url_for('forum.view_forum', forum=topic.forum_id) }}">{{ topic.forum.title }}</a></li>
-    <li><a href="{{ url_for('forum.view_topic', topic=topic.id) }}">{{ topic.title }} </a></li>
+    <li><a href="{{ url_for('forum.view_category', category_id=topic.forum.category.id) }}">{{ topic.forum.category.title }}</a></li>
+    <li><a href="{{ url_for('forum.view_forum', forum_id=topic.forum_id) }}">{{ topic.forum.title }}</a></li>
+    <li><a href="{{ url_for('forum.view_topic', topic_id=topic.id) }}">{{ topic.title }} </a></li>
     <li class="active">New Post</li>
 </ul>
 

+ 2 - 2
flaskbb/templates/forum/new_topic.html

@@ -7,8 +7,8 @@
 
 <ul class="breadcrumb">
     <li><a href="{{ url_for('forum.index') }}">Forum</a></li>
-    <li><a href="{{ url_for('forum.view_category', category=forum.category_id) }}">{{ forum.category.title }}</a></li>
-    <li><a href="{{ url_for('forum.view_forum', forum=forum.id) }}">{{ forum.title }}</a> </li>
+    <li><a href="{{ url_for('forum.view_category', category_id=forum.category_id) }}">{{ forum.category.title }}</a></li>
+    <li><a href="{{ url_for('forum.view_forum', forum_id=forum.id) }}">{{ forum.title }}</a> </li>
     <li class="active">New Topic</li>
 </ul>
 

+ 9 - 9
flaskbb/templates/forum/topic.html

@@ -7,20 +7,20 @@
 
 <ol class="breadcrumb">
     <li><a href="{{ url_for('forum.index') }}">Forum</a></li>
-    <li><a href="{{ url_for('forum.view_category', category=topic.forum.category.id) }}">{{ topic.forum.category.title }}</a></li>
-    <li><a href="{{ url_for('forum.view_forum', forum=topic.forum_id) }}">{{ topic.forum.title }}</a></li>
+    <li><a href="{{ url_for('forum.view_category', category_id=topic.forum.category.id) }}">{{ topic.forum.category.title }}</a></li>
+    <li><a href="{{ url_for('forum.view_forum', forum_id=topic.forum_id) }}">{{ topic.forum.title }}</a></li>
     <li class="active">{{ topic.title }}</li>
 </ol>
 
 <div class="pull-left" style="padding-bottom: 10px">
-    {{ render_pagination(posts, url_for('forum.view_topic', topic=topic.id)) }}
+    {{ render_pagination(posts, url_for('forum.view_topic', topic_id=topic.id)) }}
 </div> <!-- end span pagination -->
 
 {% if current_user.is_authenticated() %}
 <div class="pull-right" style="padding-bottom: 10px">
-    <a href="{{ url_for('forum.new_post', topic=topic.id) }}" class="btn btn-primary">Reply</a>
+    <a href="{{ url_for('forum.new_post', topic_id=topic.id) }}" class="btn btn-primary">Reply</a>
     {% if current_user.id == topic.user_id %}
-    <a href="{{ url_for('forum.delete_topic', topic=topic.id) }}" class="btn btn-primary">Delete Topic</a>
+    <a href="{{ url_for('forum.delete_topic', topic_id=topic.id) }}" class="btn btn-primary">Delete Topic</a>
     {% endif %}
 </div>
 {% endif %}
@@ -36,9 +36,9 @@
                 <span class="pull-left">
                     <a href="
                     {% if posts.page > 1 %}
-                        {{ url_for('forum.view_topic', topic=topic.id) }}?page={{ posts.page }}#pid{{ post.id }}
+                        {{ url_for('forum.view_topic', topic_id=topic.id) }}?page={{ posts.page }}#pid{{ post.id }}
                     {% else %}
-                        {{ url_for('forum.view_topic', topic=topic.id) }}#pid{{ post.id }}
+                        {{ url_for('forum.view_topic', topic_id=topic.id) }}#pid{{ post.id }}
                     {% endif %}
                         ">{{ post.date_created|format_date('%d %B %Y') }}</a>
                     {% if post.date_modified %}
@@ -99,8 +99,8 @@
 
                 <span class="pull-right">
                     {% if current_user.is_authenticated() and current_user.id == post.user_id %}
-                    <a href="{{ url_for('forum.edit_post', post=post.id) }}">Edit</a> |
-                    <a href="{{ url_for('forum.delete_post', post=post.id) }}">Delete</a> |
+                    <a href="{{ url_for('forum.edit_post', post_id=post.id) }}">Edit</a> |
+                    <a href="{{ url_for('forum.delete_post', post_id=post.id) }}">Delete</a> |
                     {% endif %}
                     <a href="#">Quote</a> |
                     <a href="#">Report</a> |

+ 2 - 2
flaskbb/templates/user/all_posts.html

@@ -16,8 +16,8 @@
     {% for post in posts.items %}
         <tr>
             <td>
-                <strong><a href="{{ url_for('forum.view_topic', topic=post.topic.id)}}">{{ post.topic.title }}</a></strong>
-                in <a href="{{ url_for('forum.view_forum', forum=post.topic.forum.id) }}">{{ post.topic.forum.title }}</a>
+                <strong><a href="{{ url_for('forum.view_topic', topic_id=post.topic.id)}}">{{ post.topic.title }}</a></strong>
+                in <a href="{{ url_for('forum.view_forum', forum_id=post.topic.forum.id) }}">{{ post.topic.forum.title }}</a>
                 <span class="divider"> - </span>
                 <small>{{ post.date_created|time_since }}</small>
             </td>

+ 2 - 2
flaskbb/templates/user/all_topics.html

@@ -37,7 +37,7 @@
             <td width="4%"></td>
             <td>
                 <div>
-                    <a href="{{ url_for('forum.view_topic', topic=topic.id) }}">{{ topic.title }}</a> <br />
+                    <a href="{{ url_for('forum.view_topic', topic_id=topic.id) }}">{{ topic.title }}</a> <br />
                     <small>by <a href="{{ url_for('user.profile', username=topic.user.username) }}">{{ topic.user.username }}</a></small>
                 </div>
             </td>
@@ -48,7 +48,7 @@
                 {{ topic.views }}
             </td>
             <td>
-                <a href="{{ url_for('forum.view_topic', topic=topic.id) }}#pid{{topic.last_post.id}}">{{ topic.last_post.date_created|time_since }}</a><br />
+                <a href="{{ url_for('forum.view_topic', topic_id=topic.id) }}#pid{{topic.last_post.id}}">{{ topic.last_post.date_created|time_since }}</a><br />
                 <small>by <a href="{{ url_for('user.profile', username=topic.last_post.user.username) }}">{{ topic.last_post.user.username }}</a></small>
             </td>
         </tr>

+ 1 - 1
flaskbb/templates/user/profile.html

@@ -47,7 +47,7 @@
                 <tr>
                   <td align="right">Last post:</td>
                   <td>{%- if user.last_post -%}
-                      <a href="{{ url_for('forum.view_post', post=user.last_post.id) }}">{{ user.last_post.date_created|time_since }}</a>
+                      <a href="{{ url_for('forum.view_post', post_id=user.last_post.id) }}">{{ user.last_post.date_created|time_since }}</a>
                       {%- else -%}
                         Never
                       {%- endif -%}