Beispiel #1
0
def index(request):
    data = {"applications": get_applications(request)}
    msg = get_message_or_error(request)
    if msg:
        data.update(msg)
    if is_admin(request):
        return HttpResponseRedirect('/admin/')
    else:
        return render(request, 'index.html', data)
Beispiel #2
0
def create_application(request):
    if request.method == "GET":
        data = {"isAdmin": is_admin(request), "goods": get_goods(request)}
        msg = get_message_or_error(request)
        if msg:
            data.update(msg)
        return render(request, 'createApplication.html', data)
    elif request.method == "POST":
        data = form_body_to_json(request.body.decode('utf-8'))
        r = post_request(request, "applications", data)
        if r.status_code == 400:
            request.session['message'] = handle_error_response(
                json.loads(r.content.decode('utf-8')))
            return HttpResponseRedirect('/applications/create/')
        else:
            request.session['message'] = "Successfully created an application"
            return HttpResponseRedirect('/applications/')
Beispiel #3
0
def edit_good(request, good_id):
    if request.method == "GET":
        data = {
            "isAdmin": is_admin(request),
            "good": get_good(good_id, request)
        }
        msg = get_message_or_error(request)
        if msg:
            data.update(msg)
        return render(request, 'editGood.html', data)
    elif request.method == "POST":
        data = form_body_to_json(request.body.decode('utf-8'))
        r = put_request(request,
                        "goods",
                        data,
                        url_extension=str(good_id) + "/")
        if r.status_code == 400:
            request.session['message'] = handle_error_response(
                json.loads(r.content.decode('utf-8')))
            return HttpResponseRedirect('/goods/edit/' + str(good_id) + "/")
        else:
            request.session['message'] = "Successfully edited a good"
            return HttpResponseRedirect('/goods/')
Beispiel #4
0
def view_application(request, application_id):
    return render(
        request, 'viewApplication.html', {
            "isAdmin": is_admin(request),
            "application": get_application(application_id, request)
        })
Beispiel #5
0
def index(request):
    return render(
        request, 'admin.html', {
            "isAdmin": is_admin(request),
            "applications": get_admin_applications(request)
        })
Beispiel #6
0
def view_good(request, good_id):
    return render(request, 'viewGood.html', {
        "isAdmin": is_admin(request),
        "good": get_good(good_id, request)
    })
Beispiel #7
0
def index(request):
    data = {"isAdmin": is_admin(request), "goods": get_goods(request)}
    msg = get_message_or_error(request)
    if msg:
        data.update(msg)
    return render(request, 'viewGoods.html', data)