コード例 #1
0
ファイル: views.py プロジェクト: liljayr/CaptainConsole
def success(request):
    # Sækja í localStorage
    # Setja í DB
    # Tæma localStorage
    request_data = u'{}'.format(request.body)
    decoded_data = urllib.parse.unquote(request_data)
    cart_index = decoded_data.find("cart")
    cart_str = decoded_data[cart_index+5:-1]
    cart = json.loads(cart_str)
    user_id = request.user.id
    # býr til nýtt order
    user = User.objects.get(id=user_id)
    order = Order(user_id=user)


    order.save()
    for item in cart:
        order_item = OrderItems()
        order_item.order = order
        ids = item["product_id"].split("_")
        _type = ids[0]
        _id = ids[1]
        if _type == "game":
            game = Games.objects.get(id=_id)
            order_item.game_id = game
        else:
            console = Consoles.objects.get(id=_id)
            order_item.console_id = console
        amount = item["amount"]
        order_item.amount = amount
        order_item.save()

    return renderTemplate(request, 'cart/success.html')
コード例 #2
0
def paypal_return(request):
    context = {'post': request.POST, 'get': request.GET}
    user_obj = User.objects.get(pk=request.user.id)
    user_obj.profile.is_allowed = True
    user_obj.profile.save()
    Name = user_obj.username
    Email = user_obj.email
    Amount = user_obj.profile.amount
    order = Order(profile_name=Name,
                  profile_email=Email,
                  profile_amount=Amount)
    order.save()
    current_site = get_current_site(request)
    #to_email = '*****@*****.**'
    to_email = '*****@*****.**'
    msg_mail = 'You have received an amount'
    message_html = render_to_string(
        'email_for_received_amount.html', {
            'Name': Name,
            'profile_amount': Amount,
            'profile_name': Name,
            'profile_email': Email,
            'domain': current_site.domain,
            'message': msg_mail,
        })
    message_html1 = render_to_string(
        'email_payment_confirmation.html', {
            'Name': Name,
            'profile_amount': Amount,
            'profile_name': Name,
            'profile_email': Email,
            'domain': current_site.domain,
            'message': 'you have paid an amount',
        })
    send_mail(
        'Amount received',
        msg_mail,
        '*****@*****.**',
        [to_email],
        html_message=message_html,
    )
    send_mail(
        'Amount Paid',
        msg_mail,
        '*****@*****.**',
        [to_email],
        html_message=message_html1,
    )
    return render_to_response('paypal_return.html', context)
コード例 #3
0
def createOrder(request):
    client = Account.objects.get(userId=request.user.id)
    cart = CartLine.objects.filter(client_id=client.id)
    if cart:
        order = Order(client_id=client.id,
                      order_date=datetime.datetime.now(),
                      status=Order.WAITING)
        order.save()

        for cartline in cart:
            order_detail = OrderDetail(
                order_id=order.id,
                product_id=cartline.product.id,
                qty=cartline.quantity,
                product_unit_price=cartline.product.price)
            order_detail.save()
        cart.delete()
    if request.META.get('HTTP_REFERER'):
        return redirect(request.META.get('HTTP_REFERER'))
コード例 #4
0
ファイル: views.py プロジェクト: folse/Member
def order_add(request):
	data = {}
	response = {}
	if True:
		shop = Shop.objects.filter(id=request.GET['shop_id'])[0]
		customers = Customer.objects.filter(username=request.GET['customer_username'])
		if customers.exists():
			# add a new membership record
			customer = customers[0]
			membership = Membership.objects.filter(customer = customer)[0]
			membership.vaild_quantity += int(request.GET['quantity'])
			membership.save()
			
			order = Order(
            	shop = shop,
            	customer = customer,
            	customer_username = customer.username,
            	quantity = request.GET['quantity'],
            	trade_type = request.GET['trade_type']
            )
			order.save()

			sms_cmd = 'curl -H "Authorization: Token f1205211a7f4f97331eca4f78ced18cf2304298bca79f782a03f051132576b91" \
-H "Content-Type: application/json" \
-X POST -d \'{"to": "46' + request.GET['customer_username'][1:] +'", "message": "Grattis, du har nu laddat på med ' + request.GET['quantity'] + ' poäng, och ' + str(membership.vaild_quantity) + ' poäng kvar påditt konto hos '+ shop.name +'", "from": "Kundsystem", "encoding": "UTF-8", "receive_dlr": 0}\' \
"https://api.beepsend.com/2/send/"'

			message = os.popen(sms_cmd).readline()

			print message

			data['vaild_quantity'] = membership.vaild_quantity
			response['data'] = data
			response['resp'] = '0000'
			
		else:
			response['resp'] = '0006'
			response['msg'] = 'Fel, Denna medlem har inte registrerats innan' #This membership does not exist
	else:
		response['resp'] = '0001'
		response['msg'] = 'add order faild'
	return HttpResponse(json.dumps(response))
コード例 #5
0
            c.taxNumber = '1234567'
            c.bank = random.choice([
                '中国银行', '中国工商银行', '中国农业银行', '中国建设银行', '中国交通银行', '招商银行', '民生银行'
            ])
            c.bankAccount = '1234567890'
        c.address = '丹凤路%s号' % random.randint(1, 2000)
        c.contact = '联系人-%s' % i
        c.username = list(cxs)[i]
        c.telephone = '138' + ''.join(
            [str(random.randint(0, 9)) for _i in range(8)])
        c.save()

    materials = Material.objects.all()
    companies = Company.objects.all()
    for i in range(ORDER_NUM):
        o = Order()
        o.company = random.choice(list(companies))
        o.date = datetime.datetime.now() - datetime.timedelta(
            days=random.randint(1, 500))
        o.content = '内容-%s' % i
        o.quantity = random.randint(1, 5)
        o.taxPercent = (random.choice(Order.ORDER_TAX))[0]
        if i % 4:
            o.type = Order.ORDER_TYPE[0][0]
            o.price = random.randint(10, 100) * 50
        else:
            o.type = Order.ORDER_TYPE[1][0]
            o.material = random.choice(list(materials))
            o.sizeWidth = random.randint(1, 5)
            o.sizeHeight = random.randint(1, 5)
        o.author = random.choice(ops)