order site 1

master
Marek Baczynski 6 years ago
parent 54833c1c9d
commit 9b0f67b5ef

@ -0,0 +1,27 @@
import json
import requests
from flask import Flask
from flask import render_template, request, Response
import xmlrpc.client
s = xmlrpc.client.ServerProxy('http://localhost:8000')
app = Flask(__name__)
@app.route('/', strict_slashes=False)
def index():
return render_template('index.html')
@app.route('/order', methods=['POST'])
def order():
candy1 = int(request.form['candy1'])
candy2 = int(request.form['candy2'])
candy3 = int(request.form['candy3'])
candy4 = int(request.form['candy4'])
print ("test {} {} {} {} ".format(candy1, candy2, candy3, candy4))
return '{"status":"ok"}'
#s.new_order(params)
if __name__ == '__main__':
app.run('0.0.0.0')

@ -0,0 +1,58 @@
$(document).ready(function(){
var quantitiy=0;
$('.quantity-right-plus').click(function(e){
// Stop acting like a button
e.preventDefault();
// Get the field name
var quantity = parseInt($('#quantity').val());
// If is not undefined
$('#quantity').val(quantity + 1);
// Increment
});
$('.quantity-left-minus').click(function(e){
// Stop acting like a button
e.preventDefault();
// Get the field name
var quantity = parseInt($('#quantity').val());
// If is not undefined
// Increment
if(quantity>0){
$('#quantity').val(quantity - 1);
}
});
});
function submitOrder(){
var data = new FormData();
data.append('candy1', $('#candy1').val());
data.append('candy2', $('#candy2').val());
data.append('candy3', $('#candy3').val());
data.append('candy4', $('#candy4').val());
$.ajax({
url: 'order',
type: 'POST',
cache: false,
data: data,
contentType: false,
processData: false,
success: function() {
alert("ok")
},
fail: function() {
alert("not ok")
},
});
}

@ -0,0 +1,97 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Alepa Twitch Grabs Candy</title>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="{{url_for('static', filename='picker.js')}}"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<h2>Simple Quantity increment buttons with Javascript </h2>
<div class="col-lg-2">
Tasty treats
<div class="input-group">
<span class="input-group-btn">
<button type="button" class="quantity-left-minus btn btn-danger btn-number" data-type="minus" data-field="">
<span class="glyphicon glyphicon-minus"></span>
</button>
</span>
<input type="text" id="candy1" name="quantity" class="form-control input-number" value="0" min="1" max="20">
<span class="input-group-btn">
<button type="button" class="quantity-right-plus btn btn-success btn-number" data-type="plus" data-field="">
<span class="glyphicon glyphicon-plus"></span>
</button>
</span>
</div>
</div>
<div class="col-lg-2">
Sweet snacks
<div class="input-group">
<span class="input-group-btn">
<button type="button" class="quantity-left-minus btn btn-danger btn-number" data-type="minus" data-field="">
<span class="glyphicon glyphicon-minus"></span>
</button>
</span>
<input type="text" id="candy2" name="quantity" class="form-control input-number" value="0" min="1" max="20">
<span class="input-group-btn">
<button type="button" class="quantity-right-plus btn btn-success btn-number" data-type="plus" data-field="">
<span class="glyphicon glyphicon-plus"></span>
</button>
</span>
</div>
</div>
<div class="col-lg-2">
Chocolaty candy
<div class="input-group">
<span class="input-group-btn">
<button type="button" class="quantity-left-minus btn btn-danger btn-number" data-type="minus" data-field="">
<span class="glyphicon glyphicon-minus"></span>
</button>
</span>
<input type="text" id="candy3" name="quantity" class="form-control input-number" value="0" min="0" max="20">
<span class="input-group-btn">
<button type="button" class="quantity-right-plus btn btn-success btn-number" data-type="plus" data-field="">
<span class="glyphicon glyphicon-plus"></span>
</button>
</span>
</div>
</div>
<div class="col-lg-2">
Good something
<div class="input-group">
<span class="input-group-btn">
<button type="button" class="quantity-left-minus btn btn-danger btn-number" data-type="minus" data-field="">
<span class="glyphicon glyphicon-minus"></span>
</button>
</span>
<input type="text" id="candy4" name="quantity" class="form-control input-number" value="0" min="0" max="20">
<span class="input-group-btn">
<button type="button" class="quantity-right-plus btn btn-success btn-number" data-type="plus" data-field="">
<span class="glyphicon glyphicon-plus"></span>
</button>
</span>
</div>
</div>
<div class="col-lg-2">
<div class="input-group">
<button class="btn btn-magick" onClick="submitOrder()">Place sweet order!</button>
</div>
</div>
</div>
</div>
</body>
</html>
Loading…
Cancel
Save