예제 #1
0
파일: test_utils.py 프로젝트: dotKom/feedme
 def test_manually_parse_users_one(self):
     chosen_user = G(User, id=2)
     list_of_available_users = """<form><select><option value="1">Testbruker</option><option value="2" selected>Testbruker Valgt</option></select>"""
     chosen_users = [chosen_user]
     self.assertEquals(chosen_users, manually_parse_users(list_of_available_users),
             "Got %s, expected %s" % \
                     (manually_parse_users(list_of_available_users), chosen_users))
예제 #2
0
 def test_manually_parse_users_one(self):
     chosen_user = G(User, id=2)
     list_of_available_users = """<form><select><option value="1">Testbruker</option><option value="2" selected>Testbruker Valgt</option></select>"""
     chosen_users = [chosen_user]
     self.assertEquals(chosen_users, manually_parse_users(list_of_available_users),
             "Got %s, expected %s" % \
                     (manually_parse_users(list_of_available_users), chosen_users))
예제 #3
0
파일: views.py 프로젝트: dotKom/feedme
def create_orderline(request, group=None):
    r = dict()
    group = get_object_or_404(Group, name=group)

    if request.method == 'POST':
        form = OrderLineForm(request.POST)
        if form.is_valid():
            new_orderline = form.save(commit=False)
            new_orderline.creator = request.user
            new_orderline.order = get_order(group)
            users = manually_parse_users(form)
            if check_orderline(group, new_orderline.creator, new_orderline.price, buddies=users):
                new_orderline.save()
                form.save_m2m()  # Manually save the m2m relations when using commit=False
                new_orderline.users.add(new_orderline.creator)
                messages.success(request, 'Added orderline')
                return redirect('feedme:feedme_index_new', group)
            else:
                messages.error(request, 'Failed to add orderline')
    else:
        form = OrderLineForm()
        form.fields["users"].queryset = get_order(group).available_users().exclude(id=request.user.id)

    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/orderview.html', r)
예제 #4
0
def orderlineview(request, orderline_id=None, group=None):
    new_or_existing_orderline = 'new'
    if orderline_id is None:
        orderline = OrderLine()
        creator = None
    else:
        orderline = get_object_or_404(OrderLine, pk=orderline_id)
        new_or_existing_orderline = 'existing'
        creator = orderline.creator

    group = get_object_or_404(Group, name=group)

    if request.method == 'POST':
        form = OrderLineForm(request.POST, instance=orderline)
        if form.is_valid():
            new_orderline = form.save(commit=False)
            if creator is not None:
                new_orderline.creator = creator
            else:
                new_orderline.creator = request.user
            new_orderline.order = get_order(group)
            users = manually_parse_users(form)
            if check_orderline(group, creator, orderline.price, buddies=users):
                new_orderline.save()
                form.save_m2m(
                )  # Manually save the m2m relations when using commit=False
                if new_or_existing_orderline == 'new':
                    messages.success(request, "Orderline added")
                else:
                    messages.success(request, "Orderline edited")
                new_orderline.users.add(new_orderline.creator)
                return redirect('feedme:feedme_index_new', group)
            else:
                messages.error(
                    request,
                    "Orderline validation failed, please verify your data and try again."
                )
    else:
        form = OrderLineForm(instance=orderline)
        form.fields["users"].queryset = get_order(
            group).available_users().exclude(id=request.user.id)

    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/orderview.html', r)
예제 #5
0
파일: views.py 프로젝트: dotKom/feedme
def orderlineview(request, orderline_id=None, group=None):
    new_or_existing_orderline = 'new'
    if orderline_id is None:
        orderline = OrderLine()
        creator = None
    else:
        orderline = get_object_or_404(OrderLine, pk=orderline_id)
        new_or_existing_orderline = 'existing'
        creator = orderline.creator

    group = get_object_or_404(Group, name=group)

    if request.method == 'POST':
        form = OrderLineForm(request.POST, instance=orderline)
        if form.is_valid():
            new_orderline = form.save(commit=False)
            if creator is not None:
                new_orderline.creator = creator
            else:
                new_orderline.creator = request.user
            new_orderline.order = get_order(group)
            users = manually_parse_users(form)
            if check_orderline(group, creator, orderline.price, buddies=users):
                new_orderline.save()
                form.save_m2m()  # Manually save the m2m relations when using commit=False
                if new_or_existing_orderline == 'new':
                    messages.success(request, "Orderline added")
                else:
                    messages.success(request, "Orderline edited")
                new_orderline.users.add(new_orderline.creator)
                return redirect('feedme:feedme_index_new', group)
            else:
                messages.error(request, "Orderline validation failed, please verify your data and try again.")
    else:
        form = OrderLineForm(instance=orderline)
        form.fields["users"].queryset = get_order(group).available_users().exclude(id=request.user.id)

    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/orderview.html', r)
예제 #6
0
def create_orderline(request, group=None):
    r = dict()
    group = get_object_or_404(Group, name=group)

    if request.method == 'POST':
        form = OrderLineForm(request.POST)
        if form.is_valid():
            new_orderline = form.save(commit=False)
            new_orderline.creator = request.user
            new_orderline.order = get_order(group)
            users = manually_parse_users(form)
            if check_orderline(group,
                               new_orderline.creator,
                               new_orderline.price,
                               buddies=users):
                new_orderline.save()
                form.save_m2m(
                )  # Manually save the m2m relations when using commit=False
                new_orderline.users.add(new_orderline.creator)
                messages.success(request, 'Added orderline')
                return redirect('feedme:feedme_index_new', group)
            else:
                messages.error(request, 'Failed to add orderline')
    else:
        form = OrderLineForm()
        form.fields["users"].queryset = get_order(
            group).available_users().exclude(id=request.user.id)

    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/orderview.html', r)