Example #1
0
    def publishTraverse(self, request, name):
        """Lookup a name -  (request:IRequest, name:str) -> IView

        The 'request' argument is the publisher request object.  The
        'name' argument is the name that is to be looked up; it must
        be an ASCII string or Unicode object.

        If a lookup is not possible, raise a NotFound error.

        This method should return an object having the specified name and
        `self` as parent. The method can use the request to determine the
        correct object.
        """
        _meth_id = "%s.publishTraverse" % self.__class__.__name__
        log.debug("%s: name=%s __name__=%s __parent__=%s context=%s" % (
            _meth_id, name, self.__name__, self.__parent__, 
            getattr(self, "context", "UNDEFINED")))
        try:
            assert self.publishTraverseResolver is not None
            return self.publishTraverseResolver(self, request, name)
        except (AssertionError,):
            pass # self.publishTraverseResolver is None, not an error
        except (NotFound,):
            pass # this is not really an error
            #debug.log_exc_info(sys.exc_info(), log.debug)
        except (TypeError, Exception):
            debug.log_exc_info(sys.exc_info(), log.error)
        traverser = ItemTraverser(self, request)
        return traverser.publishTraverse(request, name)
Example #2
0
 def fireTransitionScheduled(item, wfc, toward=SCHEDULED):
     try:
         wfc.fireTransitionToward(toward, check_security=True)
         raise RuntimeWarning("It has WORKED !!! fireTransitionToward(%r)" %
                              (toward))
     except (NoTransitionAvailableError, RuntimeWarning):
         debug.log_exc_info(sys.exc_info(), log.error)
Example #3
0
 def fireTransitionScheduled(item, wfc, toward):
     try:
         wfc.fireTransitionToward(toward, check_security=True)
         raise RuntimeWarning(
             "It has WORKED !!! fireTransitionToward(%r)" % (toward))
     except (NoTransitionAvailableError, RuntimeWarning):
         debug.log_exc_info(sys.exc_info(), log.error)
Example #4
0
 def fireTransitionScheduled(item, check_security=False):
     try:
         IWorkflowController(item).fireTransitionToward("scheduled", 
                 check_security=False)
         raise RuntimeWarning(
             """It has WORKED !!! fireTransitionToward("scheduled")""")
     except (NoTransitionAvailableError, RuntimeWarning):
         debug.log_exc_info(sys.exc_info(), log.error)
Example #5
0
 def fireTransitionScheduled(item, check_security=False):
     try:
         IWorkflowInfo(item).fireTransitionToward("scheduled",
                                                  check_security=False)
         raise RuntimeWarning(
             """It has WORKED !!! fireTransitionToward("scheduled")""")
     except (NoTransitionAvailableError, RuntimeWarning):
         debug.log_exc_info(sys.exc_info(), log.error)
Example #6
0
 def update(self):
     session = Session()
     try:
         ministry_ids = [ m.group_id for m in self.__parent__.ministries ]
     except (Exception,):
         debug.log_exc_info(sys.exc_info(), log_handler=log.info)
         ministry_ids = []
     qfilter = domain.Ministry.group_id.in_(ministry_ids)
     ministries = session.query(domain.Ministry).filter(qfilter).order_by(
         domain.Ministry.start_date.desc())
     self.query = ministries
     self.items = [ item for ministry in self.query.all()
                    for item in self._get_ministry_items(ministry) ]
Example #7
0
 def translate_objects(self, nodes, lang=None):
     """ (nodes:[ITranslatable]) -> [nodes]
     """
     if lang is None:
         lang = translation.get_request_language()
     t_nodes = []
     for node in nodes:
         try:
             t_nodes.append(translation.translate_obj(node, lang))
         except (AssertionError,): # node is not ITranslatable
             debug.log_exc_info(sys.exc_info(), log_handler=log.warn)
             t_nodes.append(node)
     return t_nodes
