diff --git a/apimanager/branches/views.py b/apimanager/branches/views.py
index f3d5cc2..1a27401 100644
--- a/apimanager/branches/views.py
+++ b/apimanager/branches/views.py
@@ -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
diff --git a/apimanager/customerlist/templates/customerlist/customerlist.html b/apimanager/customerlist/templates/customerlist/customerlist.html
index d46756a..6ae61bf 100644
--- a/apimanager/customerlist/templates/customerlist/customerlist.html
+++ b/apimanager/customerlist/templates/customerlist/customerlist.html
@@ -3,7 +3,7 @@
{% trans "Customer List" %}
diff --git a/apimanager/customerlist/urls.py b/apimanager/customerlist/urls.py
index 5affbd7..122fb52 100644
--- a/apimanager/customerlist/urls.py
+++ b/apimanager/customerlist/urls.py
@@ -12,5 +12,5 @@ urlpatterns = [
name='customer-list'),
url(r'^export_csv$',
ExportCsvView.as_view(),
- name='export-csv')
+ name='export-csv-customer')
]
diff --git a/apimanager/customerlist/views.py b/apimanager/customerlist/views.py
index 3a8ebea..634b880 100644
--- a/apimanager/customerlist/views.py
+++ b/apimanager/customerlist/views.py
@@ -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
diff --git a/apimanager/productlist/templates/productlist/productlist.html b/apimanager/productlist/templates/productlist/productlist.html
index c5a0236..4a76a1f 100644
--- a/apimanager/productlist/templates/productlist/productlist.html
+++ b/apimanager/productlist/templates/productlist/productlist.html
@@ -3,43 +3,42 @@
{% trans "Product List" %}
-
-
-
- | {% trans "Product Code" %} |
- {% trans "Bank Id" %} |
- {% trans "Product Name" %} |
- {% trans "More info" %} |
-
-
- {% for product in products_list %}
+
+
+
+ | {% trans "Product Code" %} |
+ {% trans "Bank Id" %} |
+ {% trans "Name" %} |
+ {% trans "More info" %} |
+
+
+ {% for product in products_list %}
-
-
- | {{ product.code }} |
- {{ product.bank_id }} |
- {{ product.name }} |
-
-
+ |
+ {% trans "View" %} |
+
+ {% endfor %}
-
-
-
+
+
+
{% endblock %} {% block extrajs %} {% endblock extrajs %} {% block extracss %}
diff --git a/apimanager/productlist/urls.py b/apimanager/productlist/urls.py
index c9f0576..6fd076a 100644
--- a/apimanager/productlist/urls.py
+++ b/apimanager/productlist/urls.py
@@ -12,6 +12,6 @@ urlpatterns = [
name='product-list'),
url(r'^export_csv$',
ExportCsvView.as_view(),
- name='export-csv'),
+ name='export-csv-product'),
]
diff --git a/apimanager/productlist/views.py b/apimanager/productlist/views.py
index c75cdc4..966bdfe 100644
--- a/apimanager/productlist/views.py
+++ b/apimanager/productlist/views.py
@@ -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)