class IPhotoGallerySettings(model.Schema): """Schema for the control panel form.""" enable_download = schema.Bool( title=_(u'Enable image download globally?'), description= _(u'Enable download of original images in photo galleries by using an explicit link. ' u'If ftw.zipexport is installed, enable also downloading of a ZIP file with all the images.' ), default=False)
def zip_selected(self, objects): if not HAS_ZIPEXPORT: return None response = self.request.response with ZipGenerator() as generator: for obj in objects: repre = getMultiAdapter((obj, self.request), interface=IZipRepresentation) for path, pointer in repre.get_files(): generator.add_file(path, pointer) # check if zip has files if generator.is_empty: message = _( u'Zip export is not supported on the selected content.') api.portal.show_message(message, self.request, type=u'error') self.request.response.redirect(self.context.absolute_url()) return zip_file = generator.generate() response.setHeader('Content-Disposition', 'inline; filename="{0}"'.format(self.filename)) response.setHeader('Content-type', 'application/zip') response.setHeader('Content-Length', os.stat(zip_file.name).st_size) return filestream_iterator(zip_file.name, 'rb')
def zip_selected(self, objects): if not HAS_ZIPEXPORT: return None response = self.request.response with ZipGenerator() as generator: for obj in objects: repre = getMultiAdapter( (obj, self.request), interface=IZipRepresentation) for path, pointer in repre.get_files(): generator.add_file(path, pointer) # check if zip has files if generator.is_empty: message = _(u'Zip export is not supported on the selected content.') api.portal.show_message(message, self.request, type=u'error') self.request.response.redirect(self.context.absolute_url()) return zip_file = generator.generate() response.setHeader( 'Content-Disposition', 'inline; filename="{0}"'.format(self.filename)) response.setHeader('Content-type', 'application/zip') response.setHeader('Content-Length', os.stat(zip_file.name).st_size) return filestream_iterator(zip_file.name, 'rb')
def __call__(self): if HAS_ZIPEXPORT and self.filename: return self.zip_selected([self.context]) else: message = _(u'Operation not supported.') api.portal.show_message(message, self.request, type=u'error') self.request.response.redirect(self.context.absolute_url()) return
class IPhotoGallery(model.Schema): """A Photo Gallery content type with a slideshow view.""" text = RichText( title=_(u'Body text'), required=False, ) model.fieldset('settings', label=__(u'Settings'), fields=['allow_download']) allow_download = schema.Bool( title=_(u'Allow image download?'), description=_( u'Allow downloading of original images on this photo gallery.'), default=True, )
class IPhotoGalleryTile(IPersistentCoverTile): """A tile that shows a photo gallery.""" uuid = schema.TextLine( title=_(u'UUID'), required=False, readonly=True, )
class IPhotoGallery(model.Schema): """A Photo Gallery content type with a slideshow view.""" labels = schema.List(title=_(u"Etiquetes"), description=_(u"Introduiu les etiquetes a mostrar"), required=False, value_type=schema.Choice( vocabulary=u'plone.app.vocabularies.Keywords')) text = RichText( title=_(u'Body text'), required=False, ) model.fieldset('settings', label=__(u'Settings'), fields=['allow_download']) allow_download = schema.Bool( title=_(u'Allow image download?'), description=_( u'Allow downloading of original images on this photo gallery.'), default=True, )
class PhotoGalleryTile(PersistentCoverTile, PhotoGalleryMixin): """A tile that shows a photo gallery.""" implements(IPhotoGalleryTile) index = ViewPageTemplateFile('photogallery.pt') is_configurable = True is_editable = False is_droppable = True short_name = _(u'msg_short_name_photogallery', u'Photo Gallery') def accepted_ct(self): """Accept only Photo Gallery objects.""" return ['Photo Gallery'] def populate_with_object(self, obj): super(PhotoGalleryTile, self).populate_with_object(obj) # check permissions if obj.portal_type in self.accepted_ct(): uuid = IUUID(obj) data_mgr = ITileDataManager(self) data_mgr.set(dict(uuid=uuid)) def is_empty(self): return (self.data.get('uuid', None) is None or uuidToObject(self.data.get('uuid')) is None) @view.memoize def gallery(self): return uuidToObject(self.data.get('uuid')) @view.memoize def results(self): gallery = self.gallery() return gallery.listFolderContents() def image(self, obj, scale='large'): """Return an image scale if the item has an image field. :param obj: [required] :type obj: content type object :param scale: the scale to be used :type scale: string """ scales = obj.restrictedTraverse('@@images') return scales.scale('image', scale)
class PhotoGallerySettingsEditForm(controlpanel.RegistryEditForm): """Control panel edit form.""" schema = IPhotoGallerySettings label = _(u'Photo Gallery') description = _(u'Settings for the sc.photogallery package')