mirror of
https://github.com/OpenBankProject/API-Manager.git
synced 2026-02-06 14:46:45 +00:00
feature/ Get Bank List
This commit is contained in:
parent
23b988215a
commit
4241a511d5
@ -2,9 +2,6 @@
|
||||
{% block page_title %} {{ block.super }} / {% trans "Bank List" %}{% endblock page_title %} {% block content %}
|
||||
<div id="banks">
|
||||
<h1>{% trans "Bank 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-bank-csv' %}';">
|
||||
</form>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover tablesorter" id="atms-list" aria-describedby="atms list">
|
||||
<thead>
|
||||
|
||||
@ -4,13 +4,15 @@ URLs for Bank list app
|
||||
"""
|
||||
|
||||
from django.conf.urls import url
|
||||
from .views import BankListView, ExportCsvView
|
||||
from .views import BankListView #, ExportCsvView
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$',
|
||||
BankListView.as_view(),
|
||||
name='bank-list'),
|
||||
url(r'^export_csv$',
|
||||
ExportCsvView.as_view(),
|
||||
name='export-bank-csv')
|
||||
|
||||
]
|
||||
"""
|
||||
url(r'^export_csv$',
|
||||
ExportCsvView.as_view(),
|
||||
name='export-bank-csv') """
|
||||
|
||||
@ -3,7 +3,7 @@ from django.shortcuts import render
|
||||
# Create your views here.
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Views of Banks List app
|
||||
Views of Bank List app
|
||||
"""
|
||||
import datetime
|
||||
from django.contrib import messages
|
||||
@ -13,10 +13,7 @@ from django.urls import reverse_lazy
|
||||
from django.http import HttpResponse
|
||||
from django.views.generic import FormView,TemplateView, View
|
||||
from banks.views import IndexBanksView
|
||||
from base.views import get_banks
|
||||
from obp.api import API, APIError
|
||||
import csv
|
||||
|
||||
|
||||
|
||||
class BankListView(IndexBanksView, LoginRequiredMixin, FormView ):
|
||||
@ -28,13 +25,9 @@ class BankListView(IndexBanksView, LoginRequiredMixin, FormView ):
|
||||
try:
|
||||
urlpath = '/banks'
|
||||
result = api.get(urlpath)
|
||||
print("result is from get_banks:", result)
|
||||
banks_list = []
|
||||
if 'banks' in result:
|
||||
banks_list.extend(result["banks"])
|
||||
""" 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 []
|
||||
@ -50,32 +43,3 @@ class BankListView(IndexBanksView, LoginRequiredMixin, FormView ):
|
||||
'banks_list': banks_list
|
||||
})
|
||||
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 = get_banks(self.request)
|
||||
atms_list = []
|
||||
for bank_id in self.bankids:
|
||||
urlpath = '/banks/{}/atms'.format(bank_id)
|
||||
result = api.get(urlpath)
|
||||
#print(result)
|
||||
if 'atms' in result:
|
||||
atms_list.extend(result['atms'])
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
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'
|
||||
writer = csv.writer(response)
|
||||
writer.writerow(["id","name","notes","line_1","line_2","line_3","city", "county", "state", "postcode","country_code", "longitude","latitude","more_info"])
|
||||
for user in atms_list:
|
||||
writer.writerow([user['id'],user['name'], user['notes'], user["address"]['line_1'], user["address"]['line_2'],
|
||||
user["address"]['line_3'], user["address"]['city'], user["address"]['county'], user["address"]['state'], user["address"]['postcode'], user["address"]['country_code'], user["location"]['longitude'], user["location"]['latitude'], user['more_info']])
|
||||
return response
|
||||
|
||||
#print(atms_list)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user