コード例 #1
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)
コード例 #2
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)
コード例 #3
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)
コード例 #4
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)