Example #8
0
 def translate_objects(self, nodes, lang=None):
     """ (nodes:[ITranslatable]) -> [nodes]
     """
     if lang is None:
         lang = translation.get_request_language()
     t_nodes = []
     for node in nodes:
         try:
             t_nodes.append(translation.translate_obj(node, lang))
         except (AssertionError, ):  # node is not ITranslatable
             debug.log_exc_info(sys.exc_info(), log_handler=log.warn)
             t_nodes.append(node)
     return t_nodes
Example #9
0
 def update(self):
     session = Session()
     try:
         ministry_ids = [ m.group_id for m in self.__parent__.ministries ]
     except (Exception,):
         debug.log_exc_info(sys.exc_info(), log_handler=log.info)
         ministry_ids = []
     qfilter = domain.Ministry.group_id.in_(ministry_ids)
     ministries = session.query(domain.Ministry).filter(qfilter).order_by(
         domain.Ministry.start_date.desc())
     self.query = ministries
     self.items = [ item for ministry in self.query.all()
                    for item in self._get_ministry_items(ministry) ]
Example #10
0
 def update(self):
     """
     refresh the query
     """
     session = Session()
     try:
         ministry_ids = [ m.group_id for m in self.__parent__.ministries ]
     except (Exception,):
         debug.log_exc_info(sys.exc_info(), log_handler=log.info)
         ministry_ids = []
     qfilter = domain.Ministry.group_id.in_(ministry_ids)
     ministries = session.query(domain.Ministry).filter(qfilter).order_by(
         domain.Ministry.start_date.desc())
     self.query = ministries
Example #11
0
 def translate_objects(self, nodes, lang=None):
     """ (nodes:[ITranslatable]) -> [nodes]
     """
     if lang is None:
         lang = translation.get_request_language()
     t_nodes = []
     for node in nodes:
         try:
             t_nodes.append(translation.translate_obj(node, lang))
         except (AssertionError, ):  # node is not ITranslatable
             debug.log_exc_info(sys.exc_info(), log_handler=log.warn)
             # if a node is not translatable then we assume that NONE of
             # the nodes are translatable, so we simply break out,
             # returning the untranslated nodes as is
             return nodes
     return t_nodes
Example #12
0
 def translate_objects(self, nodes, lang=None):
     """ (nodes:[ITranslatable]) -> [nodes]
     """
     if lang is None:
         lang = translation.get_request_language()
     t_nodes = []
     for node in nodes:
         try:
             t_nodes.append(translation.translate_obj(node, lang))
         except (AssertionError,):  # node is not ITranslatable
             debug.log_exc_info(sys.exc_info(), log_handler=log.warn)
             # if a node is not translatable then we assume that NONE of
             # the nodes are translatable, so we simply break out,
             # returning the untranslated nodes as is
             return nodes
     return t_nodes
