Skip to content

Commit 8f9a0cd

Browse files
nbhambhaninbhambhani
nbhambhani
authored and
nbhambhani
committed
Request context variable update
1 parent 1abca75 commit 8f9a0cd

File tree

6 files changed

+13
-8
lines changed

6 files changed

+13
-8
lines changed

app.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ def index():
4141
access_token = access_token[0]
4242
global customer_list
4343
customer_list = excel.load_excel()
44-
return render_template('index.html',
44+
return render_template('index.html',
4545
customer_dict=customer_list,
4646
title="QB Customer Leads",
4747
text_color=font_color)
4848

4949
# Update leads in html after adding a customer to QBO handled here for simplicity
50-
@app.route('/', methods=['GET','POST'])
50+
@app.route('/', methods=['POST'])
5151
def update_table():
5252
customer_id = request.form['id']
5353
for customer in customer_list:
5454
if customer['Id'] == customer_id:
5555
# Create customer object, add customer to qbo and get response
5656
customer_obj = create_customer(customer)
57-
response_data = add_customer(customer_obj, req_context)
57+
response_data = add_customer(customer_obj, request_context)
5858
status_code = response_data['status_code']
5959
message = response_data['message']
6060
global font_color
@@ -72,7 +72,7 @@ def update_table():
7272

7373
@app.route('/auth')
7474
def auth():
75-
return qbo.authorize(callback=url_for('oauth_authorized'))
75+
return qbo.authorize(callback=url_for('oauth_authorized'))
7676

7777
@app.route('/reset-session')
7878
def reset_session():
@@ -91,13 +91,15 @@ def oauth_authorized(resp):
9191
return redirect(next_url)
9292
# Setting the session using flask session just for the simplicity of this Sample App. It's not the most secure way to do this.
9393
session['is_authorized'] = True
94+
access_token = resp['oauth_token']
95+
session['access_token'] = access_token
9496
session['realm_id'] = realm_id
9597
session['qbo_token'] = (
9698
resp['oauth_token'],
9799
resp['oauth_token_secret']
98100
)
99-
global req_context
100-
req_context = req_context()
101+
global request_context
102+
request_context = req_context()
101103
return redirect(url_for('index'))
102104

103105
if __name__ == '__main__':

utils/context.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ def __init__(self, realm_id, access_key, access_secret):
1212
self.access_secret = access_secret
1313

1414
def print_context(self):
15-
print self.consumer_key, self.consumer_secret, self.realm_id,
16-
self.access_secret, self.access_key
15+
print self.consumer_key, self.consumer_secret, self.realm_id, self.access_secret, self.access_key
1716

utils/context.pyc

1.09 KB
Binary file not shown.

utils/excel.pyc

1.78 KB
Binary file not shown.

utils/requestMethods.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ def do_post(url, headers, payload, auth):
99
response_data['content'] = req.content
1010
return response_data
1111

12+
def get(url, headers, payload, auth):
13+
req = requests.get(url, auth=auth, headers=headers, data=payload)
14+
return req.content
15+
1216
def request(req_data, req_context, method):
1317
headers = {'Accept': 'application/json', 'content-type': 'application/json; charset=utf-8', 'User-Agent': 'PythonSampleApp1'}
1418
payload = req_data['payload']

utils/requestMethods.pyc

1.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)