예제 #1
0
    def test_join_multiple_orderlines_as_buddy(self):
        self.order.group = self.group

        self.assertTrue(in_other_orderline(self.order, self.user),
                        'User should be in another orderline')
        self.assertFalse(in_other_orderline(self.order, self.user3),
                         'User should not be in another orderline')
예제 #2
0
파일: views.py 프로젝트: dotKom/feedme
def join_orderline(request, group, orderline_id):
    orderline = get_object_or_404(OrderLine, pk=orderline_id)
    group = get_object_or_404(Group, name=group)
    # @TODO if not buddy system enabled, disable join
    if in_other_orderline(get_order(group), request.user):
        messages.error(request, 'You cannot be in multiple orderlines')
        logger.warn('%s tried to join multiple orderlines (new: %i) for "%s"!' %
                   (request.user, orderline.id, get_order(group)))
    elif orderline.order.use_validation and \
            not validate_user_funds(
                request.user, (orderline.price / (orderline.users.count() + 1))):  # Adds us to the test as well
        messages.error(request, 'You need cashes')
        logger.info('%s tried to join an orderline for "%s", by %s,  with insufficient funds.' %
                    (request.user, orderline.order, orderline.creator))
    else:
        orderline.users.add(request.user)
        orderline.save()
        messages.success(request, 'Joined orderline')
    return redirect('feedme:feedme_index_new', group)
예제 #3
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)
예제 #4
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)
예제 #5
0
def join_orderline(request, group, orderline_id):
    orderline = get_object_or_404(OrderLine, pk=orderline_id)
    group = get_object_or_404(Group, name=group)
    # @TODO if not buddy system enabled, disable join
    if in_other_orderline(get_order(group), request.user):
        messages.error(request, 'You cannot be in multiple orderlines')
        logger.warn(
            '%s tried to join multiple orderlines (new: %i) for "%s"!' %
            (request.user, orderline.id, get_order(group)))
    elif orderline.order.use_validation and \
            not validate_user_funds(
                request.user, (orderline.price / (orderline.users.count() + 1))):  # Adds us to the test as well
        messages.error(request, 'You need cashes')
        logger.info(
            '%s tried to join an orderline for "%s", by %s,  with insufficient funds.'
            % (request.user, orderline.order, orderline.creator))
    else:
        orderline.users.add(request.user)
        orderline.save()
        messages.success(request, 'Joined orderline')
    return redirect('feedme:feedme_index_new', group)
예제 #6
0
파일: test_tests.py 프로젝트: dotKom/feedme
    def test_join_multiple_orderlines_as_buddy(self):
        self.order.group = self.group

        self.assertTrue(in_other_orderline(self.order, self.user), 'User should be in another orderline')
        self.assertFalse(in_other_orderline(self.order, self.user3), 'User should not be in another orderline')