示例#1
0
def accept_contract(request, pk):
    contract = get_object_or_404(Contract, pk=pk)
    if request.method == "POST":
        form = Form(request.POST)
        if form.is_valid() and contract.can_accept_or_reject(request.user):
            change_contract_status(contract, "accepted", True)
    return HttpResponseRedirect(reverse("view_contract", args=[pk]))
示例#2
0
def clientDelete(request, id):
    client = get_object_or_404(Client, pk=id)
    if request.method == "POST":
        form = Form(request.POST)
        if form.is_valid():
            client.user.delete()
    return redirect('my_site:index')
示例#3
0
def userDelete(request, id):
    user = get_object_or_404(Owner, pk=id)
    if request.method == "POST":
        form = Form(request.POST)
        if form.is_valid():
            user.user.delete()
    return redirect('my_site:index')
示例#4
0
def save_attribute_form(request: HttpRequest, workflow: Workflow,
                        template: str, form: forms.Form,
                        attr_idx: int) -> JsonResponse:
    """Process the AJAX request to create or update an attribute.

    :param request: Request object received

    :param workflow: current workflow being manipulated

    :param template: Template to render in the response

    :param form: Form used to ask for data

    :param attr_idx: Index of the attribute being manipulated

    :return: AJAX reponse
    """
    if request.method == 'POST' and form.is_valid():
        # Correct form submitted
        if not form.has_changed():
            return JsonResponse({'html_redirect': None})

        # proceed with updating the attributes.
        wf_attributes = workflow.attributes

        # If key_idx is not -1, this means we are editing an existing pair
        if attr_idx != -1:
            key = sorted(wf_attributes.keys())[attr_idx]
            wf_attributes.pop(key)

            # Rename the appearances of the variable in all actions
            for action_item in workflow.actions.all():
                action_item.rename_variable(key, form.cleaned_data['key'])

        # Update value
        wf_attributes[
            form.cleaned_data['key']] = form.cleaned_data['attr_value']

        workflow.attributes = wf_attributes
        workflow.save()

        # Log the event
        Log.objects.register(
            request.user, Log.WORKFLOW_ATTRIBUTE_CREATE, workflow, {
                'id': workflow.id,
                'name': workflow.name,
                'attr_key': form.cleaned_data['key'],
                'attr_val': form.cleaned_data['attr_value']
            })

        return JsonResponse({'html_redirect': ''})

    return JsonResponse({
        'html_form':
        render_to_string(template, {
            'form': form,
            'id': attr_idx
        },
                         request=request),
    })
示例#5
0
def reject_contract(request, pk):
    contract = get_object_or_404(Contract, pk=pk)
    if request.method == "POST":
        form = Form(request.POST)
        if form.is_valid() and contract.can_change_status_to(
                request.gooseuser, "rejected"):
            change_contract_status(contract, "rejected")
    return HttpResponseRedirect(reverse("view_contract", args=[pk]))
示例#6
0
文件: views.py 项目: bourzua/TIL_real
def write(request):
    if request.method == 'POST':
        form = Form(request.POST)
        if form.is_valid():
            form.save()
    else:
        form = Form()

    return render(request, 'write.html', {'form': form})
示例#7
0
def reject_contract(request, pk):
    contract = get_object_or_404(Contract, pk=pk)
    if request.method == "POST":
        form = Form(request.POST)
        if form.is_valid() and contract.can_accept_or_reject(request.user):
            contract.status = "rejected"
            log = []
            for item in contract.inventoryitem_set.all():
                log.append(
                    {
                        "id": item.id,
                        "item": str(item),
                        "quantity": item.quantity,
                        "status": item.status(),
                        "loot_group_id": item.loot_group and item.loot_group.id,
                    }
                )
            contract.log = json.dumps(log, cls=ComplexEncoder)
            contract.full_clean()
            contract.save()
            contract.inventoryitem_set.update(contract=None)
    return HttpResponseRedirect(reverse("view_contract", args=[pk]))