def _getObjectInfo(self, obj):
        ''' XXX this has to be simplified
        '''
        def getHostname(request):
            """
            stolen from the developer manual
            """

            if "HTTP_X_FORWARDED_HOST" in request.environ:
                # Virtual host
                host = request.environ["HTTP_X_FORWARDED_HOST"]
            elif "HTTP_HOST" in request.environ:
                # Direct client request
                host = request.environ["HTTP_HOST"]
            else:
                return None

            # separate to domain name and port sections
            host = host.split(":")[0].lower()

            return host

        def getUser(context):
            portal_membership = getToolByName(getSite(), 'portal_membership')
            return portal_membership.getAuthenticatedMember()

        data = dict(performed_on=datetime.utcnow(),
                    user=getUser(obj).getUserName(),
                    site_name=getHostname(self.request),
                    uid=getUID(obj),
                    type=obj.portal_type,
                    title=obj.Title(),
                    path='/'.join(obj.getPhysicalPath()))
        return data
Beispiel #2
0
def archetypes_initialized(event):
    """Pick up the delayed IObjectAddedEvent when an Archetypes object is
    initialised.
    """
    obj = event.object
    if is_portal_factory(obj):
        return

    if not IBaseObject.providedBy(obj):
        return

    cr_handlers.init()
    delayed_event = cr_handlers._status.delayed_events.get(
        'IObjectInitializedEvent-audit-%s' % getUID(obj), None)
    if delayed_event is not None:
        cr_handlers._status.delayed_events[
            'IObjectInitializedEvent-audit-%s' % getUID(obj)] = None
        execute_event(delayed_event)
Beispiel #3
0
def created_event(event):
    obj = event.object

    if is_portal_factory(obj):
        return

    if IObjectCopiedEvent.providedBy(event):
        return  # ignore this event since we're listening to cloned instead
    # The object added event executes too early for Archetypes objects.
    # We need to delay execution until we receive a subsequent
    # IObjectInitializedEvent
    if IBaseObject.providedBy(obj):
        cr_handlers.init()
        cr_handlers._status.delayed_events[
            'IObjectInitializedEvent-audit-%s' % getUID(obj)] = event
    elif IContentish.providedBy(obj) or IComment.providedBy(obj):
        execute_event(event)
    else:
        return
    def _getObjectInfo(self, obj):
        ''' XXX this has to be simplified
        '''

        def getHostname(request):
            """
            stolen from the developer manual
            """

            if "HTTP_X_FORWARDED_HOST" in request.environ:
                # Virtual host
                host = request.environ["HTTP_X_FORWARDED_HOST"]
            elif "HTTP_HOST" in request.environ:
                # Direct client request
                host = request.environ["HTTP_HOST"]
            else:
                return None

            # separate to domain name and port sections
            host = host.split(":")[0].lower()

            return host

        def getUser(context):
            portal_membership = getToolByName(getSite(), 'portal_membership')
            return portal_membership.getAuthenticatedMember()

        data = dict(
            performed_on=datetime.utcnow(),
            user=getUser(obj).getUserName(),
            site_name=getHostname(self.request),
            uid=getUID(obj),
            type=obj.portal_type,
            title=obj.Title(),
            path='/'.join(obj.getPhysicalPath())
        )
        return data