Browse Source

Bug fixes

sh4nks 10 years ago
parent
commit
855bf9be73
4 changed files with 17 additions and 10 deletions
  1. 3 5
      flaskbb/app.py
  2. 12 3
      flaskbb/forum/models.py
  3. 1 1
      flaskbb/user/models.py
  4. 1 1
      flaskbb/utils/decorators.py

+ 3 - 5
flaskbb/app.py

@@ -286,12 +286,10 @@ def configure_logging(app):
         @event.listens_for(Engine, "before_cursor_execute")
         def before_cursor_execute(conn, cursor, statement,
                                   parameters, context, executemany):
-            context._query_start_time = time.time()
+            conn.info.setdefault('query_start_time', []).append(time.time())
 
         @event.listens_for(Engine, "after_cursor_execute")
         def after_cursor_execute(conn, cursor, statement,
                                  parameters, context, executemany):
-            total = time.time() - context._query_start_time
-
-            # Modification for StackOverflow: times in milliseconds
-            app.logger.debug("Total Time: %.02fms" % (total * 1000))
+            total = time.time() - conn.info['query_start_time'].pop(-1)
+            app.logger.debug("Total Time: %f", total)

+ 12 - 3
flaskbb/forum/models.py

@@ -181,12 +181,13 @@ class Post(db.Model, CRUDMixin):
 
         # Adding a new post
         if user and topic:
+            created = datetime.utcnow()
             self.user_id = user.id
             self.username = user.username
             self.topic_id = topic.id
-            self.date_created = datetime.utcnow()
+            self.date_created = created
 
-            topic.last_updated = datetime.utcnow()
+            topic.last_updated = created
 
             # This needs to be done before the last_post_id gets updated.
             db.session.add(self)
@@ -200,7 +201,7 @@ class Post(db.Model, CRUDMixin):
             topic.forum.last_post_title = topic.title
             topic.forum.last_post_user_id = user.id
             topic.forum.last_post_username = user.username
-            topic.forum.last_post_created = datetime.utcnow()
+            topic.forum.last_post_created = created
 
             # Update the post counts
             user.post_count += 1
@@ -643,10 +644,18 @@ class Forum(db.Model, CRUDMixin):
             # a new last post was found in the forum
             if not last_post.id == self.last_post_id:
                 self.last_post_id = last_post.id
+                self.last_post_title = last_post.topic.title
+                self.last_post_user_id = last_post.user_id
+                self.last_post_username = last_post.username
+                self.last_post_created = last_post.date_created
 
         # No post found..
         else:
             self.last_post_id = None
+            self.last_post_title = None
+            self.last_post_user_id = None
+            self.last_post_username = None
+            self.last_post_created = None
 
         db.session.commit()
 

+ 1 - 1
flaskbb/user/models.py

@@ -412,7 +412,7 @@ class User(db.Model, UserMixin, CRUDMixin):
                        secondary groups from user.
         """
 
-        if groups:
+        if groups is not None:
             # TODO: Only remove/add groups that are selected
             secondary_groups = self.secondary_groups.all()
             for group in secondary_groups:

+ 1 - 1
flaskbb/utils/decorators.py

@@ -69,7 +69,7 @@ def can_access_topic(func):
         from flaskbb.forum.models import Forum, Topic
         from flaskbb.user.models import Group
 
-        topic = Topic.query.get(topic_id == topic_id)
+        topic = Topic.query.filter_by(id=topic_id).first()
         # get list of user group ids
         if current_user.is_authenticated():
             user_groups = [gr.id for gr in current_user.groups]