Beispiel #1
0
    def test_get_next_wednesday(self):
        d = date.today()
        days_ahead = 2 - d.weekday()  # Monday 0, Tuesday 1, ...
        if days_ahead < 0:  # Has already happened, use <= if include today too
            days_ahead += 7
        next_wednesday = d + timedelta(days=days_ahead)

        self.assertEquals(
            next_wednesday, get_next_wednesday(),
            "Got %s, expected %s" % (get_next_wednesday(), next_wednesday))
Beispiel #2
0
def admin(request, group=None):
    # Admin index - defaults to new order page
    r = dict()
    group = get_object_or_404(Group, name=group)

    if request.method == 'POST':
        form = NewOrderForm(request.POST)
        if form.is_valid():
            form.save()
            poll = Poll.get_active()
            if poll:
                poll.deactivate()
            messages.success(request, 'New order added')
            logger.info('%s created a new order for %s: "%s".' % (request.user, group, get_order(group)))
            return redirect('feedme:feedme_index_new', group)
    else:
        form = NewOrderForm()
        if Poll.objects.count() > 0:
            poll = Poll.get_active()
            if poll:
                form.fields['restaurant'].initial = poll.get_winner()
        form.fields["date"].initial = get_next_wednesday()

    # r['form'] = form
    r['feedme_groups'] = [g for g in get_feedme_groups() if request.user in g.user_set.all()]
    r['group'] = group
    r['is_admin'] = is_admin(request)
    return render(request, 'feedme/admin.html', r)
Beispiel #3
0
def admin(request, group=None):
    # Admin index - defaults to new order page
    r = dict()
    group = get_object_or_404(Group, name=group)

    if request.method == 'POST':
        form = NewOrderForm(request.POST)
        if form.is_valid():
            form.save()
            poll = Poll.get_active()
            if poll:
                poll.deactivate()
            messages.success(request, 'New order added')
            logger.info('%s created a new order for %s: "%s".' %
                        (request.user, group, get_order(group)))
            return redirect('feedme:feedme_index_new', group)
    else:
        form = NewOrderForm()
        if Poll.objects.count() > 0:
            poll = Poll.get_active()
            if poll:
                form.fields['restaurant'].initial = poll.get_winner()
        form.fields["date"].initial = get_next_wednesday()

    # r['form'] = form
    r['feedme_groups'] = [
        g for g in get_feedme_groups() if request.user in g.user_set.all()
    ]
    r['group'] = group
    r['is_admin'] = is_admin(request)
    return render(request, 'feedme/admin.html', r)
Beispiel #4
0
    def test_get_next_wednesday(self):
        d = date.today()
        days_ahead = 2 - d.weekday()  # Monday 0, Tuesday 1, ...
        if days_ahead < 0:  # Has already happened, use <= if include today too
            days_ahead += 7
        next_wednesday = d + timedelta(days=days_ahead)

        self.assertEquals(next_wednesday, get_next_wednesday(), "Got %s, expected %s" % (get_next_wednesday(), next_wednesday))