X-Git-Url: http://git.veekun.com/zzz-floof.git/blobdiff_plain/7c20a2661d532fe1e338f0f0dfb9fe42113ab103..453a7ca3b9d5e7093f843b883db58f9beb1b3aa8:/floof/model/comments.py diff --git a/floof/model/comments.py b/floof/model/comments.py index 5e57c14..08fa847 100644 --- a/floof/model/comments.py +++ b/floof/model/comments.py @@ -17,12 +17,12 @@ def indent_comments(comments): """ last_comment = None - indent = 0 + indent = 0 right_ancestry = [] for comment in comments: # If this comment is a child of the last, bump the nesting level if last_comment and comment.left < last_comment.right: - indent = indent + 1 + indent = indent + 1 # Remember current ancestory relevant to the root right_ancestry.append(last_comment) @@ -30,7 +30,7 @@ def indent_comments(comments): # broken out of, back out a level for i in xrange(len(right_ancestry) - 1, -1, -1): if comment.left > right_ancestry[i].right: - indent = indent - 1 + indent = indent - 1 right_ancestry.pop(i) # Cache parent comment @@ -52,8 +52,8 @@ class Discussion(Entity): comments = OneToMany('Comment', order_by='left') class Comment(Entity): - time = Field(DateTime, default=datetime.datetime.now) - text = Field(Unicode(65536)) + time = Field(DateTime, default=datetime.datetime.now, required=True) + text = Field(Unicode(65536), required=True) # Comments are a tree, and are stored as a nested set, because: # - It's easy to get a subtree with a single query. @@ -62,11 +62,11 @@ class Comment(Entity): # The only real disadvantage is that adding a comment requires a quick # update of all the following comments (in post-order), but that's rare # enough that it shouldn't be a problem. - left = Field(Integer, index=True) - right = Field(Integer) + left = Field(Integer, index=True, required=True) + right = Field(Integer, required=True) - discussion = ManyToOne('Discussion') - user = ManyToOne('User') + discussion = ManyToOne('Discussion', required=True) + user = ManyToOne('User', required=True) def __init__(self, parent=None, **kwargs): """Constructor override to set left/right correctly on a new comment. @@ -83,10 +83,10 @@ class Comment(Entity): # comment's left/right Comment.query.filter(Comment.discussion == self.discussion) \ .filter(Comment.left >= parent_right) \ - .update({ Comment.left: Comment.left + 2 }) + .update({ 'left': Comment.left + 2 }) Comment.query.filter(Comment.discussion == self.discussion) \ .filter(Comment.right >= parent_right) \ - .update({ Comment.right: Comment.right + 2 }) + .update({ 'right': Comment.right + 2 }) # Then stick the new comment in the right place self.left = parent_right