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 __new__(cls, context, request): parent = aq_parent(context) if IATEvent.providedBy(parent): return ATImageScaling(parent, request) elif IDXEvent.providedBy(parent): return DXImageScaling(parent, request) return None
def get_location(self): """In case location is not of type basestring, it's propably a reference, which case we handle here. """ context = self.context # Get the original location directly from the context, as in case of # reference, the accessor might return an string representing the # location instead of the referenced object. location = None if IATEvent.providedBy(context): location = context.getLocation() elif IDXEvent.providedBy(context): from plone.app.event.dx.behaviors import IEventLocation location = IEventLocation(context).location if location and not isinstance(location, basestring) and\ hasattr(location, 'absolute_url') and\ hasattr(location, 'Title'): # Then I'm a reference location = u'<a href="%s" title="%s">%s</a>' % ( location.absolute_url(), self.data.location, # A meaningful title, e.g. the address location.Title() ) return location
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 test_implementsInterfaces(self): """Test if an ATEvent object implements all relevant interfaces. """ self.assertTrue(IEvent.providedBy(self.obj)) self.assertTrue(IEventRecurrence.providedBy(self.obj)) self.assertTrue(IATEvent.providedBy(self.obj)) self.assertTrue(IATEventRecurrence.providedBy(self.obj)) self.assertTrue(IATEvent_ATCT.providedBy(self.obj)) self.assertTrue(verifyObject(IATEvent_ATCT, self.obj))
def test_occurrence(self): self.at.setRecurrence('RRULE:FREQ=WEEKLY;COUNT=10') # does not match occurrence date qdate = datetime.date.today() + datetime.timedelta(days=4) self.assertRaises( AttributeError, self.at_traverser.publishTraverse, self.layer['request'], str(qdate)) qdatedt = pydt(self.at.start() + 7) item = self.at_traverser.publishTraverse(self.layer['request'], str(qdatedt.date())) self.assertTrue(IOccurrence.providedBy(item)) self.assertTrue(IATEvent.providedBy(item.aq_parent))
def __cmp__(self, other): """Compare method. If other is based on ATEvent, compare start, duration and title. #If other is a number, compare duration and number If other is a DateTime instance, compare start date with date In all other cases there is no specific order. """ # TODO: maybe also include location to compate two events. # Please note that we can not use self.Title() here: the generated # edit accessor uses getToolByName, which ends up in # five.localsitemanager looking for a parent using a comparison # on this object -> infinite recursion. if IATEvent.providedBy(other): return cmp((self.start_date, self.duration, self.title), (other.start_date, other.duration, other.title)) elif isinstance(other, DateTime): return cmp(self.start(), other) else: # TODO come up with a nice cmp for types return cmp(self.title, other)