Exemplo n.º 1
0
def ticket_title_generator(obj):
    """Generate a title for the ticket, also using event information.
    """

    event = obj
    ret = {
        'title': obj.title, 'eventtitle': '', 'eventstart': '', 'eventend': ''
    }

    if ITicketOccurrence.providedBy(event):
        event = aq_parent(aq_parent(event))
        # Traverse to the Occurrence object
        if IATEvent.providedBy(event):
            # get the request out of thin air to be able to publishTraverse to
            # the transient Occurrence object.
            traverser = OccTravAT(event, getRequest())
        elif IDXEvent.providedBy(event):
            # TODO
            traverser = OccTravDX(event, getRequest())
        else:
            raise NotImplementedError(
                u"There is no event occurrence traverser implementation for "
                u"this kind of object."
            )
        try:
            event = traverser.publishTraverse(getRequest(), obj.id)
        except KeyError:
            # Maybe the ticket occurrence isn't valid anymore because the
            # event occurence doesn't exist anymore.
            # Just ignore that case.
            return ret

    elif ITicket.providedBy(event):
        event = aq_parent(event)

    if IEvent.providedBy(event) or IOccurrence.providedBy(event):
        acc = IEventAccessor(event)
        lstart = ulocalized_time(
            DT(acc.start),
            long_format=True,
            context=event
        )
        lend = ulocalized_time(
            DT(acc.start),
            long_format=True,
            context=event
        )
        # XXX: no unicode, store as utf-8 encoded string instead
        ret = dict(
            title=u'%s - %s (%s - %s)' % (
                safe_unicode(acc.title),
                safe_unicode(obj.title),
                lstart,
                lend,
            ),
            eventtitle=acc.title,
            eventstart=acc.start,
            eventend=acc.end,
        )
    return ret
def ticket_wf_changed(obj, event):
    if ITicketOccurrence.providedBy(obj):
        # Don't change state for subobjects of TicketOccurrence and avoid
        # infinite loops. We land in here after changing the state for
        # TicketOccurrence objects.
        return
    wft = getToolByName(obj, 'portal_workflow')
    changed = []
    failed = []
    for sub in obj.contentValues():
        if not ITicketOccurrence.providedBy(sub):
            # WTF? continue.
            continue
        try:
            wft.doActionFor(sub, event.action)
            changed.append(sub)
        except WorkflowException:
            failed.append(sub)

    state = wft.getInfoFor(obj, 'review_state')
    if changed:
        msg = _(
            'msg_changed_ticketoccurrence_workflow',
            default=u"Set the workflow to ${state} for these "
                    u"Ticket Occurrences: ${items}.",
            mapping={
                'state': state,
                'items': ', '.join([it.id for it in changed])
            }

        )
        IStatusMessage(getRequest()).addStatusMessage(msg, 'info')

    if failed:
        msg = _(
            'msg_failed_ticketoccurrence_workflow',
            default=u"Failed to set the workflow to ${state} for these "
                    u"Ticket Occurrences: ${items}.",
            mapping={
                'state': state,
                'items': ', '.join([
                    '{} ({})'.format(it.id, wft.getInfoFor(it, 'review_state'))
                    for it in failed])
            }

        )
        IStatusMessage(getRequest()).addStatusMessage(msg, 'warning')
