Commits

Anonymous committed 533b0aa

use basepost class

Comments (0)

Files changed (3)

newsmeme/models/__init__.py

 """   
 
 from newsmeme.models.users import User
-from newsmeme.models.posts import Post, Tag, post_tags
+from newsmeme.models.posts import BasePost, Post, Tag, post_tags
 from newsmeme.models.comments import Comment
 from newsmeme.models.photos import Photo
 

newsmeme/models/posts.py

 from newsmeme.models.types import DenormalizedText
 from newsmeme.models.users import User
 
-class PostQuery(BaseQuery):
+class BasePostQuery(BaseQuery):
 
     def jsonify(self):
         for post in self.all():
         return self.options(*options)
         
     def deadpooled(self):
-        return self.filter(Post.score <= 0)
+        return self.filter(BasePost.score <= 0)
 
     def popular(self):
-        return self.filter(Post.score > 0)
+        return self.filter(BasePost.score > 0)
     
     def hottest(self):
-        return self.order_by(Post.num_comments.desc(),
-                             Post.score.desc(),
-                             Post.id.desc())
+        return self.order_by(BasePost.num_comments.desc(),
+                             BasePost.score.desc(),
+                             BasePost.id.desc())
 
     def public(self):
-        return self.filter(Post.access==Post.PUBLIC)
+        return self.filter(BasePost.access==BasePost.PUBLIC)
 
     def restricted(self, user=None):
         """
-        Returns posts filtered for a) public posts b) posts authored by
-        the user or c) posts authored by friends
+        Returns posts filtered for a) public  b) authored by
+        the user or c) authored by friends
         """
 
         if user and user.is_moderator:
             return self
 
-        criteria = [Post.access==Post.PUBLIC]
+        criteria = [BasePost.access==BasePost.PUBLIC]
 
         if user:
-            criteria.append(Post.author_id==user.id)
+            criteria.append(BasePost.author_id==user.id)
             if user.friends:
-                criteria.append(db.and_(Post.access==Post.FRIENDS,
-                                        Post.author_id.in_(user.friends)))
+                criteria.append(db.and_(BasePost.access==BasePost.FRIENDS,
+                                        BasePost.author_id.in_(user.friends)))
         
         return self.filter(reduce(db.or_, criteria))
 
 
             keyword = '%' + keyword + '%'
 
-            criteria.append(db.or_(Post.title.ilike(keyword),
-                                   Post.description.ilike(keyword),
-                                   Post.link.ilike(keyword),
-                                   Post.tags.ilike(keyword),
+            criteria.append(db.or_(BasePost.title.ilike(keyword),
+                                   BasePost.description.ilike(keyword),
+                                   BasePost.link.ilike(keyword),
+                                   BasePost.tags.ilike(keyword),
                                    User.username.ilike(keyword)))
 
 
 
     PER_PAGE = 20
 
-    query_class = PostQuery
+    query_class = BasePostQuery
 
     id = db.Column(db.Integer, primary_key=True)
 
 
     id = db.Column(db.Integer, primary_key=True)
     slug = db.Column(db.Unicode(80), unique=True)
-    posts = db.dynamic_loader(Post, secondary=post_tags, query_class=PostQuery)
+    posts = db.dynamic_loader(BasePost, 
+                              secondary=post_tags, 
+                              query_class=BasePostQuery)
 
     _name = db.Column("name", db.Unicode(80), unique=True)
     

newsmeme/views/frontend.py

 from flaskext.mail import Message
 from flaskext.babel import gettext as _
 
-from newsmeme.models import Post, Tag
+from newsmeme.models import Post, Tag, BasePost
 from newsmeme.extensions import mail, db
 from newsmeme.helpers import render_template, cached
 from newsmeme.forms import PostForm, ContactForm
     if not keywords:
         return redirect(url_for("frontend.index"))
 
-    page_obj = Post.query.search(keywords).restricted(g.user).\
+    page_obj = BasePost.query.search(keywords).restricted(g.user).\
             as_list().paginate(page, per_page=Post.PER_PAGE)
 
     if page_obj.total == 1: