Example #1
0
    def testTransactionAnnotation(self):
        from zope.interface import directlyProvides
        from zope.app.location.traversing import LocationPhysicallyLocatable
        from zope.app.location.interfaces import ILocation
        from zope.app.traversing.interfaces import IPhysicallyLocatable
        from zope.app.traversing.interfaces import IContainmentRoot
        ztapi.provideAdapter(ILocation, IPhysicallyLocatable,
                             LocationPhysicallyLocatable)

        root = self.db.open().root()
        root['foo'] = foo = LocatableObject()
        root['bar'] = bar = LocatableObject()
        bar.__name__ = 'bar'
        foo.__name__ = 'foo'
        bar.__parent__ = foo
        foo.__parent__ = root
        directlyProvides(root, IContainmentRoot)

        from zope.publisher.interfaces import IRequest
        expected_path = "/foo/bar"
        expected_user = "******" + self.user.id
        expected_request = IRequest.__module__ + '.' + IRequest.getName()

        self.publication.afterCall(self.request, bar)
        txn_info = self.db.undoInfo()[0]
        self.assertEqual(txn_info['location'], expected_path)
        self.assertEqual(txn_info['user_name'], expected_user)
        self.assertEqual(txn_info['request_type'], expected_request)

        # also, assert that we still get the right location when
        # passing an instance method as object.
        self.publication.afterCall(self.request, bar.foo)
        self.assertEqual(txn_info['location'], expected_path)
Example #2
0
    def testTransactionAnnotation(self):
        from zope.interface import directlyProvides
        from zope.location.traversing import LocationPhysicallyLocatable
        from zope.location.interfaces import ILocation
        from zope.traversing.interfaces import IPhysicallyLocatable
        from zope.traversing.interfaces import IContainmentRoot
        ztapi.provideAdapter(ILocation, IPhysicallyLocatable,
                             LocationPhysicallyLocatable)

        root = self.db.open().root()
        root['foo'] = foo = LocatableObject()
        root['bar'] = bar = LocatableObject()
        bar.__name__ = 'bar'
        foo.__name__ = 'foo'
        bar.__parent__ = foo
        foo.__parent__ = root
        directlyProvides(root, IContainmentRoot)

        from zope.publisher.interfaces import IRequest
        expected_path = "/foo/bar"
        expected_user = "******" + self.user.id
        expected_request = IRequest.__module__ + '.' + IRequest.getName()

        self.publication.afterCall(self.request, bar)
        txn_info = self.storage.undoInfo()[0]
        self.assertEqual(txn_info['location'], expected_path)
        self.assertEqual(txn_info['user_name'], expected_user)
        self.assertEqual(txn_info['request_type'], expected_request)

        # also, assert that we still get the right location when
        # passing an instance method as object.
        self.publication.afterCall(self.request, bar.foo)
        self.assertEqual(txn_info['location'], expected_path)
Example #3
0
def get_principal():
    """ () -> either(zope.security.interfaces.IGroupAwarePrincipal, None)
    """
    interaction = getInteraction()
    for participation in interaction.participations:
        if IRequest.providedBy(participation):
            return participation.principal
Example #4
0
def get_request():
    i = zope.security.management.queryInteraction()
    if i is not None:
        for p in i.participations:
            if IRequest.providedBy(p):
                return p
    return None
Example #5
0
def get_principal():
    """ () -> either(IPrincipal, None)
    """
    interaction = getInteraction()
    for participation in interaction.participations:
        if IRequest.providedBy(participation):
            return participation.principal
Example #6
0
def get_request_principal():
    """ () -> either(zope.security.interfaces.IGroupAwarePrincipal, None)
    """
    interaction = getInteraction()
    for participation in interaction.participations:
        if IRequest.providedBy(participation):
            return participation.principal
Example #7
0
def get_principal():
    """ () -> either(IPrincipal, None)
    """
    interaction = getInteraction()
    for participation in interaction.participations:
        if IRequest.providedBy(participation):
            return participation.principal
Example #8
0
def get_request():
    i = zope.security.management.queryInteraction()
    if i is not None:
        for p in i.participations:
            if IRequest.providedBy(p):
                return p
    return None
def getRequest():
    i = getInteraction() # raises NoInteraction

    for p in i.participations:
        if IRequest.providedBy(p):
            return p

    raise RuntimeError('Could not find current request.')
def getRequest():
    try:
        i = zope.security.management.getInteraction() # raises NoInteraction
    except zope.security.interfaces.NoInteraction:
        return

    for p in i.participations:
        if IRequest.providedBy(p):
            return p
def getRequest():
    try:
        i = zope.security.management.getInteraction()  # raises NoInteraction
    except zope.security.interfaces.NoInteraction:
        return

    for p in i.participations:
        if IRequest.providedBy(p):
            return p
