Commits

Anonymous committed bc65f32

use basepost class

  • Participants
  • Parent commits 7e040c1
  • Branches photos

Comments (0)

Files changed (3)

newsmeme/models/photos.py

 from flask import url_for
 
 from newsmeme.extensions import db, photos, thumbs
-from newsmeme.models.posts import Post
+from newsmeme.models.posts import BasePost
 
 class _PhotoObj(object):
 
 
     @cached_property
     def url(self):
-        return self.upload_set.url(self.filename)
+        if self.filename:
+            return self.upload_set.url(self.filename)
 
     @cached_property
     def size(self):
             os.remove(self.path)
 
 
-class Photo(Post):
+class Photo(BasePost):
 
     _photo = db.Column("photo", db.String(200), unique=True)
     _thumb = db.Column("thumb", db.String(200), unique=True)

newsmeme/models/posts.py

         return self.filter(q).join(User).distinct()
 
 
-class Post(db.Model):
+class BasePost(db.Model):
 
     __tablename__ = "posts"
     
 
         @cached_property
         def view(self):
-            if self.obj.access == Post.PUBLIC:
+            if self.obj.access == self.obj.PUBLIC:
                 return Permission()
 
-            if self.obj.access == Post.FRIENDS:
+            if self.obj.access == self.obj.FRIENDS:
                 needs = [UserNeed(user_id) for user_id in \
                             self.obj.author.friends]
 
             return auth
 
     def __init__(self, *args, **kwargs):
-        super(Post, self).__init__(*args, **kwargs)
+        super(BasePost, self).__init__(*args, **kwargs)
         self.votes = self.votes or set()
         self.access = self.access or self.PUBLIC
 
     @cached_property
     def access_name(self):
         return {
-                 Post.PUBLIC : "public",
-                 Post.FRIENDS : "friends",
-                 Post.PRIVATE : "private"
+                 self.PUBLIC : "public",
+                 self.FRIENDS : "friends",
+                 self.PRIVATE : "private"
                }.get(self.access, "public")
         
     def can_access(self, user=None):
     def slug(self):
         return slugify(self.title or '')[:80]
 
+class Post(BasePost):
+
+    __mapper_args__ = {'polymorphic_identity' : 'posts'}
 
 post_tags = db.Table("post_tags", db.Model.metadata,
     db.Column("post_id", db.Integer, 

newsmeme/templates/photos/photo.html

 $(document).ready(function()
 {
 
-var maxHeight = window.innerHeight - 100;
-var maxWidth = window.innerWidth - 100;
+var maxHeight = window.innerHeight - 25;
+var maxWidth = window.innerWidth - 25;
 
 var height = maxHeight < {{ photo.photo.height }} ? maxHeight : {{ photo.photo.height }};
 var width = maxWidth < {{ photo.photo.width }} ? maxWidth : {{ photo.photo.width }};