def getTollFree(request, clientId): if 'user_data' not in request.session: return HttpResponseRedirect("/login") staff_id = str( request.session['user_data']['user_info']['staff_and_agents_id']) # send request to api params = {"staff_id": staff_id, "client_id": clientId} if 'id' in request.GET: if request.GET['id'] != '0': params['client_toll_free_id'] = request.GET['id'] else: return render(request, 'portal/account/tabs/toll_free_detail.html', {'toll_free': { 'client_id': clientId }}) params = json.dumps(params) r = Request() r = r.get(params, 'clients/getTollFree', request.session['user_data']['tokens']['access_token']) data = r.json() if 'id' in request.GET: # mobile detail.html return render(request, 'portal/account/tabs/toll_free_detail.html', {'toll_free': data['data']['toll_free'][0]}) elif 'type' in request.GET and request.GET['type'] == 'dropdown': return render(request, 'portal/account/dropdown_list.html', {'data': data}) else: return HttpResponse(json.dumps({'aaData': data['data']['toll_free']}))
def createAccount(request): if request.method == "POST": staff_id = str( request.session['user_data']['user_info']['staff_and_agents_id']) # send request to api post_data = request.POST if 'client_id' in post_data and post_data['client_id'] != "": url = "clients/edit" else: url = "clients/create" params = '{"staff_id":' + staff_id + ', "data":' + json.dumps( post_data) + '}' r = Request() r = r.post(params, url, request.session['user_data']['tokens']['access_token']) data = r.json() if 'client_id' in data['data'][ 'client'] and data['data']['client']['client_id'] != 0: msg = 'Account created with id : ' + str( data['data']['client']['client_id']) data = {'alert': 'success', 'message': msg} elif 'client_updated' in data['data']['client']: data = {'alert': 'success', 'message': "Account Updated"} else: data = {'alert': 'error', 'message': data['data']['client']['msg']} return HttpResponse(json.dumps(data))
def createTollfree(request, clientId): if request.method == "POST": staff_id = str( request.session['user_data']['user_info']['staff_and_agents_id']) post_data = request.POST params = '{"staff_id":' + staff_id + ', "client_id":' + clientId + ', "data":' + json.dumps( post_data) + '}' if 'client_toll_free_id' in post_data and post_data[ 'client_toll_free_id'] != '': url = 'clients/updateTollfree' else: url = 'clients/createTollfree' r = Request() r = r.post(params, url, request.session['user_data']['tokens']['access_token']) data = r.json() if 'client_toll_free_id' in post_data and post_data[ 'client_toll_free_id'] != '': if data['data']['tollfree']['tollfree_updated']: msg = 'Tollfree Updated' data = {'alert': 'success', 'message': msg} else: data = {'alert': 'error', 'message': 'Tollfree not updated'} else: if data['data']['tollfree']['tollfree_created']: msg = 'Tollfree created' data = {'alert': 'success', 'message': msg} else: data = {'alert': 'error', 'message': 'Tollfree not creaded'} return HttpResponse(json.dumps(data))
def getContacts(request, clientId): if 'user_data' not in request.session: return HttpResponseRedirect("/login") staff_id = str( request.session['user_data']['user_info']['staff_and_agents_id']) # send request to api params = {"staff_id": staff_id, "client_id": clientId} if 'contactId' in request.GET: if request.GET['contactId'] != '0': params['contact_id'] = request.GET['contactId'] else: return render(request, 'portal/account/tabs/cont_contact_detail.html', {'contact': { 'client_id': clientId }}) params = json.dumps(params) r = Request() r = r.get(params, 'clients/getContacts', request.session['user_data']['tokens']['access_token']) data = r.json() if 'contactId' in request.GET: return render(request, 'portal/account/tabs/cont_contact_detail.html', {'contact': data['data']['contacts'][0]}) else: return HttpResponse(json.dumps({'aaData': data['data']['contacts']}))
def createWhiteLabel(request, clientId): if request.method == "POST": staff_id = str( request.session['user_data']['user_info']['staff_and_agents_id']) post_data = request.POST params = '{"staff_id":' + staff_id + ', "client_id":' + clientId + ', "data":' + json.dumps( post_data) + '}' if 'wl_client_id' in post_data and post_data['wl_client_id'] != '': url = 'clients/updateWhiteLabel' else: url = 'clients/createWhiteLabel' r = Request() r = r.post(params, url, request.session['user_data']['tokens']['access_token']) data = r.json() if 'wl_client_id' in post_data and post_data['wl_client_id'] != '': if data['data']['white_label']['whitelabel_updated']: msg = 'Client White Label Updated' data = { 'alert': 'success', 'message': msg, 'action': 'createWl' } else: data = { 'alert': 'error', 'message': 'Client White Label not updated' } return HttpResponse(json.dumps(data))
def editPartner(request): if 'user_data' not in request.session: return HttpResponseRedirect("/login") staff_id = str( request.session['user_data']['user_info']['staff_and_agents_id']) post_data = request.POST # send request to api params = '{"staff_id":' + staff_id + ', "data":' + json.dumps( post_data) + '}' r = Request() r = r.post(params, 'staff/editStaff', request.session['user_data']['tokens']['access_token']) data = r.json() if 'staff_and_agents_id' in post_data and post_data[ 'staff_and_agents_id'] != '': if data['data']['staff']['staff_updated']: msg = 'Staff Updated' data = {'alert': 'success', 'message': msg} else: data = {'alert': 'error', 'message': 'Staff not updated'} else: if data['data']['staff']['staff_created']: msg = 'Staff created' data = {'alert': 'success', 'message': msg} else: data = {'alert': 'error', 'message': 'Staff not creaded'} return HttpResponse(json.dumps(data))
def getOneoffinvoices(request, clientId): if 'user_data' not in request.session: return HttpResponseRedirect("/login") staff_id = str( request.session['user_data']['user_info']['staff_and_agents_id']) # send request to api params = '{"staff_id":' + staff_id + ',"client_id":"' + clientId + '", "limit":"1"}' r = Request() r = r.get(params, 'clients/getOneOffInvoices', request.session['user_data']['tokens']['access_token']) data = r.json() oneoffinvoices = [] for index in data['data']['oneoffinvoices']: temp = {} temp['invoice_number'] = index['invoice_number'] temp['invoice_date'] = index['invoice_date'] temp['oi_description'] = index['oi_description'] temp['oi_gross_amount'] = '$' + str(index['oi_gross_amount']) temp['credits'] = '$ 0.00' temp['payments'] = '$ 0.00' temp['total_amount'] = '$' + str(index['oi_gross_amount']) temp['oi_transaction_id'] = index['oi_transaction_id'] oneoffinvoices.append(temp) return HttpResponse(json.dumps({'aaData': oneoffinvoices}))
def proccessLogin(request): if request.method == "POST": if (request.POST['account'] and request.POST['pass']): try: username = request.POST['account'] password = request.POST['pass'] # send request to api params = '{"username":'******',"password":"******"}' r = Request() r = r.post(params, 'login') data = r.json() if data['isSuccess'] and checkUserType( data['data']['user_info']['type']): # save tokens in session request.session['user_data'] = data['data'] return redirect("maintainAccountView", client_id=608) else: request.session['errors'] = data['errors'] return HttpResponseRedirect("/login") except ValueError: request.session['error'] = 'Account and Password do not match' else: request.session['error'] = 'Account and Password do not match' else: request.session['error'] = 'Invalid Request Method' return HttpResponseRedirect("/login")
def getStandingCharges(request, clientId): if 'user_data' not in request.session: return HttpResponseRedirect("/login") staff_id = str( request.session['user_data']['user_info']['staff_and_agents_id']) params = {"staff_id": staff_id, "client_id": clientId} # send request to api if 'standing_charge_id' in request.GET: if request.GET['standing_charge_id'] != '0': params['standing_charge_id'] = request.GET['standing_charge_id'] else: return render(request, 'portal/account/tabs/st_charges_detail.html', {'standing_charges': { 'client_id': clientId }}) r = Request() r = r.get(json.dumps(params), 'clients/getStandingCharges', request.session['user_data']['tokens']['access_token']) data = r.json() if 'standing_charge_id' in request.GET: # mobile detail.html return render( request, 'portal/account/tabs/st_charges_detail.html', {'standing_charges': data['data']['standing_charges'][0]}) else: return HttpResponse( json.dumps({'aaData': data['data']['standing_charges']}))
def getClients(request, partner_id=""): staff_id = str( request.session['user_data']['user_info']['staff_and_agents_id']) # user search string params = '{"staff_id":' + staff_id + ', "partner_id":' + partner_id + '}' r = Request() r = r.get(params, 'clients/getClients', request.session['user_data']['tokens']['access_token']) data = r.json() return HttpResponse(json.dumps({'aaData': data['data']['clients']}))
def getServiceProviders(request): if 'user_data' not in request.session: return HttpResponseRedirect("/login") staff_id = str( request.session['user_data']['user_info']['staff_and_agents_id']) # send request to api params = '{"staff_id":' + staff_id + '}' r = Request() r = r.get(params, 'providers/getServiceProviders', request.session['user_data']['tokens']['access_token']) data = r.json() return render(request, 'portal/account/dropdown_list.html', {'data': data})
def getAccountSummary(request, clientId): if 'user_data' not in request.session: return HttpResponseRedirect("/login") staff_id = str( request.session['user_data']['user_info']['staff_and_agents_id']) # send request to api params = json.dumps({"staff_id": staff_id, "client_id": clientId}) r = Request() r = r.get(params, 'clients/getAccountSummary', request.session['user_data']['tokens']['access_token']) data = r.json() return render(request, 'portal/account/tabs/acc_account_summary.html', {'data': data})
def getPayments(request, clientId): if 'user_data' not in request.session: return HttpResponseRedirect("/login") staff_id = str( request.session['user_data']['user_info']['staff_and_agents_id']) # send request to api params = '{"staff_id":' + staff_id + ',"client_id":"' + clientId + '"}' r = Request() r = r.get(params, 'clients/getPayments', request.session['user_data']['tokens']['access_token']) data = r.json() return render(request, 'portal/account/tabs/acc_payments.html', {'data': data})
def getWhitelabel(request, clientId): staff_id = str( request.session['user_data']['user_info']['staff_and_agents_id']) params = {"staff_id": staff_id, "client_id": clientId} # send request to api r = Request() if request.GET['wl_enabled'] and request.GET['wl_enabled'] == 'False': if 'action' in request.GET and request.GET['action'] == 'read': return render(request, 'portal/account/controls_sidebar/wl_form.html') r = r.post(json.dumps(params), 'prices/getDefaultPrices', request.session['user_data']['tokens']['access_token']) data = r.json() data['data']['prices_default']['client_id'] = clientId return render(request, 'portal/account/controls_sidebar/enable_wl.html', {'white_label': data['data']['prices_default']}) r = Request() r = r.get(json.dumps(params), 'clients/getWhitelabel', request.session['user_data']['tokens']['access_token']) data = r.json() if 'action' in request.GET and request.GET['action'] == 'read': return render(request, 'portal/account/controls_sidebar/wl_form.html', {'white_label': data['data']['white_label']}) else: return render(request, 'portal/account/controls_sidebar/enable_wl.html', {'white_label': data['data']['white_label']})
def searchPartner(request): if request.method == "POST": if 'user_data' not in request.session: return HttpResponseRedirect("/login") staff_id = str( request.session['user_data']['user_info']['staff_and_agents_id']) # user search string search_str = request.POST['search_str'] params = '{"staff_id":' + staff_id + ', "limit":"20", "search_str":"' + search_str + '"}' r = Request() r = r.get(params, 'staff/getAllStaffs', request.session['user_data']['tokens']['access_token']) data = r.json() return render(request, 'portal/components/search_result.html', {'data': data})
def maintainPartnerView(request, partner_id=""): if 'user_data' not in request.session: return HttpResponseRedirect("/login") staff_id = str( request.session['user_data']['user_info']['staff_and_agents_id']) # send request to api params = '{"staff_id":' + staff_id + ', "partner_id":' + partner_id + '}' r = Request() r = r.get(params, 'staff/getStaff', request.session['user_data']['tokens']['access_token']) data = r.json() if data['isSuccess']: context = { 'user_data': request.session['user_data']['user_info'], 'data': data } return render(request, 'portal/partner_account/maintain.html', context) return HttpResponseRedirect("/login")
def index(request): # salt = hex(random.getrandbits(128)).encode() # return HttpResponse(len(salt)) # dk = hashlib.pbkdf2_hmac('sha256',b'mypass',salt, 1000000) # return HttpResponse(binascii.hexlify(dk)) if 'user_data' not in request.session: return HttpResponseRedirect("/login") # do further call to get user information staff_id = str( request.session['user_data']['user_info']['staff_and_agents_id']) # send request to api params = '{"staff_id":' + staff_id + '}' r = Request() r = r.post(params, 'services', request.session['user_data']['tokens']['access_token']) data = r.json() if 'isSuccess' in data: services = { 'total_amt': 0, 'toll_calls_amt': 0, 'local_ditto_amt': 0, 'fax_amt': 0, 'st_charges_amt': 0 } if data['data']['services'] is not None: for index in data['data']['services']: services['total_amt'] += index['invoice_net_amount'] services['toll_calls_amt'] += index['toll_traffic_amount'] services['local_ditto_amt'] += index['local_traffic_amount'] services['fax_amt'] += index['fax_traffic_amount'] services['st_charges_amt'] += index['standing_charges_amount'] context = { 'user_data': request.session['user_data']['user_info'], 'data': services } return render(request, 'portal/index.html', context) else: del request.session['user_data'] request.session['errors'] = data['errors'] return HttpResponseRedirect("/login")
def maintainAccountView(request, client_id=""): if 'user_data' not in request.session: return HttpResponseRedirect("/login") staff_id = str( request.session['user_data']['user_info']['staff_and_agents_id']) # send request to api params = '{"staff_id":' + staff_id + ', "client_id":"' + str( client_id) + '"}' r = Request() data = r.get(params, 'clients/getClients', request.session['user_data']['tokens']['access_token']) data = data.json() if data['isSuccess']: # get rate plans r = Request() rate_plans = r.get( params, 'plans/getRatePlans', request.session['user_data']['tokens']['access_token']) data['rate_plans'] = rate_plans.json()['data']['rate_plans'] context = { 'user_data': request.session['user_data']['user_info'], 'data': data } return render(request, 'portal/account/maintain.html', context) return HttpResponseRedirect("/login")
def getAreaNames(request, area_code=""): if 'user_data' not in request.session: return HttpResponseRedirect("/login") staff_id = str( request.session['user_data']['user_info']['staff_and_agents_id']) # send request to api if area_code != "": params = '{"staff_id":' + staff_id + ', "area_code":' + area_code + '}' else: params = '{"staff_id":' + staff_id + '}' r = Request() r = r.get(params, 'area/getAreaNames', request.session['user_data']['tokens']['access_token']) if area_code == "": data = r.json() return render(request, 'portal/account/dropdown_list.html', {'data': data}) else: return HttpResponse(r)