Example #12
0
 def getRequest(self):
     """ this trick will return the request from the working interaction
     see http://wiki.zope.org/zope3/FAQProgramming#how-do-i-get-irequest-object-in-event-handler
     """
     i = getInteraction()  # raises NoInteraction
     for i_request in i.participations:
         if IRequest.providedBy(i_request):
             return i_request
     raise RuntimeError('Could not find current request.')
 def get_request(self):
     try:
         i = getInteraction() # raises NoInteraction
     except NoInteraction:
         raise Exception("No request error.")
 
     for p in i.participations:
         if IRequest.providedBy(p):
             return p
     raise Exception("No request error.")
Example #14
0
def get_request():
    """ () -> either(IRequest, None)
    
    Raises zope.security.interfaces.NoInteraction if no interaction (and no 
    request).
    """
    # use queryInteraction() to raise
    interaction = getInteraction()
    for participation in interaction.participations:
        if IRequest.providedBy(participation):
            return participation
Example #15
0
    def test_chooseRequestClass(self):
        from zope.publisher.interfaces import IRequest, IPublication

        factoryRegistry.register('GET', '*', 'browser', 0, BrowserFactory())

        caller = functional.HTTPCaller()
        request_class, publication_class = caller.chooseRequestClass(
            method='GET', path='/', environment={})

        self.assert_(IRequest.implementedBy(request_class))
        self.assert_(IPublication.implementedBy(publication_class))
Example #16
0
def get_request():
    """ () -> either(IRequest, None)
    
    Raises zope.security.interfaces.NoInteraction if no interaction (and no 
    request).
    """
    # use queryInteraction() to raise 
    interaction = getInteraction()
    for participation in interaction.participations:
        if IRequest.providedBy(participation):
            return participation
Example #17
0
    def __init__(self, request):
        """Adapt IRequest.
        Do not call this class directly, always use a
        utils.theming_policy(request) adapter lookup.

        This enables overriding of the IThemingPolicy adapter
        via ZCML by integrators.

        When used as INoRequest adapter, returns the default policy.
        """
        if IRequest.providedBy(request):
            self.request = request
        else:
            self.request = None
Example #18
0
    def __init__(self, request):
        """Adapt IRequest.
        Do not call this class directly, always use a
        utils.theming_policy(request) adapter lookup.

        This enables overriding of the IThemingPolicy adapter
        via ZCML by integrators.

        When used as INoRequest adapter, returns the default policy.
        """
        if IRequest.providedBy(request):
            self.request = request
        else:
            self.request = None
Example #19
0
    def testTransactionAnnotation(self):
        from zope.interface import directlyProvides
        from zope.location.traversing import LocationPhysicallyLocatable
        from zope.location.interfaces import ILocation
        from zope.traversing.interfaces import IPhysicallyLocatable
        from zope.traversing.interfaces import IContainmentRoot

        component.provideAdapter(LocationPhysicallyLocatable, (ILocation,), IPhysicallyLocatable)

        def get_txn_info():
            if hasattr(self.storage, "iterator"):
                # ZODB 3.9
                txn_id = self.storage.lastTransaction()
                txn = list(self.storage.iterator(txn_id, txn_id))[0]
                txn_info = dict(
                    location=txn.extension["location"], user_name=txn.user, request_type=txn.extension["request_type"]
                )
            else:
                # ZODB 3.8
                txn_info = self.storage.undoInfo()[0]
            return txn_info

        root = self.db.open().root()
        root["foo"] = foo = LocatableObject()
        root["bar"] = bar = LocatableObject()
        bar.__name__ = "bar"
        foo.__name__ = "foo"
        bar.__parent__ = foo
        foo.__parent__ = root
        directlyProvides(root, IContainmentRoot)

        from zope.publisher.interfaces import IRequest

        expected_path = "/foo/bar"
        expected_user = "******" + self.user.id
        expected_request = IRequest.__module__ + "." + IRequest.getName()

        self.publication.afterCall(self.request, bar)
        txn_info = get_txn_info()
        self.assertEqual(txn_info["location"], expected_path)
        self.assertEqual(txn_info["user_name"], expected_user)
        self.assertEqual(txn_info["request_type"], expected_request)

        # also, assert that we still get the right location when
        # passing an instance method as object.
        self.publication.afterCall(self.request, bar.foo)
        txn_info = get_txn_info()
        self.assertEqual(txn_info["location"], expected_path)
    def testTransactionAnnotation(self):
        from zope.interface import directlyProvides
        from zope.location.traversing import LocationPhysicallyLocatable
        from zope.location.interfaces import ILocation
        from zope.traversing.interfaces import IPhysicallyLocatable
        from zope.traversing.interfaces import IContainmentRoot
        component.provideAdapter(LocationPhysicallyLocatable, (ILocation, ),
                                 IPhysicallyLocatable)

        def get_txn_info():
            if hasattr(self.storage, 'iterator'):
                # ZODB 3.9
                txn_id = self.storage.lastTransaction()
                txn = list(self.storage.iterator(txn_id, txn_id))[0]
                txn_info = dict(location=txn.extension['location'],
                                user_name=txn.user,
                                request_type=txn.extension['request_type'])
            else:
                # ZODB 3.8
                txn_info = self.storage.undoInfo()[0]
            return txn_info

        root = self.db.open().root()
        root['foo'] = foo = LocatableObject()
        root['bar'] = bar = LocatableObject()
        bar.__name__ = 'bar'
        foo.__name__ = 'foo'
        bar.__parent__ = foo
        foo.__parent__ = root
        directlyProvides(root, IContainmentRoot)

        from zope.publisher.interfaces import IRequest
        expected_path = "/foo/bar"
        expected_user = "******" + self.user.id
        expected_request = IRequest.__module__ + '.' + IRequest.getName()

        self.publication.afterCall(self.request, bar)
        txn_info = get_txn_info()
        self.assertEqual(txn_info['location'], expected_path)
        self.assertEqual(txn_info['user_name'], expected_user)
        self.assertEqual(txn_info['request_type'], expected_request)

        # also, assert that we still get the right location when
        # passing an instance method as object.
        self.publication.afterCall(self.request, bar.foo)
        txn_info = get_txn_info()
        self.assertEqual(txn_info['location'], expected_path)
