def add_zip_with_non_standard_mimetype(self): """ This is a normal zip file but with a non standard zip mimetype """ self.file = create( Builder('file').titled(u'multizip').attach_file_containing( self.asset('multi.zip'), u'multi.zip').within(self.folder)) if IDexterityItem.providedBy(self.file): self.file.file.contentType = 'application/x-zip-compressed' else: self.file.getFile().setContentType('application/x-zip-compressed')
def container_url(self): context = self.context if IDexterityItem.providedBy(context): context = aq_parent(context) return context.absolute_url()
def __init__(self, toolbar): super(FolderMenuItem, self).__init__(toolbar) if IDexterityItem.providedBy(self.context): self.context = aq_parent(self.context)
def _render_obj(self, obj): """ Render object to string. """ if isinstance(obj, basestring): return obj ## 'plone.global_sections' viewlet uses request['URL'] highlight ## selected tab, so it must be overridden but only for a while initial_url = self.request['URL'] try: obj_url = obj.absolute_url() except AttributeError: try: obj_url = obj.context.absolute_url() except AttributeError: obj_url = None if obj_url: self.request['URL'] = obj_url ## breadcrumb implementation in quills uses 'PARENTS', so it must ## be overriden but ony for a while initial_parents = self.request['PARENTS'] if hasattr(obj, 'aq_chain'): self.request['PARENTS'] = obj.aq_chain try: if IResource.providedBy(obj): try: f = open(obj.context.path) result = f.read() f.close() except IOError: log.error("Couldn't open '%s' file with resource" % obj.context.path) return None return result if isinstance(obj, (BrowserView, FSPageTemplate, PythonScript)): try: return obj() except NotFound: log.error("Resource '%s' not found" % repr(obj)) return None if isinstance(obj, (FSFile, FSImage)): return self._render_obj(obj._readFile(None)) if isinstance(obj, FSDTMLMethod): return self._render_obj(obj.read()) mt = None try: mt = obj.aq_base.meta_type except AttributeError: pass if mt in self.file_types or isinstance(obj, (ImageField, OFSImage, Pdata, File)): return self._render_obj(obj.data) if PLONE_RESOURCE_INSTALLED and isinstance(obj, FilesystemFile): if not obj.request: obj.request = self.request return obj().read() if PLONE_APP_BLOB_INSTALLED and IBlobWrapper.providedBy(obj): return obj.data if IBaseObject.providedBy(obj) or isinstance(obj, PloneSite) or \ (PLONE_DEXTERITY_INSTALLED and IDexterityItem.providedBy(obj)): def_page_id = obj.getDefaultPage() if def_page_id: def_page = obj[def_page_id] return self._render_obj(def_page) view_name = obj.getLayout() view = queryMultiAdapter((obj, self.request), name=view_name) if view_name == 'language-switcher': lang = self.request.get('LANGUAGE') def_page = getattr(obj, lang, None) if def_page: return self._render_obj(def_page) if view: try: return view.context() except (ContentProviderLookupError, TypeError): pass view = obj.restrictedTraverse(view_name, None) if view: try: return view.context() except (AttributeError, TypeError): try: return view() except Exception, error: log.warning("Unable to render view: '%s'! Error occurred: %s" % (view, error)) pass else: try: return obj() except AttributeError: pass finally: ## back to initial url if obj_url: self.request['URL'] = initial_url ## back to initial parents self.request['PARENTS'] = initial_parents log.warning("Not recognized object '%s'!" % repr(obj)) return None