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

        self.assertEquals(next_tuesday, get_next_tuesday(), "Got %s, expected %s" % (get_next_tuesday(), next_tuesday))
Beispiel #2
0
    def test_get_next_tuesday(self):
        d = date.today()
        days_ahead = 1 - d.weekday()  # Monday 0, Tuesday 1, ...
        if days_ahead < 0:  # Has already happened, use <= if include today too
            days_ahead += 7
        next_tuesday = d + timedelta(days=days_ahead)

        self.assertEquals(
            next_tuesday, get_next_tuesday(),
            "Got %s, expected %s" % (get_next_tuesday(), next_tuesday))
Beispiel #3
0
def new_poll(request, group=None):
    group = get_object_or_404(Group, name=group)
    if request.method == 'POST':
        form = NewPollForm(request.POST)
        if form.is_valid():
            form.save()
            messages.success(request, 'New poll added')
            logger.info('%s created a new poll for %s.' %
                        (request.user, group))
            return redirect('feedme:feedme_index_new', group)
        else:
            messages.error(request, 'Form not validated')
    else:
        form = NewPollForm()
        form.fields['question'].initial = "Hvor skal %s spise?" % group.name
        form.fields['due_date'].initial = get_next_tuesday()
        form.fields['group'].initial = group

    r = dict()
    r['feedme_groups'] = [
        g for g in get_feedme_groups() if request.user in g.user_set.all()
    ]
    r['group'] = group
    r['form'] = form
    r['is_admin'] = is_admin(request)

    return render(request, 'feedme/admin.html', r)
Beispiel #4
0
def new_poll(request, group=None):
    group = get_object_or_404(Group, name=group)
    if request.method == 'POST':
        form = NewPollForm(request.POST)
        if form.is_valid():
            form.save()
            messages.success(request, 'New poll added')
            logger.info('%s created a new poll for %s.' % (request.user, group))
            return redirect('feedme:feedme_index_new', group)
        else:
            messages.error(request, 'Form not validated')
    else:
        form = NewPollForm()
        form.fields['question'].initial = "Hvor skal %s spise?" % group.name
        form.fields['due_date'].initial = get_next_tuesday()
        form.fields['group'].initial = group

    r = dict()
    r['feedme_groups'] = [g for g in get_feedme_groups() if request.user in g.user_set.all()]
    r['group'] = group
    r['form'] = form
    r['is_admin'] = is_admin(request)

    return render(request, 'feedme/admin.html', r)