def get_chamber_for_context(context): """Return the chamber in which the context exists. """ # first look for current parliament from context tree chamber = common.getattr_ancestry(context, None, "__parent__", acceptable=interfaces.IParliament.providedBy) # !+ should this ever be None here? if chamber is None: # check logged in user's chamber chamber = get_login_user_chamber() return chamber
def get_parl_container(context, chamber_id): parl = None chamber_key = container_obj_key(chamber_id) container = getattr_ancestry(context, None, acceptable=model_ifaces.IParliamentContainer.providedBy) if container: parl = container[chamber_key] else: #check locally for container containers = get_managed_containers(context) or context.items() for key, container in containers: if model_ifaces.IParliamentContainer.providedBy(container): return container[chamber_key] return parl
def get_parl_container(context, chamber_id): parl = None chamber_key = container_obj_key(chamber_id) container = getattr_ancestry( context, None, acceptable=model_ifaces.IParliamentContainer.providedBy) if container: parl = container[chamber_key] else: #check locally for container containers = get_managed_containers(context) or context.items() for key, container in containers: if model_ifaces.IParliamentContainer.providedBy(container): return container[chamber_key] return parl
def get_parl_container(context, chamber_id): parl = None chamber_key = container_obj_key(chamber_id) container = getattr_ancestry(context, acceptable=model_ifaces.IChamberContainer.providedBy) if not container: #check locally for container containers = get_managed_containers(context) or context.items() for key, local_container in containers: if model_ifaces.IChamberContainer.providedBy(local_container): container = local_container break try: parl = container[chamber_key] except KeyError: log.error("No such chamber was found with key %s", chamber_key) return parl
def get_min_date_active(self): """Determine the min_date_active to validate against. """ def is_workflowed_and_draft(instance): """is item workflowed, and if so is it in a logical draft state? """ if interfaces.IWorkflowed.providedBy(instance): wf = interfaces.IWorkflow(instance) return instance.status in wf.get_state_ids(tagged=["draft"], restrict=False) return False instance = removeSecurityProxy(self.context) min_date_active = None if IFeatureAudit.providedBy(self.context): # !+PASTDATAENTRY(mr, jun-2011) offers a way to enter past data # for workflowed items via the UI -- note, ideally we should be # able to also control the item's creation active_date. # # If a workflowed item is in draft state, we do NOT take the # date_active of its last change as the min_date_active, but # let that min fallback to parliament's creation date... if not is_workflowed_and_draft(instance): changes = get_changes(instance, "workflow") if changes: # then use the "date_active" of the most recent entry min_date_active = changes[-1].date_active if not min_date_active: # ok, try determine a min_date_active in another way, namely via the # start_date of the "parliament" the instance "lives" in... parliament = models.utils.get_parliament( common.getattr_ancestry( instance, "parliament_id")) #!+parent_ref="head"? min_date_active = datetime.datetime.combine( parliament.start_date, datetime.time()) # As the precision of the UI-submitted datetime is only to the minute, # we adjust min_date_active by a margin of 59 secs earlier to avoid # issues of doing 2 transitions in quick succession (within same minute) # the 2nd of which could be taken to be too old... return min_date_active - datetime.timedelta(seconds=59)
def get_min_date_active(self): """Determine the min_date_active to validate against. """ def is_workflowed_and_draft(instance): """is item workflowed, and if so is it in a logical draft state? """ if interfaces.IWorkflowed.providedBy(instance): wf = interfaces.IWorkflow(instance) return instance.status in wf.get_state_ids(tagged=["draft"], restrict=False) return False instance = removeSecurityProxy(self.context) min_date_active = None if IFeatureAudit.providedBy(self.context): # !+PASTDATAENTRY(mr, jun-2011) offers a way to enter past data # for workflowed items via the UI -- note, ideally we should be # able to also control the item's creation active_date. # # If a workflowed item is in draft state, we do NOT take the # date_active of its last change as the min_date_active, but # let that min fallback to parliament's creation date... if not is_workflowed_and_draft(instance): changes = get_changes(instance, "workflow") if changes: # then use the "date_active" of the most recent entry min_date_active = changes[-1].date_active if not min_date_active: # ok, try determine a min_date_active in another way, namely via the # start_date of the "parliament" the instance "lives" in... parliament = models.utils.get_parliament( common.getattr_ancestry(instance, "parliament_id")) #!+parent_ref="head"? min_date_active = datetime.datetime.combine( parliament.start_date, datetime.time()) # As the precision of the UI-submitted datetime is only to the minute, # we adjust min_date_active by a margin of 59 secs earlier to avoid # issues of doing 2 transitions in quick succession (within same minute) # the 2nd of which could be taken to be too old... return min_date_active - datetime.timedelta(seconds=59)
def get_chamber_for_group(group): """Cascade up first group ancestry to chamber, returning it (or None). """ return common.getattr_ancestry(group, None, "parent_group", acceptable=interfaces.IParliament.providedBy) ''' !+ equivalent alternative:
def search_section(self): return getattr_ancestry(self.context, None, acceptable=ISearchableSection.providedBy)
def get_ancestor_group(group, acceptable=None): """Cascade up group ancestry to first acceptable(group), or None. """ return common.getattr_ancestry(group, horizontal_attr=None, vertical_attr="parent_group", acceptable=acceptable)