Example #13
0
def prepare_user_workspaces(event):
    """Determine the current principal's workspaces, depending on roles and
    group memberships. 
    
    "bungeni.Clerk", "bungeni.Speaker", "bungeni.MP"
        these roles get a parliament-level workspace
    
    "bungeni.Minister"
        "implied" role (by being a member of a ministry group) 
        gets a ministry-level workspace (for each ministry)
    
    "zope.Manager", "bungeni.Admin", "bungeni.Owner", "bungeni.Everybody", 
    "bungeni.Anybody"
        not relevant for user workspaces, no workspaces
        !+ should these get an owner-level (user) workspace?
    
    """
    request = event.request
    application = event.object # is bungeni.core.app.BungeniApp
    destination_url_path = url.get_destination_url_path(request)
    def need_to_prepare_workspaces(obj, req):
        return (
            # need only to do it when traversing "/", 
            # obj should be the BungeniApplication
            model_interfaces.IBungeniApplication.providedBy(obj)
            and
            # user is logged in
            interfaces.IBungeniAuthenticatedSkin.providedBy(req)
            and (
                # either the request should be for a view within /workspace
                # note: IWorkspaceSectionLayer is applied to the request by 
                # publication.apply_request_layer_by_url() that therefore must 
                # have already been called
                interfaces.IWorkspaceSectionLayer.providedBy(req)
                or 
                interfaces.IWorkspaceSchedulingSectionLayer.providedBy(req)
                or
                # or the request is for *the* Home Page (as in this case
                # we still need to know the user workspaces to be able to 
                # redirect appropriately)
                interfaces.IHomePageLayer.providedBy(req)
            )
        )
    if not need_to_prepare_workspaces(application, request):
        return
    
    # initialize a layer data object, for the views in the layer
    LD = IAnnotations(request)["layer_data"] = misc.bunch(
        workspaces=[], # workspace containers !+ unique?
        # !+ role-based workspaces: (role|group, workspace_container)
        # these are needed by the views, as we need them also here, we just
        # remember them to not need to calculate them again
        user_id=None,
        user_group_ids=None,
        government_id=None,
        ministries=None, # list of ministries (that are also workspaces)
    )
    
    LD.user_id = get_db_user_id()
    try:
        parliament = get_current_parliament(None)
        assert parliament is not None # force exception
        # we do get_roles under the current parliament as context, but we 
        # must also ensure that the BungeniApp is present somewhere along 
        # the __parent__ stack:
        parliament.__parent__ = application
        roles = get_roles(parliament)
        # "bungeni.Clerk", "bungeni.Speaker", "bungeni.MP"
        for role_id in roles:
            if role_id in ("bungeni.Clerk", "bungeni.Speaker", "bungeni.MP"):
                log.debug("adding parliament workspace %s (for role %s)" % (
                                                        parliament, role_id))
                LD.workspaces.append(parliament)
    
        # "bungeni.Minister"
        # need to check for ministry groups to which the principal belongs, and 
        # for each such ministry assign a ministry workspace
        LD.user_group_ids = get_group_ids_for_user_in_parliament(
                                    LD.user_id, parliament.group_id)
        LD.government_id = get_current_parliament_governments(
                                    parliament)[0].group_id # IndexError
        LD.ministries = get_ministries_for_user_in_government(
                                            LD.user_id, LD.government_id)
        log.debug(""" [prepare_user_workspaces]
            user_id:%s
            roles:%s
            parliament:(%s, %s) 
            government_id:%s
            ministries:%s""" % (
                LD.user_id,
                roles,
                parliament.full_name, parliament.group_id, 
                LD.government_id, 
                [(m.full_name, m.group_id) for m in LD.ministries] ))
        for ministry in LD.ministries:
            log.debug("adding ministry workspace %s" % ministry)
            LD.workspaces.append(ministry)
    except (Exception,):
        debug.log_exc_info(sys.exc_info(), log_handler=log.info)
    
    # ensure unique workspaces, preserving order, retaining same list obj ref
    LD.workspaces[:] = [ workspace for i,workspace in enumerate(LD.workspaces) 
                         if LD.workspaces.index(workspace)==i ]
    
    # mark each workspace container with IWorkspaceContainer
    for workspace in LD.workspaces:
        interface.alsoProvides(workspace, interfaces.IWorkspaceContainer)
        log.debug(debug.interfaces(workspace))
    
    log.debug(" [prepare_user_workspaces] %s" % debug.interfaces(request))
    log.info(""" [prepare_user_workspaces] DONE:
        for: [request=%s][path=%s][path_info=%s]
        request.layer_data: %s""" % (
            id(request), destination_url_path, request.get("PATH_INFO"),
            IAnnotations(request).get("layer_data", None)))
