feature add ATM

This commit is contained in:
Reena_Aheer 2022-04-21 11:53:03 +02:00
parent 87aee60412
commit e4c15d3ed2
6 changed files with 29 additions and 28 deletions

View File

@ -1,5 +1,5 @@
"""
Forms of ATM app
Forms of ATMs app
"""
from django import forms

View File

@ -5,13 +5,13 @@ URLs for metrics app
from django.conf.urls import url
from .views import IndexAtmView, UpdateAtmView
from .views import IndexAtmsView, UpdateAtmsView
urlpatterns = [
url(r'^$',
IndexAtmView.as_view(),
IndexAtmsView.as_view(),
name='atms_list'),
url(r'^update/(?P<atm_id>[0-9\w\@\.\+-]+)/bank/(?P<bank_id>[0-9\w\@\.\+-]+)/$',
UpdateAtmView.as_view(),
UpdateAtmsView.as_view(),
name='atms_update')
]

View File

@ -3,7 +3,7 @@ from django.shortcuts import render
# Create your views here.
# -*- coding: utf-8 -*-
"""
Views of branches app
Views of atms app
"""
from django.contrib import messages
@ -16,18 +16,18 @@ from obp.api import API, APIError
from .forms import CreateAtmForm
class IndexAtmView(LoginRequiredMixin, FormView):
"""Index view for ATM"""
class IndexAtmsView(LoginRequiredMixin, FormView):
"""Index view for ATMs"""
template_name = "atms/index.html"
form_class = CreateAtmForm
success_url = reverse_lazy('atms_list')
def dispatch(self, request, *args, **kwargs):
self.api = API(request.session.get('obp'))
return super(IndexAtmView, self).dispatch(request, *args, **kwargs)
return super(IndexAtmsView, self).dispatch(request, *args, **kwargs)
def get_form(self, *args, **kwargs):
form = super(IndexAtmView, self).get_form(*args, **kwargs)
form = super(IndexAtmsView, self).get_form(*args, **kwargs)
# Cannot add api in constructor: super complains about unknown kwarg
form.api = self.api
fields = form.fields
@ -106,6 +106,7 @@ class IndexAtmView(LoginRequiredMixin, FormView):
try:
data = form.cleaned_data
urlpath = '/banks/{}/atms'.format(data['bank_id'])
print(urlpath)
payload = {
"id": data["atm_id"],
"bank_id": data["bank_id"],
@ -136,7 +137,6 @@ class IndexAtmView(LoginRequiredMixin, FormView):
"cash_withdrawal_national_fee": data["cash_withdrawal_national_fee"] if data["cash_withdrawal_national_fee"]!="" else "false",
"cash_withdrawal_international_fee": data["cash_withdrawal_international_fee"] if data["cash_withdrawal_international_fee"]!="" else "false",
"balance_inquiry_fee": data["balance_inquiry_fee"] if data["balance_inquiry_fee"]!="" else "false",
"branch_type": data["branch_type"] if data["branch_type"]!="" else "branch type",
"more_info": data["more_info"] if data["more_info"]!="" else "more info",
"located_at": data["located_at"] if data["located_at"]!="" else "located_at",
"services": data["services"] if data["services"]!="" else "services",
@ -144,16 +144,16 @@ class IndexAtmView(LoginRequiredMixin, FormView):
result = self.api.post(urlpath, payload=payload)
except APIError as err:
error_once_only(self.request, err)
return super(IndexAtmView, self).form_invalid(form)
return super(IndexAtmsView, self).form_invalid(form)
except Exception as err:
error_once_only(self.request, "Unknown Error")
return super(IndexAtmViewView, self).form_invalid(form)
return super(IndexAtmsView, self).form_invalid(form)
if 'code' in result and result['code']>=400:
error_once_only(self.request, result['message'])
return super(IndexAtmView, self).form_valid(form)
msg = 'Atm {} for Bank {} has been created successfully!'.format(result['id'], result['bank_id'])
messages.error(self.request, result['message'])
return super(IndexAtmsView, self).form_valid(form)
msg = 'atm {} for Bank {} has been created successfully!'.format(result['id'], result['bank_id'])
messages.success(self.request, msg)
return super(IndexAtmView, self).form_valid(form)
return super(IndexAtmsView, self).form_valid(form)
def get_banks(self):
api = API(self.request.session.get('obp'))
@ -190,7 +190,7 @@ class IndexAtmView(LoginRequiredMixin, FormView):
return atms_list
def get_context_data(self, **kwargs):
context = super(IndexAtmView, self).get_context_data(**kwargs)
context = super(IndexAtmsView, self).get_context_data(**kwargs)
atms_list = self.get_atms(context)
context.update({
'atms_list': atms_list,
@ -199,17 +199,17 @@ class IndexAtmView(LoginRequiredMixin, FormView):
return context
class UpdateAtmView(LoginRequiredMixin, FormView):
class UpdateAtmsView(LoginRequiredMixin, FormView):
template_name = "atms/update.html"
success_url = '/atms/'
form_class = CreateAtmForm
def dispatch(self, request, *args, **kwargs):
self.api = API(request.session.get('obp'))
return super(UpdateAtmView, self).dispatch(request, *args, **kwargs)
return super(UpdateAtmsView, self).dispatch(request, *args, **kwargs)
def get_form(self, *args, **kwargs):
form = super(UpdateAtmView, self).get_form(*args, **kwargs)
form = super(UpdateAtmsView, self).get_form(*args, **kwargs)
# Cannot add api in constructor: super complains about unknown kwarg
form.api = self.api
fields = form.fields
@ -285,7 +285,7 @@ class UpdateAtmView(LoginRequiredMixin, FormView):
def form_valid(self, form):
data = form.cleaned_data
urlpath = '/banks/{}/atms/{}'.format(data["bank_id"], data["atm_id"])
urlpath = '/banks/{}/atms/{}'.format(data["bank_id"],data["atm_id"])
payload = {
#"id": data["atm_id"],
"bank_id": data["bank_id"],
@ -324,20 +324,20 @@ class UpdateAtmView(LoginRequiredMixin, FormView):
result = self.api.put(urlpath, payload=payload)
if 'code' in result and result['code']>=400:
error_once_only(self.request, result['message'])
return super(UpdateAtmView, self).form_invalid(form)
return super(UpdateAtmsView, self).form_invalid(form)
except APIError as err:
messages.error(self.request, err)
return super(UpdateAtmView, self).form_invalid(form)
return super(UpdateAtmsView, self).form_invalid(form)
except:
messages.error(self.request, "Unknown Error")
return super(UpdateAtmView, self).form_invalid(form)
return super(UpdateAtmsView, self).form_invalid(form)
msg = 'Atm {} for Bank {} has been created successfully!'.format( # noqa
data["atm_id"], data["bank_id"])
messages.success(self.request, msg)
return super(UpdateAtmView, self).form_valid(form)
return super(UpdateAtmsView, self).form_valid(form)
def get_context_data(self, **kwargs):
context = super(UpdateAtmView, self).get_context_data(**kwargs)
context = super(UpdateAtmsView, self).get_context_data(**kwargs)
self.bank_id = self.kwargs['bank_id']
self.atm_id = self.kwargs['atm_id']
context.update({

View File

@ -1,4 +1,3 @@
from django.shortcuts import render
# Create your views here.
@ -133,6 +132,7 @@ class IndexBranchesView(LoginRequiredMixin, FormView):
try:
data = form.cleaned_data
urlpath = '/banks/{}/branches'.format(data['bank_id'])
print(urlpath)
payload = {
"id": data["branch_id"],
"bank_id": data["bank_id"],

View File

@ -32,7 +32,7 @@ class DirectLoginAuthenticator(Authenticator):
requestheaders['consumer_key']=local_settings.OAUTH_CONSUMER_KEY
#print("hello",local_settings.OAUTH_CONSUMER_KEY)
url = settings.API_HOST + settings.DIRECTLOGIN_PATH
authorization = 'DirectLogin username="{}",password="{}",consumer_key="{}"'.format( # noqa
authorization = 'DirectLogin username="{}",password="{}",consumer_key="{}"'.format(
requestheaders['username'],
requestheaders['password'],
requestheaders['consumer_key']

View File

@ -15,6 +15,7 @@ class DirectLoginForm(forms.Form):
attrs={'class': 'form-control'}))
password = forms.CharField(widget=forms.PasswordInput(
attrs={'class': 'form-control'}))
# We are now getting consumer_key from settings
#consumer_key = forms.CharField(widget=forms.TextInput(
#attrs={'class': 'form-control'}))