예제 #1
0
def index_new(request, group=None):
    group = get_object_or_404(Group, name=group) if \
        request.user in get_object_or_404(Group, name=group).user_set.all() else None
    order = get_order(group) if group else None
    poll = get_poll(group) if group else None
    r = dict()
    r['group'] = group
    r['order'] = order
    r['restaurants'] = Restaurant.objects.all()
    r['is_admin'] = is_admin(request)
    r['can_join'] = not in_other_orderline(order, request.user)
    r['feedme_groups'] = [
        g for g in get_feedme_groups() if request.user in g.user_set.all()
    ]

    a_id = None
    if str(request.user) != 'AnonymousUser':
        if Answer.objects.filter(poll=poll, user=request.user).count() == 1:
            a_id = Answer.objects.get(poll=poll, user=request.user)

    if request.method == 'POST':
        if request.POST['act'] == 'vote':
            if a_id is not None:
                form = PollAnswerForm(request.POST, instance=a_id)
            else:
                form = PollAnswerForm(request.POST)
            if form.is_valid():
                answer = form.save(commit=False)
                answer.user = request.user
                answer.poll = poll
                answer.save()
                messages.success(request, 'Voted for %s' % answer.answer)
                return redirect('feedme:feedme_index_new', group)

    if poll is not None:
        r['poll'] = poll
        if a_id is None:
            r['answer'] = PollAnswerForm()
        else:
            r['answer'] = PollAnswerForm(instance=a_id)
        r['results'] = poll.get_result()

    return render(request, 'feedme/index.html', r)
예제 #2
0
파일: views.py 프로젝트: dotKom/feedme
def index_new(request, group=None):
    group = get_object_or_404(Group, name=group) if \
        request.user in get_object_or_404(Group, name=group).user_set.all() else None
    order = get_order(group) if group else None
    poll = get_poll(group) if group else None
    r = dict()
    r['group'] = group
    r['order'] = order
    r['restaurants'] = Restaurant.objects.all()
    r['is_admin'] = is_admin(request)
    r['can_join'] = not in_other_orderline(order, request.user)
    r['feedme_groups'] = [g for g in get_feedme_groups() if request.user in g.user_set.all()]

    a_id = None
    if str(request.user) != 'AnonymousUser':
        if Answer.objects.filter(poll=poll, user=request.user).count() == 1:
            a_id = Answer.objects.get(poll=poll, user=request.user)

    if request.method == 'POST':
        if request.POST['act'] == 'vote':
            if a_id is not None:
                form = PollAnswerForm(request.POST, instance=a_id)
            else:
                form = PollAnswerForm(request.POST)
            if form.is_valid():
                answer = form.save(commit=False)
                answer.user = request.user
                answer.poll = poll
                answer.save()
                messages.success(request, 'Voted for %s' % answer.answer)
                return redirect('feedme:feedme_index_new', group)

    if poll is not None:
        r['poll'] = poll
        if a_id is None:
            r['answer'] = PollAnswerForm()
        else:
            r['answer'] = PollAnswerForm(instance=a_id)
        r['results'] = poll.get_result()

    return render(request, 'feedme/index.html', r)
예제 #3
0
파일: test_utils.py 프로젝트: dotKom/feedme
    def test_get_order_group_with_inactive_order(self):
        group = G(Group)
        poll = G(Poll, group=group, active=False)

        self.assertEquals(None, get_poll(group), "Got %s, expected %s." % (get_poll(group), None))
예제 #4
0
파일: test_utils.py 프로젝트: dotKom/feedme
    def test_get_order_group_with_active_order(self):
        group = G(Group)
        poll = G(Poll, group=group)

        self.assertEquals(poll, get_poll(group), "Got %s, expected %s." % (get_poll(group), poll))
예제 #5
0
파일: test_utils.py 프로젝트: dotKom/feedme
 def test_get_poll_no_poll_for_group(self):
     new_group = G(Group)
     self.assertEquals(None, get_poll(new_group), "There should be no polls for a group with no polls")
예제 #6
0
    def test_get_order_group_with_inactive_order(self):
        group = G(Group)
        poll = G(Poll, group=group, active=False)

        self.assertEquals(None, get_poll(group),
                          "Got %s, expected %s." % (get_poll(group), None))
예제 #7
0
    def test_get_order_group_with_active_order(self):
        group = G(Group)
        poll = G(Poll, group=group)

        self.assertEquals(poll, get_poll(group),
                          "Got %s, expected %s." % (get_poll(group), poll))
예제 #8
0
 def test_get_poll_no_poll_for_group(self):
     new_group = G(Group)
     self.assertEquals(
         None, get_poll(new_group),
         "There should be no polls for a group with no polls")