From 8f9a0cd727346b82a09612bee4613336a1706e48 Mon Sep 17 00:00:00 2001 From: nbhambhani Date: Thu, 6 Apr 2017 11:55:28 -0700 Subject: [PATCH] Request context variable update --- app.py | 14 ++++++++------ utils/context.py | 3 +-- utils/context.pyc | Bin 0 -> 1112 bytes utils/excel.pyc | Bin 0 -> 1818 bytes utils/requestMethods.py | 4 ++++ utils/requestMethods.pyc | Bin 0 -> 1536 bytes 6 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 utils/context.pyc create mode 100644 utils/excel.pyc create mode 100644 utils/requestMethods.pyc diff --git a/app.py b/app.py index 7fd3d4b..fe69f91 100644 --- a/app.py +++ b/app.py @@ -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 @@ -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(): @@ -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__': diff --git a/utils/context.py b/utils/context.py index fc2d1a6..5ae118b 100644 --- a/utils/context.py +++ b/utils/context.py @@ -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 diff --git a/utils/context.pyc b/utils/context.pyc new file mode 100644 index 0000000000000000000000000000000000000000..fbd92f83e5149ff4931de19c3bd86eefeb7da410 GIT binary patch literal 1112 zcmcgq&2H2{4E7}1rCVCy%nOi9$$=|E{XyDtsoGgU(90+!Q<`ov37Lt+qU8k7$_wxS z@Y&hY_5n%~du+?GKYyP1_wIJ_?bnBbHcyOmAL5@umG~6ZM2(_zMXHRboKP9lPof`0 zAJ5?@v`DAOt^VLi6|C?Gs%V`b8r#2Zm)3a+Y5QfcJ{+|!*stMVNB-py;-5lU;zsC; z4qRP{5tCk|5m!y1CJ=UxAbuYz2%7H+trNOZv?empup_Z!T8}{_jFAbg5k%UQTP+0j zN%{b#G=#zq)b#*nX;*gx-WK8U?F!RAtzPlNW{cUJC5qxMOz8Qv@Ez z+xkMYr~&j!a2I?wuR^xSo36G8UAK2O zRK@bJZI}N2i-XfQd#9^#*}7~9RqZoO$;)`&tpvU?m8*gQFTlktkeaC-yfeH7Z|Yiv ze1-!WuZZS+sPTx#BOZ^0=Et{4mO*)Ynr9#97UH?3EJ8Dn_dYEzr0Xje%!UHKw4Q;H zN*UUQ50^LA7+I$=OwigiD$(M-Br6;{(|wskW0jo}J3%y3bC);2HY W0?QBo1)8w*a^&R|!xRdi#D4+ClK!Xw literal 0 HcmV?d00001 diff --git a/utils/excel.pyc b/utils/excel.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3d89bc33206600bfc36bbd96800734f2e6851306 GIT binary patch literal 1818 zcmcIk!EW0|5S=AuS(2s5NmJM^95)COK$lpjBo{YG9JN4!Rxnm5Tm%pVTFcm!NRiU6 zY#NYG?WteT|LC!|_7=2%&~tyFAJD!T3UZD18i_m0c{@8ZJNt(IUya%?%|E^!((317 zeuZH_gD`j$#YAt{?~2|k3Kfk!G9G;g)hFZA_pm9EDap$Q@9MQS;34`OzpicI_3*I$ zRTvn1n8!Akc$+}W7;iA_t|D?oBgLB?T$5T7EfCnFy``daqNPU>f*@dto*P6dW7;HB z!BizvqvuPX^51EJ^kB3_rcS0o<_?^Bo&Ha>EKvkE89=VKm+1Q~ z+FRwYudu?c1G&X($V7T*UrqPbDd1kKjv{w81ZnOIExhFFYrZ%kx@NX(z6s4&qM1aR zO=PoX51RR|@33gH;LgOqjRWxAe_$Ze5z7HJG=K zduxqEM(?n%T^8(6??XuIF_F2M3T5R&NG;+6Fq<=*g-LoD4q|-5nbr0&gisr_Zm1(r z`>|@Os=6!xy4v;|YFj-}Eh#6LP8wvGPToc58eSY@=b@9YL>9PL(C4C;Cvw YsvycylA3uOzGO;R2I{KrHT~+&KXFuUTL1t6 literal 0 HcmV?d00001 diff --git a/utils/requestMethods.py b/utils/requestMethods.py index 5ac36d1..35c31f0 100644 --- a/utils/requestMethods.py +++ b/utils/requestMethods.py @@ -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'] diff --git a/utils/requestMethods.pyc b/utils/requestMethods.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8a0dac6a27ff7188c0a57cd0665906140b301d12 GIT binary patch literal 1536 zcmcgs!EVz)5S?|Lq$w?w1BZ$O^cD$)s6vX6S`eWi#DTOpfT~_1*IpVoPHeJciAc_= zd@6sy2f&-LRX8AVDsgr^yF0t{=IvWIer#_}AALWKsQ!6)zd&;bFfsmyQlhiU_b4?q z_vp+c6F2A^CK?p`>i85l)oIF_akqu_$xr-7T?3b;e>^OBx*z#)rMrQ4gyvquFwv!< zQZts=)uYl7l9V1@na0|uglOHQ(x*#IA&F0i(m@0|O>~-d))7mB5UIEgXKKUPE}afu zx@^I>BqfJjxJi`7R)Zpp+XZ)JB@3>l{Zd%R)v`Qu9LQAAgwfKt0k2r5fe@x!nKGe5HuuY$C`7v)h!sX3wP&z3#@?$FGmWkEO!s1)i3k!4E*+Elh_922xFWQ^PnY?$Y15`~=L zfK{?W=`f0H&hEiq<_{i5({Sl5KP&ii@2QhAYen~Xm0OlgE5Td~YF{NG^6L#RpttH& zgbuwaC&%LtD)ay&#PyC2(p*kvcExuviWJp=v(eHrO93HJI;SC`{kmHP1hPw4Q;30R z^-Ac4l#W9F%KE98tCauHi>#?WCffYRh#`P0f(fx#|