Example #14
0
def prepare_user_workspaces(event):
    """Determine the current principal's workspaces, depending on roles and
    group memberships. 
    
    "bungeni.Clerk", "bungeni.Speaker", "bungeni.MP"
        these roles get a parliament-level workspace
    
    "bungeni.Minister"
        "implied" role (by being a member of a ministry group) 
        gets a ministry-level workspace (for each ministry)
    
    "zope.Manager", "bungeni.Admin", "bungeni.Owner", "bungeni.Authenticated", 
    "bungeni.Anonymous"
        not relevant for user workspaces, no workspaces
        !+ should these get an owner-level (user) workspace?
    
    """
    request = event.request
    application = event.object  # is bungeni.core.app.BungeniApp
    destination_url_path = url.get_destination_url_path(request)

    def need_to_prepare_workspaces(obj, req):
        return (
            # need only to do it when traversing "/",
            # obj should be the BungeniApplication
            model_interfaces.IBungeniApplication.providedBy(obj) and
            # user is logged in
            interfaces.IBungeniAuthenticatedSkin.providedBy(req) and (
                # either the request should be for a view within /workspace
                # note: IWorkspaceSectionLayer is applied to the request by
                # publication.apply_request_layer_by_url() that therefore must
                # have already been called
                interfaces.IWorkspaceSectionLayer.providedBy(req) or
                interfaces.IWorkspaceSchedulingSectionLayer.providedBy(req) or
                # or the request is for *the* Home Page (as in this case
                # we still need to know the user workspaces to be able to
                # redirect appropriately)
                interfaces.IHomePageLayer.providedBy(req)))

    if not need_to_prepare_workspaces(application, request):
        return

    # initialize a layer data object, for the views in the layer
    LD = IAnnotations(request)["layer_data"] = misc.bunch(
        workspaces=[],  # workspace containers !+ unique?
        # !+ role-based workspaces: (role|group, workspace_container)
        # these are needed by the views, as we need them also here, we just
        # remember them to not need to calculate them again
        user_id=None,
        user_group_ids=None,
        government_id=None,
        ministries=None,  # list of ministries (that are also workspaces)
    )

    LD.user_id = get_db_user_id()
    try:
        parliament = get_current_parliament(None)
        assert parliament is not None  # force exception
        # we do get_context_roles under the current parliament as context, but
        # we must also ensure that the BungeniApp is present somewhere along
        # the __parent__ stack:
        parliament.__parent__ = application
        roles = common.get_context_roles(parliament)
        # "bungeni.Clerk", "bungeni.Speaker", "bungeni.MP"
        for role_id in roles:
            if role_id in ("bungeni.Clerk", "bungeni.Speaker", "bungeni.MP"):
                log.debug("adding parliament workspace %s (for role %s)" %
                          (parliament, role_id))
                LD.workspaces.append(parliament)

        # "bungeni.Minister"
        # need to check for ministry groups to which the principal belongs, and
        # for each such ministry assign a ministry workspace
        LD.user_group_ids = get_group_ids_for_user_in_parliament(
            LD.user_id, parliament.group_id)
        LD.government_id = get_current_parliament_governments(
            parliament)[0].group_id  # IndexError
        LD.ministries = get_ministries_for_user_in_government(
            LD.user_id, LD.government_id)
        log.debug(
            """ [prepare_user_workspaces]
            user_id:%s
            roles:%s
            parliament:(%s, %s) 
            government_id:%s
            ministries:%s""" %
            (LD.user_id, roles, parliament.full_name, parliament.group_id,
             LD.government_id, [(m.full_name, m.group_id)
                                for m in LD.ministries]))
        for ministry in LD.ministries:
            log.debug("adding ministry workspace %s" % ministry)
            LD.workspaces.append(ministry)
    except (Exception, ):
        debug.log_exc_info(sys.exc_info(), log_handler=log.info)

    # ensure unique workspaces, preserving order, retaining same list obj ref
    LD.workspaces[:] = [
        workspace for i, workspace in enumerate(LD.workspaces)
        if LD.workspaces.index(workspace) == i
    ]

    # mark each workspace container with IWorkspaceContainer
    for workspace in LD.workspaces:
        interface.alsoProvides(workspace, interfaces.IWorkspaceContainer)
        log.debug(debug.interfaces(workspace))

    log.debug(" [prepare_user_workspaces] %s" % debug.interfaces(request))
    log.info(""" [prepare_user_workspaces] DONE:
        for: [request=%s][path=%s][path_info=%s]
        request.layer_data: %s""" %
             (id(request), destination_url_path, request.get("PATH_INFO"),
              IAnnotations(request).get("layer_data", None)))