def get_content(self): haunted = self.context.get_haunted() if haunted is not None: if IPreviewLayer.providedBy(haunted.REQUEST): return haunted.get_previewable() return haunted.get_viewable() return None
def render(self, preview=None): if preview is None: preview = IPreviewLayer.providedBy(self.request) if preview: return "".join( ("<p>", translate(self.context.message(), context=self.request), "</p>")) return ""
def update(self, preview=None): if preview is None: preview = IPreviewLayer.providedBy(self.request) self.preview = preview self.title = self.context.manager.label self.info = self.context.info self.manage = checkPermission( 'silva.ManageSilvaSettings', self.context.manager.context)
def render(self, preview=None): if preview is None: preview = IPreviewLayer.providedBy(self.request) if preview: return u"".join( ("<p>", translate(self.context.message(), context=self.request), "</p>")) return u""
def __init__(self, context): super(Metadata, self).__init__(context) self._service = getUtility(IMetadataService) self._content = None # XXX Should be a view # XXX Should be the previewable version ? if (hasattr(context, 'REQUEST') and IPreviewLayer.providedBy(context.REQUEST)): sm = getSecurityManager() if sm.checkPermission(ChangeSilvaContent, context): self._content = context.get_editable() if self._content is None: self._content = context.get_viewable()
def render(self): public = not IPreviewLayer.providedBy(self.request) # XXX This code should be made readable. is_displayable = public and self.is_public_displayable or self.is_preview_displayable html = [] a_templ = '<a href="%s">%s %s</a>' img_tag = '' depth = -1 prev_depth = [-1] gmv = self.context.service_metadata.getMetadataValue item = None get_icon_tag = IIconResolver(self.request).get_tag for (depth, item) in self.list_toc_items(self.toc_container, 0, is_displayable): pd = prev_depth[-1] if pd < depth: #down one level html.append('<ul class="toc">') prev_depth.append(depth) elif pd > depth: #up one level for i in range(pd - depth): prev_depth.pop() html.append('</ul></li>') elif pd == depth: #same level html.append('</li>') html.append('<li>') if self.toc_show_icon: img_tag = get_icon_tag(item) title = (public and item.get_title() or item.get_title_editable()) or item.id html.append( a_templ % (absoluteURL(item, self.request), img_tag, escape(title))) if self.toc_show_description: v = public and item.get_viewable() or item.get_previewable() desc = v and gmv( v, 'silva-extra', 'content_description', acquire=0) if desc: html.append('<p>%s</p>' % desc) else: #do this when the loop is finished, to #ensure that the lists are ended properly #the last item in the list could part of a nested list (with depth 1,2,3+, etc) #so need to loop down the depth and close all open lists while depth >= 0: html.append('</li></ul>') depth -= 1 return u'\n'.join(html)
def get_releases(self): self.deprecated = self.context.is_package_deprecated self.version_matrix = self.context.package_version_matrix releases = [] publishables = self.content.get_ordered_publishables() publishables = [ obj for obj in publishables if interfaces.ISilvaSoftwareRelease.providedBy(obj) ] if not IPreviewLayer.providedBy(self.request): publishables = [ obj for obj in publishables if obj.get_default().get_public_version() ] def sort_by_version(a, b): return -cmp(parse_version(a.id), parse_version(b.id)) publishables.sort(sort_by_version) def file_detail(entry): return { 'name': entry.get_filename(), 'url': absoluteURL(entry, self.request) } def remote_detail(entry): viewable = entry.get_viewable() if viewable is not None: return {'name': entry.getId(), 'url': viewable.get_url()} return {'name': None, 'url': None} locale = self.request.locale format = locale.dates.getFormatter('dateTime', 'medium').format for entry in publishables: crea_date = entry.get_default().get_creation_datetime() files = filter(lambda info: info['name'] is not None, map(remote_detail, entry.get_remote_files())) + \ map(file_detail, entry.get_files()) releases.append({ 'name': self.content.get_title() + ' ' + entry.id, 'url': absoluteURL(entry, self.request), 'date': format(crea_date.asdatetime()), 'files': files }) return releases
def render(self): public = not IPreviewLayer.providedBy(self.request) # XXX This code should be made readable. is_displayable = public and self.is_public_displayable or self.is_preview_displayable html = [] a_templ = '<a href="%s">%s %s</a>' img_tag = '' depth = -1 prev_depth = [-1] gmv = self.context.service_metadata.getMetadataValue item = None get_icon_tag = IIconResolver(self.request).get_tag for (depth, item) in self.list_toc_items(self.toc_container, 0, is_displayable): pd = prev_depth[-1] if pd < depth: #down one level html.append('<ul class="toc">') prev_depth.append(depth) elif pd > depth: #up one level for i in range(pd-depth): prev_depth.pop() html.append('</ul></li>') elif pd == depth: #same level html.append('</li>') html.append('<li>') if self.toc_show_icon: img_tag = get_icon_tag(item) title = (public and item.get_title() or item.get_title_editable()) or item.id html.append(a_templ % (absoluteURL(item, self.request), img_tag, escape(title))) if self.toc_show_description: v = public and item.get_viewable() or item.get_previewable() desc = v and gmv(v,'silva-extra','content_description', acquire=0) if desc: html.append('<p>%s</p>'%desc) else: #do this when the loop is finished, to #ensure that the lists are ended properly #the last item in the list could part of a nested list (with depth 1,2,3+, etc) #so need to loop down the depth and close all open lists while depth >= 0: html.append('</li></ul>') depth -= 1 return u'\n'.join(html)
def render(self): to_ignore = [entry.strip() for entry in self.to_ignore.split(',')] public = not IPreviewLayer.providedBy(self.request) is_displayable = public and self.is_public_displayable or self.is_preview_displayable html = [] a_templ = '<a href="%s">%s</a>' isIndented = int(self.list_type) localRoot = getLocalSite(self.model, self.request) depth = -1 prev_depth = [-1] item = None for (depth, item) in self.list_toc_items(localRoot, 0, is_displayable, to_ignore): pd = prev_depth[-1] if pd < depth: #down one level if depth == 0 or isIndented: html.append('<ul>') prev_depth.append(depth) elif pd > depth: #up one level for i in range(pd-depth): prev_depth.pop() if isIndented: html.append('</ul></li>') elif pd == depth: #same level html.append('</li>') css_class = (IContainer.providedBy(item) and depth == 0) and ' class="topContainer"' or '' html.append('<li%s>' %css_class) title = (public and item.get_title() or item.get_title_editable()) or item.id html.append(a_templ % (absoluteURL(item, self.request), escape(title)) + self._add(item)) else: #do this when the loop is finished, to #ensure that the lists are ended properly #the last item in the list could part of a nested list (with depth 1,2,3+, etc) #so need to loop down the depth and close all open lists while depth >= 0: html.append('</li></ul>') depth -= 1 if not isIndented: html.append('</ul>') return u'\n'.join(html)
def get_releases(self): self.deprecated = self.context.is_package_deprecated self.version_matrix = self.context.package_version_matrix releases = [] publishables = self.content.get_ordered_publishables() publishables = [obj for obj in publishables if interfaces.ISilvaSoftwareRelease.providedBy(obj)] if not IPreviewLayer.providedBy(self.request): publishables = [obj for obj in publishables if obj.get_default().get_public_version()] def sort_by_version(a, b): return -cmp(parse_version(a.id), parse_version(b.id)) publishables.sort(sort_by_version) def file_detail(entry): return {'name': entry.get_filename(), 'url': absoluteURL(entry, self.request)} def remote_detail(entry): viewable = entry.get_viewable() if viewable is not None: return {'name': entry.getId(), 'url': viewable.get_url()} return {'name': None, 'url': None} locale = self.request.locale format = locale.dates.getFormatter('dateTime', 'medium').format for entry in publishables: crea_date = entry.get_default().get_creation_datetime() files = filter(lambda info: info['name'] is not None, map(remote_detail, entry.get_remote_files())) + \ map(file_detail, entry.get_files()) releases.append({'name': self.content.get_title() + ' ' + entry.id, 'url': absoluteURL(entry, self.request), 'date': format(crea_date.asdatetime()), 'files': files}) return releases
def breadcrumbs(self): return self._breadcrumbs( skip=IVersionedContent, preview=IPreviewLayer.providedBy(self.request))
def __init__(self, request): self.get = lambda content: content.get_viewable() if IPreviewLayer.providedBy(request): self.get = lambda content: content.get_previewable()
def __str__(self): return self.url(preview=IPreviewLayer.providedBy(self.request))
def traverse(self, name, remaining): if not IPreviewLayer.providedBy(self.request): alsoProvides(self.request, IPreviewLayer) return UseParentByAcquisition()
def breadcrumbs(self): return self._breadcrumbs( skip=None, preview=IPreviewLayer.providedBy(self.request))
def __init__(self, request): self.get = lambda content: content.get_viewable() if IPreviewLayer.providedBy(request): self.get = lambda content: content.get_previewable() self.metadata = getUtility(IMetadataService).getMetadataValue
def get_thumbnail_url(self): image = self._get_image() if image is not None: return image.url(request=self.request, thumbnail=True, preview=IPreviewLayer.providedBy(self.request)) return None