コード例 #1
0
 def setUp(self):
     self.timezone = pytz.timezone('Europe/Amsterdam')
     self.week = Week(
         events=Event.objects.all(),
         date=self.timezone.localize(datetime.datetime(2013, 12, 17, 9, 0)),
         tzinfo=self.timezone,
     )
コード例 #2
0
    def test_occurrences_outside_recurrence_period(self):
        start = self.MVD.localize(datetime.datetime(2017, 1, 23))

        period = Week(Event.objects.all(), start, tzinfo=self.MVD)

        self.assertEqual(
            ["%s to %s" % (o.start, o.end) for o in period.occurrences], [])
コード例 #3
0
ファイル: views.py プロジェクト: frederickney/NutriMenu
def category(request, category=None):

    if category:
        categorie = get_object_or_404(Category, slug=category)
        foods = Food.objects.filter(category=categorie)
        current_categorie = Category.objects.get(slug=category)
    else:
        foods = Food.objects.all()
        current_categorie = None

    categories = Category.objects.all()

    events = Week(foods, datetime.datetime(2008, 4, 1))

    paginator = Paginator(foods, 10) # Show 25 objects per page

    page = request.GET.get('page')
    try:
        page_objects = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        page_objects = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        page_objects = paginator.page(paginator.num_pages)

    return render(request, 'ads/meals.html', {'foods': page_objects,
                                            'categories': categories,
                                            'current_categorie': current_categorie,
                                            'events': events})
コード例 #4
0
    def test_occurrences_inside_recurrence_period(self):
        start = self.MVD.localize(datetime.datetime(2017, 1, 13))

        period = Week(Event.objects.all(), start, tzinfo=self.MVD)

        self.assertEqual(
            ["%s to %s" % (o.start, o.end) for o in period.occurrences], [
                '2017-01-13 15:00:00-03:00 to 2017-01-14 15:00:00-03:00',
                '2017-01-14 15:00:00-03:00 to 2017-01-15 15:00:00-03:00'
            ])
コード例 #5
0
    def test_occurrences_end_in_diff_tz(self):
        event = Event.objects.filter(title='Test event').get()
        AMSTERDAM = pytz.timezone('Europe/Amsterdam')
        # 2017-01-14 00:00 CET = 2017-01-13 21:00 UYT
        event.end_recurring_period = AMSTERDAM.localize(
            datetime.datetime(2017, 1, 14, 0, 0))
        start = self.MVD.localize(datetime.datetime(2017, 1, 13))

        period = Week([event], start, tzinfo=self.MVD)

        self.assertEqual(
            ["%s to %s" % (o.start, o.end) for o in period.occurrences],
            ['2017-01-13 15:00:00-03:00 to 2017-01-14 15:00:00-03:00'])
コード例 #6
0
    def test_occurrences_no_end(self):
        event = Event.objects.filter(title='Test event').get()
        event.end_recurring_period = None
        start = self.MVD.localize(datetime.datetime(2018, 1, 13))

        period = Week([event], start, tzinfo=self.MVD)

        self.assertEqual(
            ["%s to %s" % (o.start, o.end) for o in period.occurrences], [
                '2018-01-06 15:00:00-03:00 to 2018-01-07 15:00:00-03:00',
                '2018-01-07 15:00:00-03:00 to 2018-01-08 15:00:00-03:00',
                '2018-01-08 15:00:00-03:00 to 2018-01-09 15:00:00-03:00',
                '2018-01-09 15:00:00-03:00 to 2018-01-10 15:00:00-03:00',
                '2018-01-10 15:00:00-03:00 to 2018-01-11 15:00:00-03:00',
                '2018-01-11 15:00:00-03:00 to 2018-01-12 15:00:00-03:00',
                '2018-01-12 15:00:00-03:00 to 2018-01-13 15:00:00-03:00',
                '2018-01-13 15:00:00-03:00 to 2018-01-14 15:00:00-03:00'
            ])