I am a beginner to programming and stackexchange. I am trying to read a csv file and do some calculations to the data and copy the values to an excel file. I have succesfully implemented the backend work.
This is suppose to be a web app and im using Flask. The user is suppose to enter two integers and im suppose to pass those values to the global variables in class Shared. Currently the user inputs just gets printed when generate button is clicked.
Thats all i need. I have copied the code below.
I used flask example to create this.
#app.py
from flask import Flask, render_template, request, jsonify
# Initialize the Flask application
app = Flask(__name__)
# This route will show a form to perform an AJAX request
# jQuery is loaded to execute the request and update the
# value of the operation
@app.route('/')
def index():
return render_template('index.html')
# Route that will process the AJAX request, sum up two
# integer numbers (defaulted to zero) and return thej
# result as a proper JSON response (Content-Type, etc.)
@app.route('/_add_numbers')
def add_numbers():
a = request.args.get('a', 0, type=int)
b = request.args.get('b', 0, type=int)
return jsonify(result= "Party ID is " + str(a) + " and the Count is " + str(b))
if __name__ == '__main__':
app.debug = True
app.run(host='0.0.0.0')
#index.html
<!DOCTYPE html>
<html lang="en">
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
<script type=text/javascript>
$(function () {
$('a#calculate').bind('click', function () {
$.getJSON('/_add_numbers', {
a: $('input[name="a"]').val(),
b: $('input[name="b"]').val()
}, function (data) {
$("#result").text(data.result);
});
return false;
});
});
</script>
</head>
<body>
<div class="container">
<div class="header">
<h3 class="text-muted">Producer Maker Prototype</h3>
</div>
<hr/>
<div>
<p>
<label for="a">PartyID</label>
<input type="text" size="5" name="a">
<label for="b">Count</label>
<input type="text" size="5" name="b">
<span id="result"><span style="color:blue;font-weight:bold">?</span>
<p><a href="javascript:void();" id="calculate">Generate</a>
</form>
</div>
</div>
</body>
#shared.py
#I need to pass the first userinput to count and second userinput to id.
from collections import OrderedDict
#from TestProducer import TestProducer
class Shared:
unique_col_list = ['Code', 'TaxId', 'NationalProducerId', 'ContractCode', 'ExternalPartyId']
unique_col = OrderedDict()
for key in unique_col_list:
unique_col[key] = 0
unique_col['TaxId'] = 100000000
static_col = OrderedDict()
random_col = OrderedDict()
col_type = OrderedDict()
tables = OrderedDict()
count = 0
id = 0
Aucun commentaire:
Enregistrer un commentaire