Skip to content

Commit

Permalink
Fixups for NL's config
Browse files Browse the repository at this point in the history
  • Loading branch information
sudobob committed Nov 16, 2020
1 parent 550f839 commit b68f964
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
16 changes: 7 additions & 9 deletions WaApi.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,7 +8,6 @@
accounts = api.execute_request("/v2/accounts")
for account in accounts:
print(account.PrimaryDomainName)
"""

__author__ = 'dsmirnov@wildapricot.com'
Expand All @@ -21,7 +19,6 @@
import urllib.parse
import json
import base64
import pdb

from pprint import pprint

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()

Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
23 changes: 12 additions & 11 deletions static/wautils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -174,7 +174,7 @@ function process_contacts(j) {
},
...
{
"FieldName": "EquipmentSignOffs",
"FieldName": "NL Signoffs and Categories",
"Value": [
{
"Id": 11968550,
Expand Down Expand Up @@ -291,9 +291,9 @@ function process_contacts(j) {
o += '</tr></thead>';
*/
$.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 += '<td>'
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -433,15 +433,15 @@ 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;
});

/*
{
FieldName: "EquipmentSignOffs"
FieldName: "NL Signoffs and Categories"
SystemCode: "custom-11058873"
Value: Array(4)
0: {Id: 11968550, Label: "[equipment] *GREEN"}
Expand Down Expand Up @@ -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 = {
Expand All @@ -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']
Expand Down

0 comments on commit b68f964

Please sign in to comment.