mirror of
https://github.com/OpenBankProject/API-Manager.git
synced 2026-02-06 13:06:45 +00:00
feature ATM page
This commit is contained in:
parent
4f2693d39b
commit
49d21d7b18
10
README.md
10
README.md
@ -1,6 +1,14 @@
|
||||
# API Manager
|
||||
|
||||
This is a Django project to manage the Open Bank Project APIs via API Calls.
|
||||
This is a Django project to manage the Open Bank Project via API Calls.
|
||||
|
||||
You can use this project to:
|
||||
|
||||
1. Manage API Consumers (Apps)
|
||||
2. View API Metrics (which Consumers called which endpoints)
|
||||
3. Grant / Revoke User Entitlelements
|
||||
4. Manage certain resources e.g. Branches
|
||||
5. etc. etc.
|
||||
|
||||
To use this app, you need to authenticate against a sandbox where you have to register an account beforehand. Currently, you can enable or disable consumers.
|
||||
|
||||
|
||||
@ -34,6 +34,7 @@ urlpatterns = [
|
||||
url(r'^entitlementrequests/', include('entitlementrequests.urls')),
|
||||
url(r'^users/', include('users.urls')),
|
||||
url(r'^branches/', include('branches.urls')),
|
||||
url(r'^atms/', include('atms.urls')),
|
||||
url(r'^customers/', include('customers.urls')),
|
||||
url(r'^metrics/', include('metrics.urls')),
|
||||
url(r'^config/', include('config.urls')),
|
||||
|
||||
0
apimanager/atms/__init__.py
Normal file
0
apimanager/atms/__init__.py
Normal file
3
apimanager/atms/admin.py
Normal file
3
apimanager/atms/admin.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
5
apimanager/atms/apps.py
Normal file
5
apimanager/atms/apps.py
Normal file
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class BranchesConfig(AppConfig):
|
||||
name = 'atms'
|
||||
189
apimanager/atms/forms.py
Normal file
189
apimanager/atms/forms.py
Normal file
@ -0,0 +1,189 @@
|
||||
"""
|
||||
Forms of branches app
|
||||
"""
|
||||
|
||||
from django import forms
|
||||
|
||||
import random
|
||||
|
||||
|
||||
class CreateAtmForm(forms.Form):
|
||||
|
||||
atm_id = forms.CharField(
|
||||
label='ATM Id',
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'placeholder': 'atm-id-{}'.format(random.randint(1,1000)),
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
initial='atm-id-{}'.format(random.randint(1,1000)),
|
||||
)
|
||||
|
||||
bank_id = forms.ChoiceField(
|
||||
label='Bank',
|
||||
widget=forms.Select(
|
||||
attrs={
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
choices=[],
|
||||
)
|
||||
name = forms.CharField(
|
||||
label='Name',
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'placeholder': 'The name of the branch',
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=True
|
||||
)
|
||||
address = forms.CharField(
|
||||
label='Address',
|
||||
widget=forms.Textarea(
|
||||
attrs={
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=False
|
||||
)
|
||||
|
||||
location_latitude = forms.FloatField(
|
||||
label='Latitude',
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'placeholder': 37.0,
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
|
||||
location_longitude = forms.FloatField(
|
||||
label='Longitude',
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'placeholder': 110.0,
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
|
||||
meta_license_id = forms.CharField(
|
||||
label='meta_license_id',
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'placeholder': 'PDDL',
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
|
||||
meta_license_name = forms.CharField(
|
||||
label='meta_license_name',
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'placeholder': 'Open Data Commons Public Domain Dedication and License',
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
|
||||
lobby = forms.CharField(
|
||||
label=' Lobby Opening Hours',
|
||||
widget=forms.Textarea(
|
||||
attrs={
|
||||
'placeholder': 'None',
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
drive_up = forms.CharField(
|
||||
label='Drive Up',
|
||||
widget=forms.Textarea(
|
||||
attrs={
|
||||
'placeholder': 'None', # noqa
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
atm_routing_scheme = forms.CharField(
|
||||
label='Branch Routing Scheme',
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'placeholder': 'OBP',
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
atm_routing_address = forms.CharField(
|
||||
label='Branch Routing Address',
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'placeholder': '123abc',
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
is_accessible = forms.ChoiceField(
|
||||
label='is accessible',
|
||||
widget=forms.Select(
|
||||
attrs={
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
accessibleFeatures = forms.CharField(
|
||||
label='Accessible Features',
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'placeholder': 'wheelchair, atm usuable by the visually impaired',
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
atm_type = forms.CharField(
|
||||
label='ATM type',
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'placeholder': 'Full service store',
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
more_info = forms.CharField(
|
||||
label='More information',
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'placeholder': 'short walk to the lake from here',
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
|
||||
phone_number = forms.CharField(
|
||||
label='Mobile Phone Number',
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'placeholder': 'E.g. +49 123 456 78 90 12',
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs.setdefault('label_suffix', '')
|
||||
super(CreateAtmForm, self).__init__(*args, **kwargs)
|
||||
4
apimanager/atms/models.py
Normal file
4
apimanager/atms/models.py
Normal file
@ -0,0 +1,4 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
# -*- coding: utf-8 -*-
|
||||
18
apimanager/atms/static/atms/css/atms.css
Normal file
18
apimanager/atms/static/atms/css/atms.css
Normal file
@ -0,0 +1,18 @@
|
||||
#atms_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;
|
||||
}
|
||||
5
apimanager/atms/static/atms/js/atms.js
Normal file
5
apimanager/atms/static/atms/js/atms.js
Normal file
@ -0,0 +1,5 @@
|
||||
$(document).ready(function($) {
|
||||
$('#info').click(function() {
|
||||
alert("Hello World")
|
||||
});
|
||||
});
|
||||
233
apimanager/atms/templates/atms/index.html
Normal file
233
apimanager/atms/templates/atms/index.html
Normal file
@ -0,0 +1,233 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load static %}
|
||||
|
||||
{% block page_title %}{{ block.super }} / Atms{% endblock page_title %}
|
||||
|
||||
{% block content %}
|
||||
<div id="atms_list">
|
||||
<h1>ATMs</h1>
|
||||
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{% if form.non_field_errors %}
|
||||
<div class="alert alert-danger">
|
||||
{{ form.non_field_errors }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.atm_id.errors %}<div class="alert alert-danger">{{ form.atm_id.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.atm_id.label_tag }}
|
||||
{{ form.atm_id }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.bank_id.errors %}<div class="alert alert-danger">{{ form.bank_id.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.bank_id.label_tag }}
|
||||
{{ form.bank_id }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.name.errors %}<div class="alert alert-danger">{{ form.name.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.name.label_tag }}
|
||||
{{ form.name }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.branch_type.errors %}<div class="alert alert-danger">{{ form.branch_type.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.branch_type.label_tag }}
|
||||
{{ form.branch_type }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.location_latitude.errors %}<div class="alert alert-danger">{{ form.location_latitude.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.location_latitude.label_tag }}
|
||||
{{ form.location_latitude }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.location_longitude.errors %}<div class="alert alert-danger">{{ form.location_longitude.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.location_longitude.label_tag }}
|
||||
{{ form.location_longitude }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.meta_license_name.errors %}<div class="alert alert-danger">{{ form.meta_license_name.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.meta_license_name.label_tag }}
|
||||
{{ form.meta_license_name }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.atm_routing_scheme.errors %}<div class="alert alert-danger">{{ form.atm_routing_scheme.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.atm_routing_scheme.label_tag }}
|
||||
{{ form.atm_routing_scheme }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.atm_routing_address.errors %}<div class="alert alert-danger">{{ form.atm_routing_address.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.atm_routing_address.label_tag }}
|
||||
{{ form.atm_routing_address }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.is_accessible.errors %}<div class="alert alert-danger">{{ form.is_accessible.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.is_accessible.label_tag }}
|
||||
{{ form.is_accessible }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.accessibleFeatures.errors %}<div class="alert alert-danger">{{ form.accessibleFeatures.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.accessibleFeatures.label_tag }}
|
||||
{{ form.accessibleFeatures }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.more_info.errors %}<div class="alert alert-danger">{{ form.more_info.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.more_info.label_tag }}
|
||||
{{ form.more_info }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.phone_number.errors %}<div class="alert alert-danger">{{ form.phone_number.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.phone_number.label_tag }}
|
||||
{{ form.phone_number }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.address.errors %}<div class="alert alert-danger">{{ form.address.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.address.label_tag }}
|
||||
{{ form.address }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.lobby.errors %}<div class="alert alert-danger">{{ form.lobby.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.lobby.label_tag }}
|
||||
{{ form.lobby }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.drive_up.errors %}<div class="alert alert-danger">{{ form.drive_up.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.drive_up.label_tag }}
|
||||
{{ form.drive_up }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 hidden-xs">
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-primary btn-green">Add</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover tablesorter" id="branches-list" aria-describedby="branches list">
|
||||
<thead>
|
||||
<th scope="col">Atm Id</th>
|
||||
<th scope="col">Bank Id</th>
|
||||
<th scope="col">ATM Name</th>
|
||||
<th scope="col">More_info</th>
|
||||
<th scope="col">Update Button</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for atm in atms_list %}
|
||||
{% url 'atms_update' atm.id atm.bank_id as url_atm_update %}
|
||||
<tr data-atm-id="{{ branch.id }}">
|
||||
<td>{{ atm.id }}</td>
|
||||
<td>{{ atm.bank_id }}</td>
|
||||
<td>{{ atm.name }}</td>
|
||||
<td>
|
||||
<div class="popuptext">
|
||||
<ul>
|
||||
<li>Address:
|
||||
<ul>
|
||||
<li>line1: {{atm.address.line_1}}</li>
|
||||
<li>line2: {{atm.address.line_2}}</li>
|
||||
<li>line3: {{atm.address.line_3}}</li>
|
||||
<li>city: {{atm.address.city}}</li>
|
||||
<li>county: {{atm.address.county}}</li>
|
||||
<li>state: {{atm.address.state}}</li>
|
||||
<li>postcode: {{atm.address.postcode}}</li>
|
||||
<li>country_code: {{atm.address.country_code}}</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Location:
|
||||
<ul>
|
||||
<li>latitude: {{atm.location.latitude}}</li>
|
||||
<li>longitude: {{atm.location.longitude}}</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Meta License:
|
||||
<ul>
|
||||
<li>id: {{atm.meta.license.id}}</li>
|
||||
<li>name: {{atm.meta.license.name}}</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Branch Routing
|
||||
<ul>
|
||||
<li>Scheme: {{atm.atm_routing.scheme}}</li>
|
||||
<li>Address: {{atm.atm_routing.address}}</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>ATM Type: {{atm.branch_type}}</li>
|
||||
<li>More Info: {{atm.more_info}}</li>
|
||||
<li>Phone Number: {{atm.phone_number}}</li>
|
||||
<li>Accessible Features: {{atm.accessibleFeatures}}</li>
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
<td><a href="{{ url_branch_update }}" class="btn btn-primary">Update</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extrajs %}
|
||||
{% comment %}
|
||||
<script type="text/javascript" src="{% static 'branches/js/branches.js' %}"></script>
|
||||
<script type="text/javascript">
|
||||
</script>
|
||||
{% endcomment %}
|
||||
{% endblock extrajs %}
|
||||
|
||||
|
||||
{% block extracss %}
|
||||
<link href="{% static 'branches/css/branches.css' %}" rel="stylesheet">
|
||||
{% endblock extracss %}
|
||||
179
apimanager/atms/templates/atms/update.html
Normal file
179
apimanager/atms/templates/atms/update.html
Normal file
@ -0,0 +1,179 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load static %}
|
||||
|
||||
{% block page_title %}{{ block.super }} / Atms{% endblock page_title %}
|
||||
|
||||
{% block content %}
|
||||
<div id="branches">
|
||||
<h1>Update atm</h1>
|
||||
<h2>{{ bank_id }} : {{ atm_id }}</h2>
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{% if form.non_field_errors %}
|
||||
<div class="alert alert-danger">
|
||||
{{ form.non_field_errors }}
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="row" style="display: None">
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.bank_id.errors %}<div class="alert alert-danger">{{ form.bank_id.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.bank_id.label_tag }}
|
||||
{{ form.bank_id }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.atm_id.errors %}<div class="alert alert-danger">{{ form.atm_id.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.atm_id.label_tag }}
|
||||
{{ form.atm_id }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.name.errors %}<div class="alert alert-danger">{{ form.name.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.name.label_tag }}
|
||||
{{ form.name }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.location_latitude.errors %}<div class="alert alert-danger">{{ form.location_latitude.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.location_latitude.label_tag }}
|
||||
{{ form.location_latitude }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.location_longitude.errors %}<div class="alert alert-danger">{{ form.location_longitude.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.location_longitude.label_tag }}
|
||||
{{ form.location_longitude }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.meta_license_id.errors %}<div class="alert alert-danger">{{ form.meta_license_id.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.meta_license_id.label_tag }}
|
||||
{{ form.meta_license_id }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.meta_license_name.errors %}<div class="alert alert-danger">{{ form.meta_license_name.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.meta_license_name.label_tag }}
|
||||
{{ form.meta_license_name }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.accessibleFeatures.errors %}<div class="alert alert-danger">{{ form.accessibleFeatures.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.accessibleFeatures.label_tag }}
|
||||
{{ form.accessibleFeatures }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.atm_routing_scheme.errors %}<div class="alert alert-danger">{{ form.atm_routing_scheme.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.atm_routing_scheme.label_tag }}
|
||||
{{ form.atm_routing_scheme }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.atm_routing_address.errors %}<div class="alert alert-danger">{{ form.branch_routing_address.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.atm_routing_address.label_tag }}
|
||||
{{ form.atm_routing_address }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.is_accessible.errors %}<div class="alert alert-danger">{{ form.is_accessible.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.is_accessible.label_tag }}
|
||||
{{ form.is_accessible }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.atm_type.errors %}<div class="alert alert-danger">{{ form.atm_type.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.atm_type.label_tag }}
|
||||
{{ form.atm_type }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.more_info.errors %}<div class="alert alert-danger">{{ form.more_info.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.more_info.label_tag }}
|
||||
{{ form.more_info }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.phone_number.errors %}<div class="alert alert-danger">{{ form.phone_number.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.phone_number.label_tag }}
|
||||
{{ form.phone_number }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.address.errors %}<div class="alert alert-danger">{{ form.address.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.address.label_tag }}
|
||||
{{ form.address }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.lobby.errors %}<div class="alert alert-danger">{{ form.lobby.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.lobby.label_tag }}
|
||||
{{ form.lobby }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.drive_up.errors %}<div class="alert alert-danger">{{ form.drive_up.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.drive_up.label_tag }}
|
||||
{{ form.drive_up }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="submit" value="Update" class="btn btn-primary" />
|
||||
</form>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
||||
{% block extrajs %}
|
||||
{% comment %}
|
||||
<script type="text/javascript" src="{% static 'branches/js/branches.js' %}"></script>
|
||||
<script type="text/javascript">
|
||||
</script>
|
||||
{% endcomment %}
|
||||
{% endblock extrajs %}
|
||||
|
||||
|
||||
{% block extracss %}
|
||||
<link href="{% static 'branches/css/branches.css' %}" rel="stylesheet">
|
||||
{% endblock extracss %}
|
||||
|
||||
3
apimanager/atms/tests.py
Normal file
3
apimanager/atms/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
17
apimanager/atms/urls.py
Normal file
17
apimanager/atms/urls.py
Normal file
@ -0,0 +1,17 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
URLs for metrics app
|
||||
"""
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
from .views import IndexAtmView, UpdateAtmView
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$',
|
||||
IndexAtmView.as_view(),
|
||||
name='atms_list'),
|
||||
url(r'^update/(?P<atm_id>[0-9\w\@\.\+-]+)/bank/(?P<bank_id>[0-9\w\@\.\+-]+)/$',
|
||||
UpdateAtmView.as_view(),
|
||||
name='atms_update')
|
||||
]
|
||||
325
apimanager/atms/views.py
Normal file
325
apimanager/atms/views.py
Normal file
@ -0,0 +1,325 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Views of branches app
|
||||
"""
|
||||
|
||||
from django.contrib import messages
|
||||
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 CreateAtmForm
|
||||
|
||||
class IndexAtmView(LoginRequiredMixin, FormView):
|
||||
"""Index view for atm"""
|
||||
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)
|
||||
|
||||
def get_form(self, *args, **kwargs):
|
||||
form = super(IndexAtmView, self).get_form(*args, **kwargs)
|
||||
# Cannot add api in constructor: super complains about unknown kwarg
|
||||
form.api = self.api
|
||||
fields = form.fields
|
||||
try:
|
||||
fields['bank_id'].choices = self.api.get_bank_id_choices()
|
||||
fields['is_accessible'].choices = [('','Choose...'),(True, True), (False, False)]
|
||||
fields['drive_up'].initial = json.dumps({
|
||||
"monday": {
|
||||
"opening_time": "10:00",
|
||||
"closing_time": "18:00"
|
||||
},
|
||||
"tuesday": {
|
||||
"opening_time": "10:00",
|
||||
"closing_time": "18:00"
|
||||
},
|
||||
"wednesday": {
|
||||
"opening_time": "10:00",
|
||||
"closing_time": "18:00"
|
||||
},
|
||||
"thursday": {
|
||||
"opening_time": "10:00",
|
||||
"closing_time": "18:00"
|
||||
},
|
||||
"friday": {
|
||||
"opening_time": "10:00",
|
||||
"closing_time": "18:00"
|
||||
},
|
||||
"saturday": {
|
||||
"opening_time": "10:00",
|
||||
"closing_time": "18:00"
|
||||
},
|
||||
"sunday": {
|
||||
"opening_time": "10:00",
|
||||
"closing_time": "18:00"
|
||||
}
|
||||
}, indent=4)
|
||||
|
||||
fields['lobby'].initial = json.dumps({
|
||||
"monday": [
|
||||
{
|
||||
"opening_time": "10:00",
|
||||
"closing_time": "18:00"
|
||||
}
|
||||
],
|
||||
"tuesday": [
|
||||
{
|
||||
"opening_time": "10:00",
|
||||
"closing_time": "18:00"
|
||||
}
|
||||
],
|
||||
"wednesday": [
|
||||
{
|
||||
"opening_time": "10:00",
|
||||
"closing_time": "18:00"
|
||||
}
|
||||
],
|
||||
"thursday": [
|
||||
{
|
||||
"opening_time": "10:00",
|
||||
"closing_time": "18:00"
|
||||
}
|
||||
],
|
||||
"friday": [
|
||||
{
|
||||
"opening_time": "10:00",
|
||||
"closing_time": "18:00"
|
||||
}
|
||||
],
|
||||
"saturday": [
|
||||
{
|
||||
"opening_time": "10:00",
|
||||
"closing_time": "18:00"
|
||||
}
|
||||
],
|
||||
"sunday": [
|
||||
{
|
||||
"opening_time": "10:00",
|
||||
"closing_time": "18:00"
|
||||
}
|
||||
]
|
||||
}, indent=4)
|
||||
|
||||
fields['address'].initial = json.dumps({
|
||||
"line_1":"No 1 the Road",
|
||||
"line_2":"The Place",
|
||||
"line_3":"The Hill",
|
||||
"city":"Berlin",
|
||||
"county":"String",
|
||||
"state":"Brandenburg",
|
||||
"postcode":"13359",
|
||||
"country_code":"DE"
|
||||
}, indent=4)
|
||||
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
except:
|
||||
messages.error(self.request, "Unknown Error")
|
||||
|
||||
return form
|
||||
|
||||
def form_valid(self, form):
|
||||
try:
|
||||
data = form.cleaned_data
|
||||
urlpath = '/banks/{}/atms'.format(data['bank_id'])
|
||||
payload = {
|
||||
"id": data["atm_id"],
|
||||
"bank_id": data["bank_id"],
|
||||
"name": data["name"],
|
||||
"address": json.loads(data['address']),
|
||||
"location": {
|
||||
"latitude": float(data["location_latitude"]) if data["location_latitude"] is not None else 37.0,
|
||||
"longitude": float(data["location_longitude"]) if data["location_longitude"] is not None else 110.0
|
||||
},
|
||||
"meta": {
|
||||
"license": {
|
||||
"id": "PDDL",
|
||||
"name": data["meta_license_name"] if data["meta_license_name"]!="" else "license name"
|
||||
}
|
||||
},
|
||||
"lobby": json.loads(data['lobby']),
|
||||
"drive_up": json.loads(data["drive_up"]),
|
||||
"branch_routing": {
|
||||
"scheme": data["branch_routing_scheme"] if data["branch_routing_scheme"]!="" else "license name",
|
||||
"address": data["branch_routing_address"] if data["branch_routing_address"]!="" else "license name"
|
||||
},
|
||||
"is_accessible": data["is_accessible"] if data["is_accessible"]!="" else "false",
|
||||
"accessibleFeatures": data["accessibleFeatures"] if data["accessibleFeatures"]!="" else "accessible features name",
|
||||
"branch_type": data["branch_type"] if data["branch_type"]!="" else "branch type",
|
||||
"more_info": data["more_info"] if data["more_info"]!="" else "more info",
|
||||
"phone_number": data["phone_number"] if data["phone_number"]!="" else "phone number"
|
||||
}
|
||||
result = self.api.post(urlpath, payload=payload)
|
||||
except APIError as err:
|
||||
error_once_only(self.request, err)
|
||||
return super(IndexAtmView, self).form_invalid(form)
|
||||
except Exception as err:
|
||||
error_once_only(self.request, "Unknown Error")
|
||||
return super(IndexAtmViewView, 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.success(self.request, msg)
|
||||
return super(IndexAtmView, 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_atms(self, context):
|
||||
|
||||
api = API(self.request.session.get('obp'))
|
||||
try:
|
||||
self.bankids = self.get_banks()
|
||||
atms_list = []
|
||||
for bank_id in self.bankids:
|
||||
urlpath = '/banks/{}/atms'.format(bank_id)
|
||||
|
||||
result = api.get(urlpath)
|
||||
if 'atms' in result:
|
||||
atms_list.extend(result['atms'])
|
||||
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 atms_list
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(IndexAtmView, self).get_context_data(**kwargs)
|
||||
atms_list = self.get_atms(context)
|
||||
context.update({
|
||||
'atms_list': atms_list,
|
||||
'bankids': self.bankids
|
||||
})
|
||||
return context
|
||||
|
||||
|
||||
class UpdateAtmView(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)
|
||||
|
||||
def get_form(self, *args, **kwargs):
|
||||
form = super(UpdateAtmView, self).get_form(*args, **kwargs)
|
||||
# Cannot add api in constructor: super complains about unknown kwarg
|
||||
form.api = self.api
|
||||
fields = form.fields
|
||||
urlpath = "/banks/{}/atms/{}".format(self.kwargs['bank_id'], self.kwargs['atm_id'])
|
||||
try:
|
||||
fields['bank_id'].choices = self.api.get_bank_id_choices()
|
||||
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
except:
|
||||
messages.error(self.request, "Unknown Error")
|
||||
try:
|
||||
result = self.api.get(urlpath)
|
||||
fields['bank_id'].initial = self.kwargs['bank_id']
|
||||
fields['atm_id'].initial = self.kwargs['atm_id']
|
||||
fields['name'].initial = result['name']
|
||||
fields['address'].initial = json.dumps(result['address'], indent=4)
|
||||
fields['location_latitude'].initial = result['location']['latitude']
|
||||
fields['location_longitude'].initial = result['location']['longitude']
|
||||
fields['meta_license_id'].initial = result['meta']['license']['id']
|
||||
fields['meta_license_name'].initial = result['meta']['license']['name']
|
||||
fields['atm_routing_scheme'].initial = result['atm_routing']['scheme']
|
||||
fields['atm_routing_address'].initial = result['atm_routing']['address']
|
||||
if result['is_accessible'].lower()=='true':
|
||||
fields['is_accessible'].choices = [(True, True), (False, False)]
|
||||
else:
|
||||
fields['is_accessible'].choices = [(False, False), (True, True)]
|
||||
fields['accessibleFeatures'].initial = result['accessibleFeatures']
|
||||
fields['atm_type'].initial = result['atm_type']
|
||||
fields['more_info'].initial = result['more_info']
|
||||
fields['phone_number'].initial = result['phone_number']
|
||||
fields['lobby'].initial = json.dumps(result['lobby'], indent=4)
|
||||
fields['drive_up'].initial = json.dumps(result['drive_up'], indent=4)
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
except Exception as err:
|
||||
messages.error(self.request, "Unknown Error {}".format(err))
|
||||
|
||||
return form
|
||||
|
||||
def form_valid(self, form):
|
||||
data = form.cleaned_data
|
||||
urlpath = '/banks/{}/atms/{}'.format(data["bank_id"], data["atm_id"])
|
||||
payload = {
|
||||
#"id": data["branch_id"],
|
||||
"bank_id": data["bank_id"],
|
||||
"name": data["name"],
|
||||
"address": json.loads(data['address']),
|
||||
"location": {
|
||||
"latitude": float(data["location_latitude"]),
|
||||
"longitude": float(data["location_longitude"])
|
||||
},
|
||||
"meta": {
|
||||
"license": {
|
||||
"id": data["meta_license_id"],
|
||||
"name": data["meta_license_name"]
|
||||
}
|
||||
},
|
||||
"lobby": json.loads(data["lobby"]),
|
||||
"drive_up": json.loads(data["drive_up"]),
|
||||
"branch_routing": {
|
||||
"scheme": data["atm_routing_scheme"] if data["atm_routing_scheme"] != "" else "license name",
|
||||
"address": data["atm_routing_address"] if data["atm_routing_address"] != "" else "license name"
|
||||
},
|
||||
"is_accessible": data["is_accessible"],
|
||||
"accessibleFeatures": data["accessibleFeatures"],
|
||||
"atm_type": data["atm_type"],
|
||||
"more_info": data["more_info"],
|
||||
"phone_number": data["phone_number"]
|
||||
}
|
||||
try:
|
||||
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)
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
return super(UpdateAtmView, self).form_invalid(form)
|
||||
except:
|
||||
messages.error(self.request, "Unknown Error")
|
||||
return super(UpdateAtmView, 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)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(UpdateAtmView, self).get_context_data(**kwargs)
|
||||
self.bank_id = self.kwargs['bank_id']
|
||||
self.atm_id = self.kwargs['atm_id']
|
||||
context.update({
|
||||
'atm_id': self.atm_id,
|
||||
'bank_id': self.bank_id
|
||||
})
|
||||
return context
|
||||
@ -73,11 +73,13 @@
|
||||
</li>
|
||||
{% url "branches_list" as branches_list_url %}
|
||||
{% url "customers-create" as customers_create_url %}
|
||||
{% url "atms_list" as atms_list_url %}
|
||||
<li class="dropdown{% if customers_create_url in request.path %} active{% endif %}">
|
||||
<a href="#" data-toggle="dropdown" class="dropdown-toggle">Resources</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li{% if customers_create_url in request.path %} class="active"{% endif %}><a href="{{ customers_create_url }}">Customers</a></li><hr class="dropdown-hr">
|
||||
<li{% if branches_list_url in request.path %} class="active"{% endif %}><a href="{{ branches_list_url }}">Branches</a></li>
|
||||
<li{% if atms_list_url in request.path %} class="active"{% endif %}><a href="{{ atms_list_url }}">ATMs</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
{% url "config-index" as config_index_url %}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user