From b68f964c563ec88791abe2d71741ea07b95a5556 Mon Sep 17 00:00:00 2001 From: sudobob Date: Mon, 16 Nov 2020 10:10:47 -0500 Subject: [PATCH] Fixups for NL's config --- WaApi.py | 16 +++++++--------- app.py | 1 + static/wautils.js | 23 ++++++++++++----------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/WaApi.py b/WaApi.py index 07dc167..678d78e 100644 --- a/WaApi.py +++ b/WaApi.py @@ -1,5 +1,4 @@ r""" - This module provides set of classes for working with WildApricot public API v2. Public API documentation can be found here: http://help.wildapricot.com/display/DOC/API+Version+2 @@ -9,7 +8,6 @@ accounts = api.execute_request("/v2/accounts") for account in accounts: print(account.PrimaryDomainName) - """ __author__ = 'dsmirnov@wildapricot.com' @@ -21,7 +19,6 @@ import urllib.parse import json import base64 -import pdb from pprint import pprint @@ -56,7 +53,7 @@ def authenticate_with_apikey(self, api_key, scope=None): request.add_header("Authorization", 'Basic ' + base64.standard_b64encode(('APIKEY:' + api_key).encode()).decode()) pprint('---authenticate_with_apikey()---') pprint(vars(request)) - pprint('---end-------------------') + pprint('----------------------') response = urllib.request.urlopen(request) self._token = WaApiClient._parse_response(response) self._token.retrieved_at = datetime.datetime.now() @@ -110,6 +107,7 @@ def execute_request_raw(self, api_url, api_request_object=None, method=None, dat request = urllib.request.Request(api_url, method=method,data=data_as_bytes) + if api_request_object is not None: request.data = json.dumps(api_request_object, cls=_ApiObjectEncoder).encode() @@ -118,17 +116,17 @@ def execute_request_raw(self, api_url, api_request_object=None, method=None, dat request.add_header("Accept", "application/json") request.add_header("Authorization", "Bearer " + self._get_access_token()) - pprint('------------execute_request_raw() request ----------------') + pprint('execute_request_raw() request ----------------') pprint(request.__dict__) if (data is not None): pprint('execute_request_raw() data -----------------') - pprint(json.dumps(data)) + #pprint(json.dumps(data)) + pprint((data)) pprint('-----------------') - try: response = urllib.request.urlopen(request) return response @@ -207,9 +205,9 @@ def _refresh_auth_token(self): @staticmethod def _parse_response(http_response): decoded = json.loads(http_response.read().decode()) - pprint('------_parse_response()------------------') + pprint('_parse_response()------------------') pprint(decoded) - pprint('------end _parse_response()------------') + pprint('------------------') if isinstance(decoded, list): result = [] for item in decoded: diff --git a/app.py b/app.py index 2a3485c..9ad9555 100755 --- a/app.py +++ b/app.py @@ -297,6 +297,7 @@ def wa_get_any_endpoint_rest(): wa_uri_prefix_accounts + creds['account'] + "/contacts/" + str(current_user.id)) if wa_accounts_contact_me.IsAccountAdministrator: + pp.pprint(ep) try: response = wapi.execute_request_raw(wa_uri_prefix + ep) diff --git a/static/wautils.js b/static/wautils.js index a639261..b82cf67 100644 --- a/static/wautils.js +++ b/static/wautils.js @@ -12,7 +12,7 @@ $(document).ready(() => { function filt_signoff(substr) { // on keyup in the search box we display only the signoffs that match $('.signoff_item_div').filter(function() { - console.log(substr); + // console.log(substr); $(this).toggle($(this).text().toUpperCase().indexOf(substr) > -1) }); } @@ -110,7 +110,7 @@ function extract_contentfield(j,fieldname) { // save it away for later window.wautils_contact_fields = j; $.each(j,(k,v) => { - // find EquipmentSignOffs then extract + // find NL Signoffs and Categories then extract // all possible AllowedValues if (v['FieldName'] !== fieldname) return true @@ -174,7 +174,7 @@ function process_contacts(j) { }, ... { - "FieldName": "EquipmentSignOffs", + "FieldName": "NL Signoffs and Categories", "Value": [ { "Id": 11968550, @@ -291,9 +291,9 @@ function process_contacts(j) { o += ''; */ $.each(v['FieldValues'],(kk,vv) => { - if (vv['FieldName'] != 'EquipmentSignOffs') - return true; // we are just looking for the EquipmentSignOffs field - // 45: {FieldName: "EquipmentSignOffs", Value: Array(4), SystemCode: "custom-11058873"} + if (vv['FieldName'] != 'NL Signoffs and Categories') + return true; // we are just looking for the NL Signoffs and Categories field + // 45: {FieldName: "NL Signoffs and Categories", Value: Array(4), SystemCode: "custom-11058873"} // save this for when we POST our updated info ^^^^^^^^^^^^^^^ window.wautils_equipment_signoff_systemcode = vv['SystemCode']; o += '' @@ -335,7 +335,7 @@ function get_signoffs() { url : '/api/v1/wa_get_any_endpoint', // string '$accountid' will get replaced with real account id on server data : $.param({'endpoint':'/accounts/$accountid/contactfields'}), - success: (j) => { extract_contentfield(j,'EquipmentSignOffs');resolve(); }, + success: (j) => { extract_contentfield(j,'NL Signoffs and Categories');resolve(); }, failure: (errMsg) => { alert("FAIL:" + errMsg); }, error: (xh,ts,et) => { alert("FAIL:" + u + ' ' + et); }, contentType: false, @@ -406,7 +406,7 @@ function get_contacts_signed_off_items(contact_to_edit) { // return contact's signed-off items: existing_signoffs = []; $.each(contact_to_edit['FieldValues'],(kk,vv) => { - if (vv['FieldName'] != 'EquipmentSignOffs') + if (vv['FieldName'] != 'NL Signoffs and Categories') return true existing_signoffs = vv; return false; @@ -433,7 +433,7 @@ function get_contacts_signed_off_items(contact_to_edit) { function has_signoff(contact_id,signoff_name) { // does contact_id have signoff_name ? $.each(contact_to_edit['FieldValues'],(kk,vv) => { - if (vv['FieldName'] != 'EquipmentSignOffs') + if (vv['FieldName'] != 'NL Signoffs and Categories') return true exisiting_signoffs = vv; return false; @@ -441,7 +441,7 @@ function has_signoff(contact_id,signoff_name) { /* { - FieldName: "EquipmentSignOffs" + FieldName: "NL Signoffs and Categories" SystemCode: "custom-11058873" Value: Array(4) 0: {Id: 11968550, Label: "[equipment] *GREEN"} @@ -590,6 +590,7 @@ function signoffs_save() { }] } + debugger; // .. but we send it via flask web server // all of wa_put_data will be sent to the flask server under 'put_data': flask_put_data = { @@ -615,7 +616,7 @@ function signoffs_save() { // find the contact we are working on.. $.each($(this)[0]['FieldValues'],function(kk,vv) { // then find 'EquipmentSignoffs' in their entry.. - if (vv['FieldName'] != 'EquipmentSignOffs') + if (vv['FieldName'] != 'NL Signoffs and Categories') return true; // and replace it with what we sent up to WA $(this)[0]['Value'] = wa_put_data['FieldValues'][0]['Value']