class GroupSettings(silvaforms.SMISubEditForm): grok.context(interfaces.ISilvaSoftwareGroup) grok.view(Settings) grok.order(5) label = u"Software group settings" fields = silvaforms.Fields(IGroupSettings)
class InfoPortlet(SMIAssetPortlet): grok.context(IImage) grok.order(10) def update(self): self.thumbnail = None self.dimensions = None self.original_available = False self.original_dimensions = None self.web_format = self.context.web_format.lower() dimensions = self.context.get_dimensions(hires=False) if dimensions != (0, 0): self.dimensions = dict(list(zip(['width', 'height'], dimensions))) if self.context.hires_image is not None: self.original_available = True original_dimensions = self.context.get_dimensions(hires=True) if original_dimensions not in (dimensions, (0, 0)): self.original_dimensions = dict( list(zip(['width', 'height'], original_dimensions))) if self.context.thumbnail_image: self.thumbnail = self.context.tag(request=self.request, preview=True, thumbnail=True) self.orientation = self.context.get_orientation() self.orientation_cls = str(self.orientation)
class NameOfTheViewlet(grok.Viewlet): grok.context(Interface) # Viewlet manager grok.viewletmanager(IHeader) # Name of the template that's using grok.template("nameoftheviewlet") # Order (!) grok.order(2) # Name of your product grok.name("collective.nameofyourproduct") # Require permissions if necessary grok.require("cmf.AddPortalContent") # Control when we want to render the viewlet, for example: def enabled(self): """ Viewlet will be enabled if... """ return True def available(self): """ Viewlet will be available when... """ return True
class Utilsviewlet(BaseViewlet): grok.context(Interface) grok.name('seantis.reservation.utilslet') grok.require('zope2.View') grok.viewletmanager(OverviewletManager) grok.order(10) template = grok.PageTemplateFile('templates/utils.pt') @property def compare_link(self): return utils.compare_link(self.manager.resource_uuids) @property def monthly_report_link(self): return utils.monthly_report_link(self.context, self.request, self.manager.resource_uuids) @property def latest_reservations_link(self): return utils.latest_reservations_link(self.context, self.request, self.manager.resource_uuids) @property def export_link(self): return utils.export_link(self.context, self.request, self.manager.resource_uuids)
class RelatedItemsViewlet(grok.Viewlet): """Viewlet de itens relacionados para Dexterity """ grok.viewletmanager(IBelowContentBody) grok.context(IDexterityContent) grok.order(100) def related(self): context = aq_inner(self.context) res = () if base_hasattr(context, 'relatedItems'): related = context.relatedItems else: try: behavior = IRelatedItems(context) related = behavior.relatedItems except TypeError: return res tools = context.restrictedTraverse('@@plone_tools') catalog = tools.catalog() if related: related = [item.to_path for item in related if item.to_path] brains = catalog(path=related) if brains: # build a position dict by iterating over the items once positions = dict([(v, i) for (i, v) in enumerate(related)]) # We need to keep the ordering intact res = list(brains) def _key(brain): return positions.get(brain.UID, -1) res.sort(key=_key) return res
class PackageSettings(silvaforms.SMISubEditForm): grok.context(interfaces.ISilvaSoftwarePackage) grok.view(Settings) grok.order(5) label = u"Software package settings" fields = silvaforms.Fields(IPackageSettings)
class NewsFlash_Viewlet(grok.Viewlet): grok.context(Interface) grok.layer(INewsFlashLayer) grok.name('collective.newsflash.viewlet') grok.order(0) grok.require('zope2.View') grok.viewletmanager(IAboveContent)
class TabBlock(Block): grok.name('tab-content') grok.title('Tabular content') grok.order(21) silvaconf.icon('tabs.png') def __init__(self): self.identifier = unicode(uuid.uuid1())
class FileServiceSettings(silvaforms.ZMISubForm): grok.context(FilesService) grok.view(FileServiceManagementView) grok.order(10) label = _(u"Select storage") fields = silvaforms.Fields(IFilesService) actions = silvaforms.Actions(silvaforms.EditAction()) ignoreContent = False
class GhostAssetPortlet(SMIAssetPortlet): grok.context(IGhostAsset) grok.order(10) def update(self): self.is_image = IImageIncluable.providedBy(self.context) self.filename = self.context.get_filename() self.mime_type = self.context.get_mime_type() self.download_url = self.context.get_download_url(preview=True, request=self.request)
class FileSystemNavigator(grok.Viewlet): grok.name('navigator-filesystem') grok.require('cmf.ManagePortal') grok.context(IPloneIDE) grok.viewletmanager(PloneIDENavigatorViewletManager) grok.order(100) def render(self): # Navigator must provide code to fit into the jstree structure. return """
class JQuerySplitterResources(grok.Viewlet): """jquery.splitter is in the static folder""" grok.name('jquery.splitter') grok.require('zope2.View') grok.viewletmanager(PloneIDEJSViewletManager) grok.context(IPloneIDE) grok.order(20) def render(self): return """<script src="%s/++resource++ploneide.core/jquery.splitter/splitter.js" type="text/javascript"></script>\n""" % self.context.portal_url( )
class DefaultCSSResources(grok.Viewlet): """ploneide.css is in the static/css folder""" grok.name('ploneide.core.ploneide') grok.require('zope2.View') grok.viewletmanager(PloneIDECSSViewletManager) grok.context(IPloneIDE) grok.order(100) def render(self): return """<link rel="stylesheet" href="%s/++resource++ploneide.core/ploneide.css" type="text/css" />\n""" % self.context.portal_url( )
class Overviewlet(BaseViewlet): grok.context(Interface) grok.name('seantis.reservation.overviewlet') grok.require('zope2.View') grok.viewletmanager(OverviewletManager) grok.order(1) overview_id = "seantis-overview-calendar" _template = u"""\ <script type="text/javascript"> if (!this.seantis) this.seantis = {}; if (!this.seantis.overview) this.seantis.overview = {}; this.seantis.overview.id = '#%(id)s'; this.seantis.overview.options= %(options)s; </script> <div id="%(id)s"></div> """ def overview_url(self): return self.context.absolute_url_path() + '/overview' def calendar_options(self): # Put the uuidmap in the json so it can be used by overview.js uuidmap = self.manager.uuidmap options = {} options['events'] = { 'url': self.overview_url(), 'type': 'POST', 'data': { 'uuid': uuidmap.keys() }, 'className': 'seantis-overview-event' } options['uuidmap'] = uuidmap return json.dumps(options) def render(self): if not IOverview.providedBy(self.view): return '' if not self.manager.uuidmap: return '' return self._template % { "id": self.overview_id, "options": self.calendar_options() }
class ExternalSourceImportFilter(TransformationFilter): grok.adapts(IVersion, ISilvaXMLHandler) grok.provides(ISilvaXMLImportFilter) grok.order(15) def __init__(self, context, handler): self.context = context self.handler = handler def prepare(self, name, text): self.sources = getWrapper(self.context, IExternalSourceManager) def __call__(self, tree): importer = self.handler.getExtra() request = importer.request for node in tree.xpath( '//html:div[contains(@class, "external-source")]', namespaces={'html': 'http://www.w3.org/1999/xhtml'}): name = node.attrib.get('source-identifier') if name is None: importer.reportProblem(u"Broken source in import.", self.context) continue try: source = self.sources(request, name=name) except SourceError as error: importer.reportProblem( u"Broken source in import: {0}".format(error), self.context) continue identifier = source.new() deserializers = getWrapper( source, IXMLFormSerialization).getDeserializers() for field_node in node.xpath('./cs:fields/cs:field', namespaces={'cs': NS_SOURCE_URI}): field_id = field_node.attrib['id'] if field_id.startswith('field-'): # XXX Backward compatiblity 3.0b1 field_id = field_id[6:].replace('-', '_') deserializer = deserializers.get(field_id) if deserializer is None: # This field have been removed. Ignore it. logger.warn(u"Unknown source parameter %s in %s" % (field_id, name)) continue # Deserialize the value deserializer(field_node, self.handler) del node[:] del node.attrib['source-identifier'] node.attrib['data-source-instance'] = identifier
class JQueryBespinResources(grok.Viewlet): """bespin is in the static folder""" grok.name('bespin') grok.require('zope2.View') grok.viewletmanager(PloneIDEJSViewletManager) grok.context(IPloneIDE) grok.order(20) def render(self): return """<link id="bespin_base" href="%s/++resource++ploneide.core/bespin-0.9a1/" /> <script src="%s/++resource++ploneide.core/bespin-0.9a1/BespinEmbedded.js" type="text/javascript"></script>\n""" % ( self.context.portal_url(), self.context.portal_url())
class DefaultJSResources(grok.Viewlet): """ploneide.js is in the static/js folder""" grok.name('ploneide.core.ploneide') grok.require('zope2.View') grok.viewletmanager(PloneIDEJSViewletManager) grok.context(IPloneIDE) grok.order(100) def render(self): return """<link id="ploneide_base" href="%s" /> <script src="%s/++resource++ploneide.core/ploneide.js" type="text/javascript"></script>""" % ( self.context.absolute_url(), self.context.portal_url())
class ExternalSourceInputFilter(TransformationFilter): """Updater External Source information on edit. """ grok.implements(IInputEditorFilter) grok.provides(IInputEditorFilter) grok.order(20) grok.adapts(ISourceEditableVersion, IBrowserRequest) def __call__(self, tree): for node in tree.xpath(SOURCE_XPATH): instance = node.attrib.get('data-source-instance') if instance is not None: del node.attrib['data-source-instance'] node.attrib['data-silva-instance'] = instance or ''
class GhostAssetEditForm(silvaforms.SMISubForm): """ Edit form Ghost Folder """ grok.context(IGhostAsset) grok.view(AssetEditTab) grok.order(10) label = _(u'Edit ghost') ignoreContent = False dataManager = silvaforms.SilvaDataManager dataValidators = [TargetValidator('haunted', IAsset, adding=False)] fields = silvaforms.Fields(IGhostAssetSchema).omit('id') actions = silvaforms.Actions(silvaforms.CancelEditAction(), silvaforms.EditAction())
class Destaques_Viewlet(grok.Viewlet): """Viewlet que lista destaques do site """ grok.viewletmanager(IPortalHeader) grok.context(Interface) grok.order(100) @property def canonical_object(self): context = self.context context_state = getMultiAdapter((context, self.request), name=u'plone_context_state') return context_state.canonical_object() @property def portal_state(self): context = self.context portal_state = getMultiAdapter((context, self.request), name=u'plone_portal_state') return portal_state @property def portal(self): return self.portal_state.portal() @property def portal_url(self): return self.portal_state.portal_url() def editable(self): """ Validamos se o destaques eh editavel """ destaques = getattr(self.portal, FEATURES_ID, None) if destaques: context_state = getMultiAdapter((destaques, self.request), name=u'plone_context_state') return context_state.is_editable() def available(self): """ Exibiremos ou nao este viewlet """ context = self.canonical_object self.destaques = getattr(self.portal, FEATURES_ID, None) if (context == self.portal) else None if self.destaques: return ICover.providedBy(self.destaques) else: return False
class CSVSourceEditForm(silvaforms.SMISubForm): """CSVSource Edit Form. """ grok.view(AssetEditTab) grok.order(10) label = _('Edit file content') ignoreContent = False dataManager = silvaforms.SilvaDataManager fields = silvaforms.Fields(ICSVSourceFields).omit('id') fields['file'].fileSetLabel = _( "Click the Upload button to replace the current CSV with a new one.") actions = silvaforms.Actions(silvaforms.CancelEditAction(), silvaforms.EditAction())
class YourReservationsViewlet(grok.Viewlet, YourReservationsData): grok.context(Interface) grok.name('seantis.reservation.YourReservationsviewlet') grok.require('zope2.View') grok.viewletmanager(OverviewletManager) grok.order(0) template = grok.PageTemplateFile('templates/your_reservations_viewlet.pt') def available(self): return self.has_reservations def finish_url(self): return self.context.absolute_url() + '/your-reservations'
class ImageEditForm(silvaforms.SMISubForm): """ Edit image attributes """ grok.context(IImage) grok.view(AssetEditTab) grok.order(10) label = _('Edit') ignoreContent = False dataManager = silvaforms.SilvaDataManager fields = silvaforms.Fields(IImageAddFields).omit('id') fields['image'].fileSetLabel = _( "Click the Upload button to replace the current image with a new image." ) actions = silvaforms.Actions(silvaforms.CancelEditAction(), silvaforms.EditAction())
class GroupRemoteSettings(silvaforms.SMISubEditForm): grok.context(interfaces.ISilvaSoftwareRemoteGroup) grok.view(Settings) grok.order(4) label = u"Software remote group settings" actions = silvaforms.Actions(silvaforms.SMISubEditForm.actions) fields = silvaforms.Fields(IRemoteGroupFields).omit('id', 'title') @silvaforms.action('Synchronize') def synchronize(self): try: self.context.synchronize(self.request) except ValueError, error: raise silvaforms.ActionError(error.args[0]) self.send_message('Software synchronized.') return silvaforms.SUCCESS
class FileSystemNavigatorResources(grok.Viewlet): """jquery.jstree is in the static folder""" grok.name('navigator-filesystem') grok.require('cmf.ManagePortal') grok.viewletmanager(PloneIDEJSViewletManager) grok.context(IPloneIDE) grok.order(200) def render(self): rv = [ """<script src="%s/++resource++ploneide.core/ploneide-fs-navigator.js" type="text/javascript"></script>""" % self.context.portal_url(), """<script src="%s/++resource++ploneide.core/ploneide-edit-bespin.js" type="text/javascript"></script>""" % self.context.portal_url(), ] return '\n'.join(rv)
class FileEditForm(silvaforms.SMISubForm): """Edit file. """ grok.context(IFile) grok.view(AssetEditTab) grok.order(10) label = _('Edit file content') ignoreContent = False dataManager = silvaforms.SilvaDataManager fields = silvaforms.Fields(IFileAddFields).omit('id') fields['title'].required = False fields['file'].fileSetLabel = _( "Click the Upload button to replace the current file with a new file.") actions = silvaforms.Actions(silvaforms.CancelEditAction(), silvaforms.EditAction())
class ExternalSourceDisplayFilter(TransformationFilter): """Updater External Source information on edit. """ grok.implements(IDisplayFilter) grok.provides(IDisplayFilter) grok.order(20) grok.adapts(ISourceEditableVersion, IBrowserRequest) def prepare(self, name, text): self.sources = getComponent(self.context, IExternalSourceManager)(self.context) def __call__(self, tree): for node in tree.xpath(SOURCE_XPATH): instance = node.attrib.get('data-source-instance') if instance is not None: del node.attrib['data-source-instance'] try: if instance is None: raise ParametersMissingError() source = self.sources(self.request, instance=instance) html = source.render() keep = not set( node.attrib['class'].split()).issubset(DEFAULT_CLASSES) except SourceError as error: html = silvaviews.render(error, self.request).strip() if not html: continue # There is already a class, as it is used to match # in the XPath. node.attrib['class'] += ' broken-source' keep = True result = lxml.html.fragment_fromstring(html, create_parent="div") if keep: node.extend(result) else: parent = node.getparent() if parent is not None: index = parent.index(node) for child in result: parent.insert(index, child) index += 1 parent.remove(node)
class FileServiceConvert(silvaforms.ZMISubForm): grok.context(FilesService) grok.view(FileServiceManagementView) grok.order(20) label = _(u"Convert stored files") description = _(u"Convert all currently stored file to " u"the current set storage.") def available(self): if self.context.storage is None: return False return self.context.storage is not ZODBFile @silvaforms.action(_(u'Convert all files')) def convert(self): parent = self.context.get_publication() self.context.convert_storage(parent) self.status = _(u'Storage for Silva Files and Images converted. ' u'Check the log for more details.')
class TemplatesViewlet(BaseViewlet): permission = 'cmf.ModifyPortalContent' grok.context(IFolderish) grok.require(permission) grok.name('seantis.reservation.mailviewlet') grok.viewletmanager(OverviewletManager) grok.order(4) _template = grok.PageTemplateFile('templates/email_templates.pt') @view.memoize def templates(self): templates = [ t.getObject() for t in utils.portal_type_in_context( self.context, portal_type='seantis.reservation.emailtemplate') ] return sorted(templates, key=lambda t: t.title) def links(self, template=None): # global links if not template: baseurl = self.context.absolute_url() return [(_(u'Add email template'), baseurl + '/++add++seantis.reservation.emailtemplate')] # template specific links links = [] baseurl = template.absolute_url() links.append((_(u'Edit'), baseurl + '/edit')) links.append((_(u'Delete'), baseurl + '/delete_confirmation')) return links def render(self, **kwargs): return self._template.render(self)
class FileServiceConvertConfiguration(silvaforms.SMISubForm): grok.context(FilesService) grok.view(FileServiceConfiguration) grok.order(20) label = _(u"Convert stored files") description = _(u"Convert all currently stored file to " u"the current set storage.") actions = silvaforms.Actions(silvaforms.CancelConfigurationAction()) def available(self): if self.context.storage is None: return False return self.context.storage is not ZODBFile @silvaforms.action(_(u'Convert all files')) def convert(self): parent = self.context.get_publication() self.context.convert_storage(parent) self.send_message(_(u'Storage for Silva Files and Images converted. ' u'Check the log for more details.'), type='feedback')