Commits

Anonymous committed 633a14a

Add parameter for custom attachment type

  • Participants
  • Parent commits 298c904

Comments (0)

Files changed (1)

File fbcontest/model/models.py

 from tgext.datahelpers.fields import Attachment, AttachedImage
 from datetime import datetime
 
+AttachmentType = tg.config.get('_pluggable_fbcontest_config', {}).get('attachment_type', AttachedImage)
+
 class FacebookContest(DeclarativeBase):
     __tablename__ = 'facebook_contest'
-
+    
     uid = Column(Integer, nullable=False, primary_key=True)
     name = Column(Unicode(100), nullable=False)
     deadline = Column(DateTime, nullable=False)
     description = Column(Unicode(2048), nullable=False)
-
+    
     @cached_property
     def cover(self):
         cover = app_model.DBSession.query(FacebookContestItem).filter_by(contest_id=self.uid)\
-                                                             .order_by(FacebookContestItem.likes.desc()).first()
+            .order_by(FacebookContestItem.likes.desc()).first()
         if not cover:
             return tg.url('/_pluggable/fbcontest/images/contest.jpg')
         return cover.image.thumb_url
-
+    
     @cached_property
     def finished(self):
         return self.deadline and datetime.now() >= self.deadline
 
 class FacebookContestItem(DeclarativeBase):
     __tablename__ = 'facebook_contest_item'
-
+    
     uid = Column(Integer, nullable=False, primary_key=True)
     name = Column(Unicode(100), nullable=False)
     description = Column(Unicode(2048), nullable=False)
-    image = Column(Attachment(AttachedImage))
+    image = Column(Attachment(AttachmentType))
     likes = Column(Integer, nullable=False, default=0)
-
+    
     contest_id = Column(Integer, ForeignKey(FacebookContest.uid))
     contest = relation(FacebookContest, backref=backref('items', order_by="FacebookContestItem.likes.desc()",
-                                                                 cascade='all, delete-orphan'))
-
+                                                        cascade='all, delete-orphan'))
+    
     def url(self, inline):
         if inline:
             return self.image.url