def run(self, resource, adapter, session, *args, **kwds): """ Run """ parent = self.context if ILinkedDataHomepage.providedBy(parent): return BreadcrumbList = session.get_class(surf.ns.SCHEMA['BreadcrumbList']) Item = session.get_class(surf.ns.SCHEMA['Thing']) ListElement = session.get_class(surf.ns.SCHEMA['ListItem']) blist = BreadcrumbList("#breadcrumb") position = 0 while not ILinkedDataHomepage.providedBy(parent): try: if position != 0: parent = parent.aq_parent url = parent.absolute_url() position += 1 list_item = ListElement("BreadCrumbsListItem" + str(position)) list_item.schema_position = position item = Item(url + "#breadcrumb") item.schema_name = parent.Title() item.schema_image = Literal(url + '/image_large') item.schema_url = url item.update() list_item.schema_item = item blist.schema_itemListElement.append(list_item) except AttributeError: break items_len = len(blist.schema_itemListElement) for n, el in enumerate(blist.schema_itemListElement): el.schema_position = Literal(items_len - n) el.update() blist.update()
def run(self, resource, adapter, session, *args, **kwds): """ JSON-LD export of latest news within our homepage """ context = self.context if not has_linked_data: return if not INavigationRoot.providedBy(context) and \ not ILinkedDataHomepage.providedBy(context.aq_parent): return fview = context.restrictedTraverse('@@frontpage_highlights') ItemList = session.get_class(surf.ns.SCHEMA['ItemList']) ListElement = session.get_class(surf.ns.SCHEMA['ListItem']) ilist = ItemList("#itemList2") portal_properties = getToolByName(context, 'portal_properties') fp = getattr(portal_properties, 'frontpage_properties') # use news as latest news while keeping it flexible in case we want # other products promoted as latest news latest_category = fp.getProperty('getLatestNewsCategory', 'news') products = fview.getLatest(latest_category) position = 0 for brain in products: url = brain.getURL() position += 1 list_item = ListElement("LatestNewsListItem" + str(position)) list_item.schema_position = position list_item.schema_url = url list_item.update() ilist.schema_itemListElement.append(list_item) ilist.update()
def plone_homepage(self): """Returns the Plone site if it's marked with ILinkedDataHomepage""" site = api.portal.get() already_set = ILinkedDataHomepage.providedBy(site) if already_set: return site
def plone_homepage(self): """ Returns the Plone site if it's marked with ILinkedDataHomepage """ site = api.portal.get() already_set = ILinkedDataHomepage.providedBy(site) if already_set: return site
def SingleCheckBoxFieldWidget(field, request): """IFieldWidget factory for CheckBoxWidget.""" widget = SCBFW(field, request) site = api.portal.get() already_set = ILinkedDataHomepage.providedBy(site) widget.field.default = already_set return widget
def SingleCheckBoxFieldWidget(field, request): """ IFieldWidget factory for CheckBoxWidget """ swidget = SCBFW(field, request) site = api.portal.get() already_set = ILinkedDataHomepage.providedBy(site) swidget.field.default = already_set return swidget
def get_site(context): """ retrieve site """ site = context while not ILinkedDataHomepage.providedBy(site): try: site = site.aq_parent except AttributeError: site = None return site return site
def run(self, resource, adapter, session, *args, **kwds): """ Add LinkedDataHomepage information to rdf """ view = getMultiAdapter((self.context, self.context.REQUEST), name="plone_context_state") if view.is_view_template(): root = view.canonical_object() if ILinkedDataHomepage.providedBy(root): modifier = HomepageModifier(root) modifier.run(resource, adapter, session, *args, **kwds)
def get_site(context): """ Retrieve site """ site = context while not ILinkedDataHomepage.providedBy(site): try: site = site.aq_parent except AttributeError: site = None return site return site
def run(self, resource, adapter, session, *args, **kwds): """ Add LinkedDataHomepage information to rdf """ view = queryMultiAdapter((self.context, self.context.REQUEST), name="plone_context_state") if view.is_view_template(): root = view.canonical_object() if ILinkedDataHomepage.providedBy(root): modifier = HomepageModifier(root) modifier.run(resource, adapter, session, *args, **kwds)
def get_site(self): site = portal.get() ldsite = self.context while not ILinkedDataHomepage.providedBy(ldsite): try: ldsite = ldsite.aq_parent except AttributeError: ldsite = None break if ldsite is None: return site return ldsite
def get_site(self): """ Get site """ site = portal.get() ldsite = self.context while not ILinkedDataHomepage.providedBy(ldsite): try: ldsite = ldsite.aq_parent except AttributeError: ldsite = None break if ldsite is None: return site return ldsite
def handleApply(self, action): """ handleApply """ data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return site = api.portal.get() catalog = api.portal.get_tool('portal_catalog') already_set = ILinkedDataHomepage.providedBy(site) set_site = data['set_plonesite'] if set_site != already_set: action = set_site and alsoProvides or noLongerProvides action(site, ILinkedDataHomepage) site._p_changed = True site.reindexObject(idxs=['object_provides']) brains = catalog.searchResults( object_provides=ILinkedDataHomepage.__identifier__) for brain in brains: # remove root and Plone site from path path = '/' + brain.getPath().split('/', 2)[2] if path not in data['homepages']: obj = brain.getObject() noLongerProvides(obj, ILinkedDataHomepage) obj.reindexObject(idxs=['object_provides']) for path in data['homepages']: path = path[1:] # change to relative to Plone root path obj = site.restrictedTraverse(path) if not alsoProvides(obj, ILinkedDataHomepage): alsoProvides(obj, ILinkedDataHomepage) obj.reindexObject(idxs=['object_provides']) self.status = "Changes saved"