Exemplo n.º 3
0
def ticket_wf_changed(obj, event):
    if ITicketOccurrence.providedBy(obj):
        # Don't change state for subobjects of TicketOccurrence and avoid
        # infinite loops. We land in here after changing the state for
        # TicketOccurrence objects.
        return
    wft = getToolByName(obj, 'portal_workflow')
    changed = []
    failed = []
    for sub in obj.contentValues():
        if not ITicketOccurrence.providedBy(sub):
            # WTF? continue.
            continue
        try:
            wft.doActionFor(sub, event.action)
            changed.append(sub)
        except WorkflowException:
            failed.append(sub)

    state = wft.getInfoFor(obj, 'review_state')
    if changed:
        msg = _('msg_changed_ticketoccurrence_workflow',
                default=u"Set the workflow to ${state} for these "
                u"Ticket Occurrences: ${items}.",
                mapping={
                    'state': state,
                    'items': ', '.join([it.id for it in changed])
                })
        IStatusMessage(getRequest()).addStatusMessage(msg, 'info')

    if failed:
        msg = _('msg_failed_ticketoccurrence_workflow',
                default=u"Failed to set the workflow to ${state} for these "
                u"Ticket Occurrences: ${items}.",
                mapping={
                    'state':
                    state,
                    'items':
                    ', '.join([
                        '{} ({})'.format(it.id,
                                         wft.getInfoFor(it, 'review_state'))
                        for it in failed
                    ])
                })
        IStatusMessage(getRequest()).addStatusMessage(msg, 'warning')
Exemplo n.º 4
0
def ticket_title_generator(obj):
    """Generate a title for the ticket, also using event information.
    """

    event = obj
    ret = {
        'title': obj.title,
        'eventtitle': '',
        'eventstart': '',
        'eventend': ''
    }

    if ITicketOccurrence.providedBy(event):
        event = aq_parent(aq_parent(event))
        # Traverse to the Occurrence object
        if IATEvent.providedBy(event):
            # get the request out of thin air to be able to publishTraverse to
            # the transient Occurrence object.
            traverser = OccTravAT(event, getRequest())
        elif IDXEvent.providedBy(event):
            # TODO
            traverser = OccTravDX(event, getRequest())
        else:
            raise NotImplementedError(
                u"There is no event occurrence traverser implementation for "
                u"this kind of object.")
        try:
            event = traverser.publishTraverse(getRequest(), obj.id)
        except KeyError:
            # Maybe the ticket occurrence isn't valid anymore because the
            # event occurence doesn't exist anymore.
            # Just ignore that case.
            return ret

    elif ITicket.providedBy(event):
        event = aq_parent(event)

    if IEvent.providedBy(event) or IOccurrence.providedBy(event):
        acc = IEventAccessor(event)
        lstart = ulocalized_time(DT(acc.start),
                                 long_format=True,
                                 context=event)
        lend = ulocalized_time(DT(acc.start), long_format=True, context=event)
        # XXX: no unicode, store as utf-8 encoded string instead
        ret = dict(
            title=u'%s - %s (%s - %s)' % (
                safe_unicode(acc.title),
                safe_unicode(obj.title),
                lstart,
                lend,
            ),
            eventtitle=acc.title,
            eventstart=acc.start,
            eventend=acc.end,
        )
    return ret
Exemplo n.º 5
0
def _get_event_url(ticket):
    """Return the URL to an event or event occurrence for a ticket or ticket
    occurrence.
    """

    url = ticket.absolute_url()

    if ITicketOccurrence.providedBy(ticket):
        # assumption1: ticketoccurrence id = occurrence id
        # assumption2: ticketoccurrence parent = ticket
        event = aq_parent(aq_parent(ticket))
        if IEvent.providedBy(event):
            url = "{}/{}".format(event.absolute_url(), ticket.id)

    elif ITicket.providedBy(ticket):
        event = aq_parent(ticket)
        if IEvent.providedBy(event):
            url = event.absolute_url()

    return url
Exemplo n.º 6
0
def _get_event_url(ticket):
    """Return the URL to an event or event occurrence for a ticket or ticket
    occurrence.
    """

    url = ticket.absolute_url()

    if ITicketOccurrence.providedBy(ticket):
        # assumption1: ticketoccurrence id = occurrence id
        # assumption2: ticketoccurrence parent = ticket
        event = aq_parent(aq_parent(ticket))
        if IEvent.providedBy(event):
            url = '{}/{}'.format(event.absolute_url(), ticket.id)

    elif ITicket.providedBy(ticket):
        event = aq_parent(ticket)
        if IEvent.providedBy(event):
            url = event.absolute_url()

    return url