Exemplo n.º 1
0
 def testPeriodFromPool(self):
     """
         Test that period initiated with occurrence_pool returns the same occurrences as "straigh" period
         in a corner case whereby a period's start date is equal to the occurrence's end date
     """
     start = datetime.datetime(2008, 1, 5, 9, 0)
     end = datetime.datetime(2008, 1, 5, 10, 0)
     parent_period = Period(Event.objects.all(), start, end)
     period = Period(parent_period.events, start, end,
                     parent_period.get_persisted_occurrences(),
                     parent_period.occurrences)
     self.assertEquals(parent_period.occurrences, period.occurrences)
Exemplo n.º 2
0
 def test_moved_occurrences(self):
     occurrences = self.recurring_event.get_occurrences(start=self.start,
                                 end=self.end)
     moved_occurrence = occurrences[1]
     span_pre = (moved_occurrence.start, moved_occurrence.end)
     span_post = [x + datetime.timedelta(hours=2) for x in span_pre]
     # check has_occurrence on both periods
     period_pre = Period([self.recurring_event], span_pre[0], span_pre[1])
     period_post = Period([self.recurring_event], span_post[0], span_post[1])
     self.assertTrue(period_pre.has_occurrences())
     self.assertFalse(period_post.has_occurrences())
     # move occurrence
     moved_occurrence.move(moved_occurrence.start + datetime.timedelta(hours=2),
                           moved_occurrence.end + datetime.timedelta(hours=2))
     occurrences = self.recurring_event.get_occurrences(start=self.start,
                                 end=self.end)
     self.assertTrue(occurrences[1].moved)
     # check has_occurrence on both periods (the result should be reversed)
     period_pre = Period([self.recurring_event], span_pre[0], span_pre[1])
     period_post = Period([self.recurring_event], span_post[0], span_post[1])
     self.assertFalse(period_pre.has_occurrences())
     self.assertTrue(period_post.has_occurrences())
Exemplo n.º 3
0
 def setUp(self):
     rule = Rule(frequency="WEEKLY")
     rule.save()
     cal = Calendar(name="MyCal")
     cal.save()
     data = {
         'title': 'Recent Event',
         'start': datetime.datetime(2008, 1, 5, 8, 0),
         'end': datetime.datetime(2008, 1, 5, 9, 0),
         'end_recurring_period': datetime.datetime(2008, 5, 5, 0, 0),
         'rule': rule,
         'calendar': cal
     }
     recurring_event = Event(**data)
     recurring_event.save()
     self.period = Period(events=Event.objects.all(),
                          start=datetime.datetime(2008, 1, 4, 7, 0),
                          end=datetime.datetime(2008, 1, 21, 7, 0))
Exemplo n.º 4
0
def calendar_events(request, calendar_slug):
    """
    JSON events feed class conforming to the JQuery FullCalendar and
    jquery-week-calendar CalEvent standard.

    [1]: http://code.google.com/p/jquery-week-calendar/
    [2]: http://arshaw.com/fullcalendar
    Corresponds to: http://arshaw.com/fullcalendar/docs/#calevent-objects
    """
    calendar = get_object_or_404(Calendar, slug=calendar_slug)

    start = request.GET.get('start', None)
    end = request.GET.get('end', None)
    if settings.USE_TZ:
        start = start and datetime.datetime.fromtimestamp(int(start), tzutc())
        end = end and datetime.datetime.fromtimestamp(int(end), tzutc())
    else:
        start = start and datetime.datetime.fromtimestamp(int(start))
        end = end and datetime.datetime.fromtimestamp(int(end))

    events = GET_EVENTS_FUNC(request, calendar)
    period = Period(events, start, end)
    cal_events = []
    for o in period.get_occurrences():
        audience_bits = [
            x for x in o.event.appropriate_for.get_set_bits()
            if x in VALID_AUDIENCES
        ]
        audiences = [AUDIENCE_TYPES[x]['name'][0] for x in audience_bits]
        if o.event.all_day:
            start = o.start.date().isoformat()
            diff = o.end - o.start
            end = o.start.date() + datetime.timedelta(days=diff.days)
            end = end.isoformat()
        else:
            start = o.start.isoformat()
            end = o.end.isoformat()
        occurrence_id = encode_occurrence(o)
        cal_event = {
            'id':
            occurrence_id,
            'allDay':
            o.event.all_day,
            'event_id':
            o.event.pk,
            'start':
            start,
            'end':
            end,
            'title':
            "%s %s" % ("".join(audiences), o.title),
            'description':
            o.description,
            'delete_url':
            "%s?id=%s&action=cancel" %
            (reverse('ajax_edit_event',
                     kwargs={'calendar_slug': calendar_slug}), o.event.pk),
            'delete_occurrence_url':
            "%s?id=%s&action=cancel" %
            (reverse('ajax_edit_event',
                     kwargs={'calendar_slug': calendar_slug}), occurrence_id),
            'edit_url':
            reverse('admin:events_event_change', args=(o.event.pk, )),
            'update_url':
            reverse('ajax_edit_event', kwargs={'calendar_slug':
                                               calendar_slug}),
            'update_occurrence_url':
            "%s?id=%s" %
            (reverse('ajax_edit_event',
                     kwargs={'calendar_slug': calendar_slug}), occurrence_id),
            'repeating_id':
            o.event.rule_id,
            'repeating_name':
            getattr(o.event.rule, "name", ""),
            'repeats':
            o.event.rule is not None,
            'audiences':
            audiences,
        }
        cal_events.append(cal_event)

    return JSONResponse(cal_events)