update customer_list

This commit is contained in:
Reena-cell 2022-10-10 12:21:07 +02:00
parent 26147ad728
commit 034e03afff
22 changed files with 251 additions and 13 deletions

View File

@ -59,6 +59,7 @@ INSTALLED_APPS = [
'productlist',
'entitlementrequests',
'customers',
'customerlist',
'metrics',
'config',
'webui',

View File

@ -43,6 +43,7 @@ urlpatterns += i18n_patterns(
url(r'^products/', include('products.urls')),
url(r'^products/list', include('productlist.urls')),
url(r'^customers/', include('customers.urls')),
url(r'^customer/list', include('customerlist.urls')),
url(r'^metrics/', include('metrics.urls')),
url(r'^config/', include('config.urls')),
url(r'^webui/', include('webui.urls')),

View File

@ -31,7 +31,6 @@ class IndexAtmsView(LoginRequiredMixin, FormView):
# Cannot add api in constructor: super complains about unknown kwarg
form.api = self.api
fields = form.fields
print(fields, "These are fields")
try:
fields['bank_id'].choices = self.api.get_bank_id_choices()
fields['is_accessible'].choices = [('',_('Choose...')),(True, True), (False, False)]

View File

@ -59,11 +59,12 @@
<li {% if metrics_summary_url in request.path %} class="active" {% endif %}><a href="{{ metrics_summary_url }}">{% trans "KPI Dashboard" %}</a></li>
</ul>
</li>
{% url "branches_list" as branches_list_url %} {% url "customers-create" as customers_create_url %} {% url "atms_create" as atms_create_url %} {% url "atm-list" as atm_list_url %} {% url "product-list" as product_list_url %} {% url "products-create" as product_create_url %}
{% url "branches_list" as branches_list_url %} {% url "customers-create" as customers_create_url %} {% url "customer-list" as customer_list_url %} {% url "atms_create" as atms_create_url %} {% url "atm-list" as atm_list_url %} {% url "product-list" as product_list_url %} {% url "products-create" as product_create_url %}
<li class="dropdown{% if customers_create_url in request.path %} active{% endif %}">
<a href="#" data-toggle="dropdown" class="dropdown-toggle">{% trans "Resources" %}</a>
<ul class="dropdown-menu">
<li {% if customers_create_url in request.path %} class="active" {% endif %}><a href="{{ customers_create_url }}">{% trans "Customers" %}</a></li>
<li {% if customer_list_url in request.path %} class="active" {% endif %}><a href="{{ customer_list_url }}">{% trans "Customer List" %}</a></li>
<hr class="dropdown-hr">
<li {% if branches_list_url in request.path %} class="active" {% endif %}><a href="{{ branches_list_url }}">{% trans "Branches" %}</a></li>
<li {% if atms_create_url in request.path %} class="active" {% endif %}><a href="{{ atms_create_url }}">{% trans "ATM Create" %}</a></li>

View File

View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class CustomersConfig(AppConfig):
name = 'customers_list'

View File

View File

@ -0,0 +1,4 @@
from django.db import models
# Create your models here.
# -*- coding: utf-8 -*-

View File

@ -0,0 +1,18 @@
#customers_list div {
margin: 5px 0;
}
/* The actual popup (appears on top) */
.popuptext {
width: 250px;
background-color: #555;
color: #fff;
text-align: left;
border-radius: 6px;
padding: 8px 0;
z-index: 1;
/*bottom: 125%;*/
top:100%
left: 50%;
margin-left: -80px;
}

View File

@ -0,0 +1,5 @@
$(document).ready(function($) {
$('#info').click(function() {
alert("Hello World")
});
});

View File

@ -0,0 +1,43 @@
{% extends 'base.html' %} {% load static %} {% load i18n %}
{% block page_title %} {{ block.super }} / {% trans "Customer List" %}{% endblock page_title %} {% block content %}
<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' %}';">
</form>
<div class="table-responsive">
<table class="table table-hover tablesorter" id="customers_list" aria-describedby="customers list">
<thead>
<th scope="col">{% trans "Customer Id" %}</th>
<th scope="col">{% trans "Bank Id" %}</th>
<th scope="col">{% trans "Customer Name" %}</th>
<th scope="col">{% trans "More info" %}</th>
</thead>
<tbody>
{% for customer in customer_list %}
{% url 'customers_update' customer.id customer.bank_id as url_customer_update %}
<tr data-customer-id="{{ customer.id }}">
<td>{{ customer.id }}</td>
<td>{{ customer.bank_id }}</td>
<td>{{ customer.name }}</td>
<td>
<div class="popuptext">
<ul>
<li>{% trans "Other Info" %}:
<ul>
<li>line1: {{customer.email}}</li>
</ul>
</li>
</ul>
</div>
</td>
<td><a href="{{ url_customer_update }}" class="btn btn-primary">{% trans "View" %}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock %} {% block extrajs %} {% endblock extrajs %} {% block extracss %}
<link href="{% static 'customerlist/css/customerlist.css' %}" rel="stylesheet"> {% endblock extracss %}

View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

View File

@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
"""
URLs for customer list app
"""
from django.conf.urls import url
from .views import CustomerListView, ExportCsvView
urlpatterns = [
url(r'^$',
CustomerListView.as_view(),
name='customer-list'),
url(r'^export_csv$',
ExportCsvView.as_view(),
name='export-csv')
]

View File

