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)
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/')
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/')
def view_application(request, application_id): return render( request, 'viewApplication.html', { "isAdmin": is_admin(request), "application": get_application(application_id, request) })
def index(request): return render( request, 'admin.html', { "isAdmin": is_admin(request), "applications": get_admin_applications(request) })
def view_good(request, good_id): return render(request, 'viewGood.html', { "isAdmin": is_admin(request), "good": get_good(good_id, request) })
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)