def _get_viewedcontent(self): # Find the project in the acquisition context. # I tried to call self.view.piv.project and .inproject, et al. but # for some reason those return None and False on a closed project. # Instead, we walk the acquisition chain by hand. item = interface_in_aq_chain(aq_inner(self.context), IProject) return item # might be None, which typically means we're in
def project(self): context = aq_inner(self.context) if IOpenTeam.providedBy(context): # get the related project return aq_inner(context.getProject()) # probably wrap this in an adapter return interface_in_aq_chain(context, IProject)
def _update_last_modified_author(page, user_id=None): # check if user_id needs to be set if user_id is None: # find last logged in user user_id = get_member(page) # annotate page object with it page_annot = IAnnotations(page) annot = page_annot.setdefault(ANNOT_KEY, OOBTree()) annot['lastModifiedAuthor'] = user_id page.reindexObject(idxs=['lastModifiedAuthor']) # if part of a project, annotate the project with the user id as well proj = interface_in_aq_chain(page.aq_inner, IProject) if proj is None: return proj_annot = IAnnotations(proj) annot = proj_annot.setdefault(ANNOT_KEY, OOBTree()) annot['lastModifiedAuthor'] = user_id proj.reindexObject(idxs=['lastModifiedAuthor'])
def updateThreadCount(obj, event): msg = ISearchableMessage(obj) if msg.isInitialMessage(): # we'd like to just reindexObject on the list # but the new msg obj isn't really created yet # so we have to do a lot of nonsense instead # First get the list object. We must acquire this from obj, # not from msg, because msg.aq_foo works but aq_foo(msg) # doesn't, due to a SearchableMessage.__getattr__. ml_obj = interface_in_aq_chain(obj, IMailingList) # sometimes we get our mailing lists wrapped in a component # registry, thanks to local utility weirdness, and aq_inner # won't even fix it if not IFolderish.providedBy(ml_obj.aq_parent): # we've got one of the weird ones, up two more steps ml_obj = ml_obj.aq_parent.aq_parent list_path = '/'.join(ml_obj.getPhysicalPath()) cat = getToolByName(msg, 'portal_catalog') md = cat.getMetadataForUID(list_path) md['mailing_list_threads'] += 1 proxy = type('proxy', (object,), md)() cat._catalog.catalogObject(proxy, list_path, idxs=['mailing_list_threads'])
def in_project(self): from opencore.utils import interface_in_aq_chain from opencore.interfaces import IProject return interface_in_aq_chain(self.context, IProject)
def listen_container(self): context = aq_inner(self.context) container = interface_in_aq_chain(context, IListenContainer) return container
def list_title(self): obj = interface_in_aq_chain(self.context, IMailingList) if obj is None: return '' return obj.Title()
def list_url(self): obj = interface_in_aq_chain(self.context, IMailingList) if obj is None: return '' return obj.absolute_url()
def subscription_snippet(self): # fix #2049. the_list = interface_in_aq_chain(aq_inner(self.context), IMailingList) return the_list.restrictedTraverse("subscription_snippet")()
def interfaceInAqChain(self, iface): return interface_in_aq_chain(aq_inner(self.context), iface)
def updateContainerMetadata(obj, event): project = interface_in_aq_chain(aq_inner(obj), IProject) if project is None: return project.setModificationDate() project.reindexObject(idxs=['modified'])
def __init__(self, context): self.context = context self.portal = interface_in_aq_chain(aq_inner(context), IOpenSiteRoot)