@ -0,0 +1,104 @@
from django.shortcuts import render
# Create your views here.
# -*- coding: utf-8 -*-
"""
Views of customer list app
"""
import datetime
from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
import json
from django.urls import reverse_lazy
from django.http import HttpResponse
from django.views.generic import FormView,TemplateView, View
from customers.views import CreateView
from obp.api import API, APIError
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 = '/banks/{}/my/customers'.format(bank_id)
#urlpath = 'http://127.0.0.1:8080/obp/v4.0.0/my/customers'
result = api.get(urlpath)
print(result, "Result is ")
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 []
print(customers_list, "This is a list")
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'
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(self, request, *args, **kwargs):
api = API(self.request.session.get('obp'))
try:
self.bankids = self.get_banks()
customers_list = []
for bank_id in self.bankids:
urlpath = '/banks/{}/customers'.format(bank_id)
result = api.get(urlpath)
#print(result)
if 'customers' in result:
customers_list.extend(result['customers'])
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(["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:
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
#print(atms_list)

View File

@ -4,7 +4,6 @@ URLs for customers app
"""
from django.conf.urls import url
from .views import CreateView
urlpatterns = [

View File

@ -41,5 +41,6 @@
</table>
</div>
</div>
{% endblock %} {% block extrajs %} {% endblock extrajs %} {% block extracss %}
<link href="{% static 'productlist/css/product.css' %}" rel="stylesheet"> {% endblock extracss %}

View File

@ -11,6 +11,7 @@ urlpatterns = [
ProductListView.as_view(),
name='product-list'),
url(r'^export_csv$',
ExportCsvView.as_view(),
name='export-csv')
ExportCsvView.as_view(),
name='export-csv'),
]

View File

@ -14,6 +14,7 @@ from django.http import HttpResponse
from django.views.generic import FormView,TemplateView, View
from products.views import IndexProductView
from obp.api import API, APIError
import csv
class ProductListView(IndexProductView, LoginRequiredMixin, FormView ):
@ -97,4 +98,3 @@ class ExportCsvView(LoginRequiredMixin, View):
return response
#print(atms_list)

View File

@ -73,7 +73,7 @@
<div class="row">
<div class="col-sm-12 hidden-xs">
<div class="form-group">
<button type="submit" class="btn btn-primary btn-green">{% trans "Add" %}</button>
<button type="submit" class="btn btn-primary btn-green" onclick="createProductList()">{% trans "Add" %}</button>
</div>
</div>
</div>
@ -84,7 +84,16 @@
{% block extrajs %}
{% comment %}
<script type="text/javascript" src="{% static 'products/js/products.js' %}"></script>
<script type="text/javascript">
<script>
function createProductList(){
$.post('/products/list/createProductList', {
'api_collection_name': 'api_collection_name',
'api_collection_is_sharable': 'api_collection_is_sharable',
'api_collection_description': 'api_collection_description',
}, function (response) {
console.log(" hello", response)
});
}
</script>
{% endcomment %}
{% endblock extrajs %}

View File

@ -5,7 +5,7 @@ URLs for metrics app
from django.conf.urls import url
from .views import IndexProductView, UpdateProductView
from .views import IndexProductView, UpdateProductView, createList
urlpatterns = [
url(r'^create',
@ -13,5 +13,8 @@ urlpatterns = [
name='products-create'),
url(r'^update/(?P<product_code>[0-9\w\@\.\+-]+)/bank/(?P<bank_id>[0-9\w\@\.\+-]+)/$',
UpdateProductView.as_view(),
name='products_update')
name='products_update'),
url(r'^createProductList',
createList,
name = 'create-product-list'),
]

View File

@ -13,6 +13,8 @@ from django.urls import reverse_lazy
from django.views.generic import FormView
from obp.api import API, APIError
from .forms import CreateProductForm
from django.views.decorators.csrf import csrf_exempt
from base.utils import exception_handle
class IndexProductView(LoginRequiredMixin, FormView):
"""Index view for Product"""
@ -29,6 +31,7 @@ class IndexProductView(LoginRequiredMixin, FormView):
# Cannot add api in constructor: super complains about unknown kwarg
form.api = self.api
fields = form.fields
print(fields, "These are fields")
try:
fields['bank_id'].choices = self.api.get_bank_id_choices()
except APIError as err:
@ -39,8 +42,23 @@ class IndexProductView(LoginRequiredMixin, FormView):
def form_valid(self, form):
try:
pass
#result = self.api.put(urlpath, payload=payload)
data = form.cleaned_data
print(data, "This is a data")
urlpath = '/banks/{}/products'.format(bank_id)
payload={
"parent_product_code": data["parent_product_code"],
"name": data["name"],
"more_info_url": data["more_info_url"],
"terms_and_conditions_url": data["terms_and_conditions_url"],
"description": data["description"],
"meta": {
"license": {
"id": "ODbL-1.0",
"name": data["meta_license_name"] if data["meta_license_name"]!="" else "license name"
}
},
}
result = self.api.put(urlpath, payload=payload)
except APIError as err:
messages.error(self.request, err)
return super(IndexProductView, self).form_invalid(form)
@ -135,5 +153,9 @@ class UpdateProductView(LoginRequiredMixin, FormView):
return context
@exception_handle
@csrf_exempt
def createList(request):
print(request.POST, "createProductList listt")
return HttpResponse("<h1>View 1</h1>")