def order(request, ordering): if auth.isLogin(request) and auth.hasProfile(auth.get_user_data(request).uuid): parts = json.loads(request.body)["order_list"].split(",") parts = map(lambda x: x.split(":"), parts) parts_detail = map(lambda x: [retrieve_component_detail(x[0]), int(x[1])], parts) non_exist_or_noprice = filter(lambda x: x[0].unit_price <= 0, parts_detail) part_detail_dicts = map(lambda x: addquantity(model_to_dict(x[0]), x[1]), parts_detail) part_detail_dicts = map(lambda x: removekey(x, "associated_order"), part_detail_dicts) part_detail_dicts = map(lambda x: removekey(x, "id"), part_detail_dicts) # XXX: show pass common name to front end # map(lambda x: operator.setitem(x, "generic_type", model_to_dict(GComponents.objects.get(pk = x["generic_type"]))), part_detail_dicts) # map(lambda x: x["generic_type"].pop("id"), part_detail_dicts) # map(lambda x: x["generic_type"].pop("ctype"), part_detail_dicts) response = HttpResponse(json.dumps(part_detail_dicts)) if len(non_exist_or_noprice): response.status_code = 400 else: if ordering: user = auth.get_user_data(request) profile = auth.get_user_profile(request) create_order(user, profile, parts_detail) mail.send_order_received(request) response.status_code = 200 return response else: response = HttpResponse() response.status_code = 403 return response
def send_order_received(request): user = get_user_profile(request) subject, text = get_subject_and_text("test", {}, {"real_name": user.real_name}) return requests.post( keys.MAILGUN_API_URL, auth=("api", keys.MAILGUN_API_KEY), data={"from": "*****@*****.**", "to": [user.email], "subject": subject, "text": text} )
def chatroom(request): if auth.isLogin(request): data = auth.get_user_data(request) if auth.hasProfile(data.uuid): profile = auth.get_user_profile(request) return render(request, "chatroom.html", {'username' : profile.username, 'disp': 'static'}) else: return redirect("/profile/") else: return render(request, "chatroom.html", {'username' : '', 'disp': 'none'})
def order_page(request): if auth.isLogin(request): data = auth.get_user_data(request) if auth.hasProfile(data.uuid): profile = auth.get_user_profile(request) return render( request, "order.html", { "realname": profile.real_name, "email": profile.email, "shipping_address": profile.default_shipping_address, "phone": profile.phone_number, }, ) else: return redirect("/profile/") response = HttpResponse() response.status_code = 403 return response
def profile(request): if isLogin(request): data = auth.get_user_data(request) if auth.hasProfile(data.uuid): profile = auth.get_user_profile(request) return render( request, "profile.html", { "realname": profile.real_name, "email": profile.email, "username": profile.username, "shipping_address": profile.default_shipping_address, "id": profile.tw_id, "phone": profile.phone_number, }, ) else: login_provider = login_providers[data.login_service](request) uuid, data = login_provider.get_userdata_and_uuid(data.access_token, request) return render( request, "profile.html", { "realname": data.real_name, "email": data.email, "username": data.username, "shipping_address": data.default_shipping_address, "id": data.tw_id, "phone": data.phone_number, }, )