Exemplo n.º 1
0
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
Exemplo n.º 2
0
def apply_paying_info(request):
    if auth.isLogin(request):
        user = auth.get_user_data(request)
        if auth.hasProfile(user.uuid):

            try:
                req_data = json.loads(request.body)
                order = Orders.objects.get(uuid=req_data["OID"], Orderer=user)
                order.paid_account = req_data["PACCOUNT"]
                order.paid_date = datetime.date(
                    datetime.date.today().year, int(req_data["PMONTH"]), int(req_data["PDAY"])
                )
                order.save()

                response = HttpResponse()
                response.status_code = 200
                return response

            except ObjectDoesNotExist:
                response = HttpResponse()
                response.status_code = 400
                return response

    response = HttpResponse()
    response.status_code = 403

    return response
Exemplo n.º 3
0
def edit_component_comment(request):
    payload = json.loads(request.body)

    if auth.isLogin(request):
        user = auth.get_user_data(request)
        if auth.hasProfile(user.uuid):
            try:
                comment = Comment.objects.get(pk = int(payload['pk']), commenter = user)

                comment.text = payload['content']

                comment.save()

                response = HttpResponse()
                response.status_code = 200

                return response
            except:
                response = HttpResponse()
                response.status_code = 404

                return response

    response = HttpResponse()
    response.status_code = 403

    return response
Exemplo n.º 4
0
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'})
Exemplo n.º 5
0
def get_user_orders(request):
    if auth.isLogin(request):
        user = auth.get_user_data(request)
        if auth.hasProfile(user.uuid):

            order_list = []

            for order in Orders.objects.all().filter(Orderer=user):

                order_list.append(order.uuid)

            response = HttpResponse(json.dumps(order_list))

            return response

    response = HttpResponse()
    response.status_code = 403

    return response
Exemplo n.º 6
0
def update_profile(request):
    if auth.isLogin(request):
        uuid = auth.get_user_data(request).uuid

        user_profile = User_Profiles(
            username=request.POST["username"],
            email=request.POST["email"],
            default_shipping_address=request.POST["shipping_address"],
            phone_number=request.POST["phone"],
            real_name=request.POST["realname"],
            tw_id=request.POST["id"],
        )

        if not auth.hasProfile(uuid):
            auth.register_data(uuid, user_profile)
        else:
            auth.update_data(uuid, user_profile)

        return redirect("digikey.views.progress_page")
Exemplo n.º 7
0
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
Exemplo n.º 8
0
def del_component_comment(request):
    if auth.isLogin(request):
        user = auth.get_user_data(request)
        if auth.hasProfile(user.uuid):
            try:
                comment = Comment.objects.get(pk = int(request.GET['pk']), commenter = user)

                comment.delete()

                response = HttpResponse()
                response.status_code = 200

                return response
            except:
                response = HttpResponse()
                response.status_code = 404

                return response

    response = HttpResponse()
    response.status_code = 403

    return response
Exemplo n.º 9
0
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,
                },
            )
Exemplo n.º 10
0
def rank_entry(request):
    if auth.isLogin(request):
        user = auth.get_user_data(request)
        if auth.hasProfile(user.uuid):
            try:
                entry = Entry.objects.get(pk = int(request.GET['pk']))

                er, newed = ERanking.objects.get_or_create(entry = entry, users = user)
                old_rank = er.rank
                er.rank = 1 if request.GET['up'] == "True" else -1
                er.save()

                if old_rank == 0:
                    response_data = str(er.rank)
                elif old_rank != er.rank:
                    if old_rank == -1:
                        response_data = "2"
                    else:
                        response_data = "-2"
                else:
                        response_data = "0"

                response = HttpResponse(response_data)
                response.status_code = 200

                return response
            except:
                response = HttpResponse()
                response.status_code = 404

                return response

    response = HttpResponse()
    response.status_code = 403

    return response
Exemplo n.º 11
0
def rank_comment(request):
    if auth.isLogin(request):
        user = auth.get_user_data(request)
        if auth.hasProfile(user.uuid):
            try:
                comment = Comment.objects.get(pk = int(request.GET['pk']))

                cr, newed = CRanking.objects.get_or_create(comment = comment, users = user)
                old_rank = cr.rank
                cr.rank = 1 if request.GET['up'] == "True" else -1
                cr.save()

                if old_rank == 0:
                    response_data = str(cr.rank)
                elif old_rank != cr.rank:
                    if old_rank == -1:
                        response_data = "2"
                    else:
                        response_data = "-2"
                else:
                        response_data = "0"

                response = HttpResponse(response_data)
                response.status_code = 200

                return response
            except:
                response = HttpResponse()
                response.status_code = 404

                return response

    response = HttpResponse()
    response.status_code = 403

    return response