Example #21
0
def getRequest():
    if ZOPE_2:
        # get request by acquisition
        site = getSite()
        if site is not None:
            try:
                return site.request
            except AttributeError:
                return site.REQUEST

    try:
        i = zope.security.management.getInteraction()
    except zope.security.interfaces.NoInteraction:
        return

    for p in i.participations:
        if IRequest.providedBy(p):
            return p
def classifySubscriber(item, event):
    """ A subscriber for an object event that fires a
    quotationtool.classify workflow process for this item."""
    pd = zope.component.getUtility(IProcessDefinition,
                                   name='quotationtool.classify')
    context = ClassificationContext(item)
    process = pd(context)
    contributor = u"unkown"
    for principal in getInteraction().participations:
        if IPrincipal.providedBy(principal):
            contributor = principal.id
        elif IRequest.providedBy(principal):
            contributor = principal.principal.id
        break
    history = IWorkflowHistory(item)
    process.start(contributor, datetime.datetime.now(),
                  _(u"Newly created items need to be classified."), history,
                  PersistentAttribution())
Example #23
0
def getRequest():
    if ZOPE_2:
        # get request by acquisition
        site = getSite()
        if site is not None:
            try:
                return site.request
            except AttributeError:
                return site.REQUEST

    try:
        i = zope.security.management.getInteraction()
    except zope.security.interfaces.NoInteraction:
        return

    for p in i.participations:
        if IRequest.providedBy(p):
            return p
    def testTransactionAnnotation(self):
        from zope.interface import directlyProvides
        from zope.location.traversing import LocationPhysicallyLocatable
        from zope.location.interfaces import ILocation
        from zope.traversing.interfaces import IPhysicallyLocatable
        from zope.traversing.interfaces import IContainmentRoot
        component.provideAdapter(LocationPhysicallyLocatable,
                                 (ILocation,), IPhysicallyLocatable)

        def get_txn_info():
            txn_id = self.storage.lastTransaction()
            txn = list(self.storage.iterator(txn_id, txn_id))[0]
            txn_info = dict(location=txn.extension['location'],
                            user_name=txn.user,
                            request_type=txn.extension['request_type'])
            return txn_info

        root = self.db.open().root()
        root['foo'] = foo = LocatableObject()
        root['bar'] = bar = LocatableObject()
        bar.__name__ = 'bar'
        foo.__name__ = 'foo'
        bar.__parent__ = foo
        foo.__parent__ = root
        directlyProvides(root, IContainmentRoot)

        from zope.publisher.interfaces import IRequest
        expected_path = "/foo/bar"
        expected_user = "******".format(self.user.id).encode('utf-8')
        expected_request = IRequest.__module__ + '.' + IRequest.getName()

        self.publication.afterCall(self.request, bar)
        txn_info = get_txn_info()
        self.assertEqual(txn_info['location'], expected_path)
        self.assertEqual(txn_info['user_name'], expected_user)
        self.assertEqual(txn_info['request_type'], expected_request)

        # also, assert that we still get the right location when
        # passing an instance method as object.
        self.publication.afterCall(self.request, bar.foo)
        txn_info = get_txn_info()
        self.assertEqual(txn_info['location'], expected_path)
Example #25
0
 def _getCurrentUserId(self):
     interaction = getInteraction()
     for participation in interaction.participations:
         if IRequest.providedBy(participation):
             return participation.principal.id
     raise RuntimeError(_("No IRequest in interaction"))
Example #26
0
 def _getCurrentUserId( self ):
     interaction = getInteraction()
     for participation in interaction.participations:
         if IRequest.providedBy(participation):
             return participation.principal.id
     return None
Example #27
0
 def _getCurrentUserId( self ):
     interaction = getInteraction()
     for participation in interaction.participations:
         if IRequest.providedBy(participation):
             return participation.principal.id
     raise RuntimeError(_("No IRequest in interaction"))