def page_description(self): """Formalize view.page_description as a view property to factor the logic for determining the page description for a view out of the template. Templates should always simply call: view.page_description """ # if view explicitly sets a page_description, use it if self._page_description: return self._page_description # otherwise try to determine it from DC annotations context = removeSecurityProxy(self.context) try: # This is equivalent of the ZPT expression "context/dc:description" # i.e. to "load the value of the variable context, then find a # component that adapts that object to Dublin Core and read the # description attribute of the component." return IDCDescriptiveProperties(context).description except (Exception,): debug.log_exc(sys.exc_info(), log_handler=log.debug) # otherwise try to determine it from the context if getattr(context, "description", None): return context.description else: return "Bungeni"
def page_description(self): """Formalize view.page_description as a view property to factor the logic for determining the page description for a view out of the template. Templates should always simply call: view.page_description """ # if view explicitly sets a page_description, use it if self._page_description: return self._page_description # otherwise try to determine it from DC annotations context = removeSecurityProxy(self.context) try: # This is equivalent of the ZPT expression "context/dc:description" # i.e. to "load the value of the variable context, then find a # component that adapts that object to Dublin Core and read the # description attribute of the component." return IDCDescriptiveProperties(context).description except (Exception, ): debug.log_exc(sys.exc_info(), log_handler=log.debug) # otherwise try to determine it from the context if getattr(context, "description", None): return context.description else: return "Bungeni"
def __getattr__(self, name): """Try to pick any attribute (not found on this change record--this method only gets called when a non-existent attribute is accessed) off the related audit snapshot record (as every change record is related to a type-dedicated audit record). !+ should this be on Change i.e. for all change actions? """ audit = self.audit try: return getattr(audit, name) except AttributeError: # !+DocVersion.filevers try: from bungeni.alchemist import utils return utils.FILES_VERSION_CONTAINER_ATTRIBUTE_ERROR_HACK( self, name) except: import sys from bungeni.ui.utils import debug debug.log_exc(sys.exc_info(), log_handler=log.error) raise AttributeError( "%r [audit_id=%r, audit_type=%r] object has no attribute %r" % (self, self.audit_id, self.audit_type, name))
def _eval_as_dict(s): """Utility to eval serialization of a dict, failure returns an empty dict. """ try: d = eval(s) assert isinstance(d, dict) return d except (SyntaxError, TypeError, AssertionError): debug.log_exc(sys.exc_info(), log_handler=log.info) return {}
def descriptor_classes(): """A generator of descriptor classes in this module, preserving the order of definition. """ # dir() returns names in alphabetical order decorated = [] for key in dir(module): cls = getattr(module, key) try: assert IModelDescriptor.implementedBy(cls) # we decorate with the source code line number for the cls decorated.append((inspect.getsourcelines(cls)[1], cls)) except (TypeError, AttributeError, AssertionError): debug.log_exc(sys.exc_info(), log_handler=log.debug) # we yield each cls in order of definition for cls in [ cls for (line_num, cls) in sorted(decorated) ]: yield cls
def page_title(self): """Formalize view.page_title as a view property to factor the logic for determining the page title for a view out of the template. Templates should always simply call view.page_title. """ if self._page_title: return self._page_title if getattr(self.context, "title"): return self.context.title try: # This is the equivalent of the ZPT expression "context/dc:title" # i.e. to "load the value of the variable context, then find a # component that adapts that object to Dublin Core and read the # title attribute of the component." return IDCDescriptiveProperties(self.context).title except (Exception, ): debug.log_exc(sys.exc_info(), log_handler=log.debug) return "Bungeni"
def page_title(self): """Formalize view.page_title as a view property to factor the logic for determining the page title for a view out of the template. Templates should always simply call view.page_title. """ if self._page_title: return self._page_title if getattr(self.context, "title"): return self.context.title try: # This is the equivalent of the ZPT expression "context/dc:title" # i.e. to "load the value of the variable context, then find a # component that adapts that object to Dublin Core and read the # title attribute of the component." return IDCDescriptiveProperties(self.context).title except (Exception,): debug.log_exc(sys.exc_info(), log_handler=log.debug) return "Bungeni"
def add_zcml_menu_items(self, container): """Add the list of ZCML menu items (if any) for this top-level container. Top-level section given by container may define a menu in ZCML with naming convention: <container_name>_navigation. """ # !+ turn this into a utility zcml_menu_name_template = "%s_navigation" try: menu_name = zcml_menu_name_template % container.__name__ menu = component.getUtility(IBrowserMenu, name=menu_name) items = menu.getMenuItems(container, self.request) except (Exception, ): debug.log_exc(sys.exc_info(), log_handler=log.debug) return [] # OK, do any necessary post-processing of each menu item local_url = url.absoluteURL(container, self.request) site_url = url.absoluteURL(getSite(), self.request) request_url = self.request.getURL() default_view_name = queryDefaultViewName(container, self.request) selection = None for item in sorted(items, key=lambda item: item["action"], reverse=True): action = item["action"] if default_view_name == action.lstrip("@@"): _url = local_url if selection is None: selected = sameProxiedObjects(container, self.context) else: _url = make_absolute(action, local_url, site_url) if selection is None: selected = pos_action_in_url(action, request_url) item["url"] = _url item["selected"] = selected and u"selected" or u"" if selected: # self is marker selection = self selected = False self.items.append(item)
def add_zcml_menu_items(self, container): """Add the list of ZCML menu items (if any) for this top-level container. Top-level section given by container may define a menu in ZCML with naming convention: <container_name>_navigation. """ # !+ turn this into a utility zcml_menu_name_template = "%s_navigation" try: menu_name = zcml_menu_name_template % container.__name__ menu = component.getUtility(IBrowserMenu, name=menu_name) items = menu.getMenuItems(container, self.request) except (Exception,): debug.log_exc(sys.exc_info(), log_handler=log.debug) return [] # OK, do any necessary post-processing of each menu item local_url = url.absoluteURL(container, self.request) site_url = url.absoluteURL(getSite(), self.request) request_url = self.request.getURL() default_view_name = queryDefaultViewName(container, self.request) selection = None for item in sorted(items, key=lambda item: item["action"], reverse=True): action = item["action"] if default_view_name==action.lstrip("@@"): _url = local_url if selection is None: selected = sameProxiedObjects(container, self.context) else: _url = make_absolute(action, local_url, site_url) if selection is None: selected = pos_action_in_url(action, request_url) item["url"] = _url item["selected"] = selected and u"selected" or u"" if selected: # self is marker selection = self selected = False self.items.append(item)
def __getattr__(self, name): """Try to pick any attribute (not found on this change record--this method only gets called when a non-existent attribute is accessed) off the related audit snapshot record (as every change record is related to a type-dedicated audit record). !+ should this be on Change i.e. for all change actions? """ audit = self.audit try: return getattr(audit, name) except AttributeError: # !+DocVersion.filevers try: from bungeni.alchemist import utils return utils.FILES_VERSION_CONTAINER_ATTRIBUTE_ERROR_HACK(self, name) except: import sys from bungeni.ui.utils import debug debug.log_exc(sys.exc_info(), log_handler=log.error) raise AttributeError( "%r [audit_id=%r, audit_type=%r] object has no attribute %r" % ( self, self.audit_id, self.audit_type, name))