Anonymous avatar Anonymous committed bff3c4c

Add parameter for custom attachment type

Comments (0)

Files changed (2)

photos/__init__.py

 """The tgapp-photos package"""
 
 def plugme(app_config, options):
+    app_config['_pluggable_photos_config'] = options
     return dict(appid='photos', global_helpers=False)

photos/model/models.py

 
 from photos.model import DeclarativeBase
 from tgext.pluggable import app_model, primary_key, plug_url
+import tg
 
 from tgext.datahelpers.fields import Attachment, AttachedImage
 
+AttachmentType = tg.config.get('_pluggable_photos_config', {}).get('attachment_type', AttachedImage)
+
 class Gallery(DeclarativeBase):
     __tablename__ = 'photos_gallery'
-
+    
     uid = Column(Integer, nullable=False, primary_key=True)
     name = Column(Unicode(100), nullable=False)
 
 class Photo(DeclarativeBase):
     __tablename__ = 'photos_photo'
-
+    
     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))
+    
     author_id = Column(Integer, ForeignKey(primary_key(app_model.User)))
     author = relation(app_model.User, backref=backref('photos'))
-
+    
     gallery_id = Column(Integer, ForeignKey(Gallery.uid))
     gallery = relation(Gallery, backref=backref('photos', cascade='all, delete-orphan'))
-
+    
     def url(self, inline):
         if inline:
             return self.image.url
         else:
-            return plug_url('photos', '/photo/%s' % self.uid)
+            return plug_url('photos', '/photo/%s' % self.uid)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.