mirror of
https://github.com/OpenBankProject/API-Manager.git
synced 2026-02-06 14:46:45 +00:00
Get bank function calling and Correction in CSV
This commit is contained in:
parent
08bd46629c
commit
7b6f607b18
@ -11,10 +11,9 @@ from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
import json
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.generic import FormView
|
||||
|
||||
from obp.api import API, APIError
|
||||
|
||||
from .forms import CreateBranchForm
|
||||
from base.views import get_banks
|
||||
|
||||
class IndexBranchesView(LoginRequiredMixin, FormView):
|
||||
"""Index view for branches"""
|
||||
@ -173,24 +172,11 @@ class IndexBranchesView(LoginRequiredMixin, FormView):
|
||||
messages.success(self.request, msg)
|
||||
return super(IndexBranchesView, self).form_valid(form)
|
||||
|
||||
def get_banks(self):
|
||||
api = API(self.request.session.get('obp'))
|
||||
try:
|
||||
urlpath = '/banks'
|
||||
result = api.get(urlpath)
|
||||
if 'banks' in result:
|
||||
return [bank['id'] for bank in sorted(result['banks'], key=lambda d: d['id'])]
|
||||
else:
|
||||
return []
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
return []
|
||||
|
||||
def get_branches(self, context):
|
||||
|
||||
api = API(self.request.session.get('obp'))
|
||||
try:
|
||||
self.bankids = self.get_banks()
|
||||
self.bankids = get_banks(self.request)
|
||||
branches_list = []
|
||||
for bank_id in self.bankids:
|
||||
urlpath = '/banks/{}/branches'.format(bank_id)
|
||||
@ -212,7 +198,7 @@ class IndexBranchesView(LoginRequiredMixin, FormView):
|
||||
branches_list = self.get_branches(context)
|
||||
context.update({
|
||||
'branches_list': branches_list,
|
||||
'bankids': self.bankids
|
||||
'bankids': get_banks(self.request)
|
||||
})
|
||||
return context
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
<div id="customers">
|
||||
<h1>{% trans "Customer List" %}</h1>
|
||||
<form class="form-inline" method="get">
|
||||
<input type="submit" class="btn btn-default" value ='{% trans "Export CSV" %}' onclick="javascript: form.action='{% url 'export-csv' %}';">
|
||||
<input type="submit" class="btn btn-default" value ='{% trans "Export CSV" %}' onclick="javascript: form.action='{% url 'export-csv-customer' %}';">
|
||||
</form>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover tablesorter" id="customers_list" aria-describedby="customers list">
|
||||
|
||||
@ -12,5 +12,5 @@ urlpatterns = [
|
||||
name='customer-list'),
|
||||
url(r'^export_csv$',
|
||||
ExportCsvView.as_view(),
|
||||
name='export-csv')
|
||||
name='export-csv-customer')
|
||||
]
|
||||
|
||||
@ -14,6 +14,7 @@ from django.http import HttpResponse
|
||||
from django.views.generic import FormView,TemplateView, View
|
||||
from customers.views import CreateView
|
||||
from obp.api import API, APIError
|
||||
from base.views import get_banks
|
||||
import csv
|
||||
|
||||
|
||||
@ -21,65 +22,41 @@ import csv
|
||||
class CustomerListView(CreateView, LoginRequiredMixin, FormView ):
|
||||
template_name = "customerlist/customerlist.html"
|
||||
success_url = '/customers/list'
|
||||
def get_banks(self):
|
||||
api = API(self.request.session.get('obp'))
|
||||
try:
|
||||
urlpath = '/banks'
|
||||
result = api.get(urlpath)
|
||||
if 'banks' in result:
|
||||
return [bank['id'] for bank in sorted(result['banks'], key=lambda d: d['id'])]
|
||||
else:
|
||||
return []
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
return []
|
||||
|
||||
def get_customers(self, context):
|
||||
|
||||
api = API(self.request.session.get('obp'))
|
||||
try:
|
||||
self.bankids = self.get_banks()
|
||||
customers_list = []
|
||||
#for bank_id in self.bankids:
|
||||
urlpath = '/customers'
|
||||
#urlpath = 'http://127.0.0.1:8080/obp/v4.0.0/my/customers'
|
||||
result = api.get(urlpath)
|
||||
if 'customers' in result:
|
||||
customers_list.extend(result['customers'])
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
return []
|
||||
except Exception as inst:
|
||||
messages.error(self.request, "Unknown Error {}".format(type(inst).__name__))
|
||||
return []
|
||||
|
||||
return customers_list
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(CreateView, self).get_context_data(**kwargs)
|
||||
customers_list = self.get_customers(context)
|
||||
context.update({
|
||||
'customers_list': customers_list,
|
||||
'bankids': self.bankids
|
||||
})
|
||||
return context
|
||||
class ExportCsvView(LoginRequiredMixin, View):
|
||||
"""View to export the user to csv"""
|
||||
def get_banks(self):
|
||||
api = API(self.request.session.get('obp'))
|
||||
try:
|
||||
urlpath = '/banks'
|
||||
self.bankids = get_banks(self.request)
|
||||
customers_list = []
|
||||
#for bank_id in self.bankids:
|
||||
urlpath = '/customers'
|
||||
#urlpath = 'http://127.0.0.1:8080/obp/v4.0.0/my/customers'
|
||||
result = api.get(urlpath)
|
||||
if 'banks' in result:
|
||||
return [bank['id'] for bank in sorted(result['banks'], key=lambda d: d['id'])]
|
||||
else:
|
||||
return []
|
||||
if 'customers' in result:
|
||||
customers_list.extend(result['customers'])
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
return []
|
||||
except Exception as inst:
|
||||
messages.error(self.request, "Unknown Error {}".format(type(inst).__name__))
|
||||
return []
|
||||
|
||||
return customers_list
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(CreateView, self).get_context_data(**kwargs)
|
||||
customers_list = self.get_customers(context)
|
||||
context.update({
|
||||
'customers_list': customers_list,
|
||||
'bankids': get_banks(self.request)
|
||||
})
|
||||
return context
|
||||
class ExportCsvView(LoginRequiredMixin, View):
|
||||
"""View to export the user to csv"""
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
api = API(self.request.session.get('obp'))
|
||||
try:
|
||||
self.bankids = self.get_banks()
|
||||
self.bankids = get_banks(self.request)
|
||||
customers_list = []
|
||||
for bank_id in self.bankids:
|
||||
urlpath = '/banks/{}/customers'.format(bank_id)
|
||||
@ -94,7 +71,7 @@ class ExportCsvView(LoginRequiredMixin, View):
|
||||
response['Content-Disposition'] = 'attachment;filename= Customers'+ str(datetime.datetime.now())+'.csv'
|
||||
writer = csv.writer(response)
|
||||
writer.writerow(["bank_id","customer_id","customer_number","legal_name","mobile_phone_number","email","face_image", "url", "date", "date_of_birth","relationship_status", "dependants","dob_of_dependants","employment_status"])
|
||||
for user in atms_list:
|
||||
for user in customers_list:
|
||||
writer.writerow([user['bank_id'],user['customer_id'], user['customer_number'], user["legal_name"],
|
||||
user["mobile_phone_number"], user["email"], user["face_image"]['url'], user["face_image"]['date'], user["date_of_birth"], user['relationship_status'], user["dependants"], user["dob_of_dependants"], user['employment_status']])
|
||||
return response
|
||||
|
||||
@ -3,43 +3,42 @@
|
||||
<div id="products">
|
||||
<h1>{% trans "Product List" %}</h1>
|
||||
<form class="form-inline" method="get">
|
||||
<input type="submit" class="btn btn-default" value ='{% trans "Export CSV" %}' onclick="javascript: form.action='{% url 'export-csv' %}';">
|
||||
<input type="submit" class="btn btn-default" value ='{% trans "Export CSV" %}' onclick="javascript: form.action='{% url 'export-csv-product' %}';">
|
||||
</form>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover tablesorter" id="product-list" aria-describedby="atms list">
|
||||
<thead>
|
||||
<th scope="col">{% trans "Product Code" %}</th>
|
||||
<th scope="col">{% trans "Bank Id" %}</th>
|
||||
<th scope="col">{% trans "Product Name" %}</th>
|
||||
<th scope="col">{% trans "More info" %}</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for product in products_list %}
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover tablesorter" id="product-list" aria-describedby="Product list">
|
||||
<thead>
|
||||
<th scope="col">{% trans "Product Code" %}</th>
|
||||
<th scope="col">{% trans "Bank Id" %}</th>
|
||||
<th scope="col">{% trans "Name" %}</th>
|
||||
<th scope="col">{% trans "More info" %}</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for product in products_list %}
|
||||
|
||||
<!--{% url 'atms_update' atm.id atm.bank_id as url_atm_update %}-->
|
||||
<tr data-product-code="{{ product.code }}">
|
||||
<td>{{ product.code }}</td>
|
||||
<td>{{ product.bank_id }}</td>
|
||||
<td>{{ product.name }}</td>
|
||||
<td>
|
||||
<div class="popuptext">
|
||||
<ul>
|
||||
<li>{% trans "Description" %}:
|
||||
<ul>
|
||||
<li>{{product.Description.more_info_url}}</li>
|
||||
</ul>
|
||||
</li>
|
||||
<tr data-product-code="{{ product.product_code }}">
|
||||
<td>{{ product.product_code }}</td>
|
||||
<td>{{ product.bank_id }}</td>
|
||||
<td>{{ product.name }}</td>
|
||||
<td>
|
||||
<div class="popuptext">
|
||||
<ul>
|
||||
<li>{% trans "Description" %}:
|
||||
<ul>
|
||||
<li>{{product.more_info_url}}</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
<td><a href="{{ url_product_update }}" class="btn btn-primary">{% trans "View" %}</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
<td><a href="{{ url_product_update }}" class="btn btn-primary">{% trans "View" %}</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %} {% block extrajs %} {% endblock extrajs %} {% block extracss %}
|
||||
|
||||
@ -12,6 +12,6 @@ urlpatterns = [
|
||||
name='product-list'),
|
||||
url(r'^export_csv$',
|
||||
ExportCsvView.as_view(),
|
||||
name='export-csv'),
|
||||
name='export-csv-product'),
|
||||
|
||||
]
|
||||
|
||||
@ -81,7 +81,6 @@ class ExportCsvView(LoginRequiredMixin, View):
|
||||
for bank_id in self.bankids:
|
||||
urlpath = '/banks/{}/products'.format(bank_id)
|
||||
result = api.get(urlpath)
|
||||
#print(result)
|
||||
if 'products' in result:
|
||||
products_list.extend(result['products'])
|
||||
except APIError as err:
|
||||
@ -89,12 +88,11 @@ class ExportCsvView(LoginRequiredMixin, View):
|
||||
except Exception as inst:
|
||||
messages.error(self.request, "Unknown Error {}".format(type(inst).__name__))
|
||||
response = HttpResponse(content_type = 'text/csv')
|
||||
response['Content-Disposition'] = 'attachment;filename= Atms'+ str(datetime.datetime.now())+'.csv'
|
||||
response['Content-Disposition'] = 'attachment;filename= Product'+ str(datetime.datetime.now())+'.csv'
|
||||
writer = csv.writer(response)
|
||||
writer.writerow(["product_code","bank_id","name","parent_product_code","more_info_url","terms_and_conditions_url","description", "license", "id", "name"])
|
||||
for user in atms_list:
|
||||
writer.writerow(["product_code","bank_id","name","parent_product_code","more_info_url","terms_and_conditions_url","description"])
|
||||
for user in products_list:
|
||||
writer.writerow([user['product_code'],user['bank_id'], user['name'], user["parent_product_code"], user["more_info_url"],
|
||||
user["terms_and_conditions_url"], user["description"], user["license"]['id'], user["license"]['name']])
|
||||
user["terms_and_conditions_url"], user["description"]])
|
||||
return response
|
||||
|
||||
#print(atms_list)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user