Skip to content

Commit

Permalink
Request context variable update
Browse files Browse the repository at this point in the history
  • Loading branch information
nbhambhani authored and nbhambhani committed Apr 6, 2017
1 parent 1abca75 commit 8f9a0cd
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 8 deletions.
14 changes: 8 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ def index():
access_token = access_token[0]
global customer_list
customer_list = excel.load_excel()
return render_template('index.html',
return render_template('index.html',
customer_dict=customer_list,
title="QB Customer Leads",
text_color=font_color)

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

@app.route('/auth')
def auth():
return qbo.authorize(callback=url_for('oauth_authorized'))
return qbo.authorize(callback=url_for('oauth_authorized'))

@app.route('/reset-session')
def reset_session():
Expand All @@ -91,13 +91,15 @@ def oauth_authorized(resp):
return redirect(next_url)
# Setting the session using flask session just for the simplicity of this Sample App. It's not the most secure way to do this.
session['is_authorized'] = True
access_token = resp['oauth_token']
session['access_token'] = access_token
session['realm_id'] = realm_id
session['qbo_token'] = (
resp['oauth_token'],
resp['oauth_token_secret']
)
global req_context
req_context = req_context()
global request_context
request_context = req_context()
return redirect(url_for('index'))

if __name__ == '__main__':
Expand Down
3 changes: 1 addition & 2 deletions utils/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ def __init__(self, realm_id, access_key, access_secret):
self.access_secret = access_secret

def print_context(self):
print self.consumer_key, self.consumer_secret, self.realm_id,
self.access_secret, self.access_key
print self.consumer_key, self.consumer_secret, self.realm_id, self.access_secret, self.access_key

Binary file added utils/context.pyc
Binary file not shown.
Binary file added utils/excel.pyc
Binary file not shown.
4 changes: 4 additions & 0 deletions utils/requestMethods.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def do_post(url, headers, payload, auth):
response_data['content'] = req.content
return response_data

def get(url, headers, payload, auth):
req = requests.get(url, auth=auth, headers=headers, data=payload)
return req.content

def request(req_data, req_context, method):
headers = {'Accept': 'application/json', 'content-type': 'application/json; charset=utf-8', 'User-Agent': 'PythonSampleApp1'}
payload = req_data['payload']
Expand Down
Binary file added utils/requestMethods.pyc
Binary file not shown.

0 comments on commit 8f9a0cd

Please sign in to comment.