From 739c44da62b1474de5e7e245df240114e8291e72 Mon Sep 17 00:00:00 2001 From: PengfeiLi0218 Date: Fri, 8 Feb 2019 12:35:51 +0800 Subject: [PATCH] Add Branches page #75 verify should come from settings and default to true #78 --- apimanager/apimanager/settings.py | 1 + apimanager/apimanager/urls.py | 1 + apimanager/base/templates/base.html | 2 + apimanager/branches/forms.py | 268 ++++++++++++++++++ .../branches/static/branches/css/branches.css | 18 ++ .../branches/static/branches/js/branches.js | 5 + .../branches/templates/branches/index.html | 215 ++++++++++++++ .../branches/templates/branches/update.html | 167 +++++++++++ apimanager/branches/urls.py | 17 ++ apimanager/users/apps.py | 6 +- apimanager/users/views.py | 18 +- 11 files changed, 706 insertions(+), 12 deletions(-) create mode 100644 apimanager/branches/forms.py create mode 100644 apimanager/branches/static/branches/css/branches.css create mode 100644 apimanager/branches/static/branches/js/branches.js create mode 100644 apimanager/branches/templates/branches/index.html create mode 100644 apimanager/branches/templates/branches/update.html create mode 100644 apimanager/branches/urls.py diff --git a/apimanager/apimanager/settings.py b/apimanager/apimanager/settings.py index 45bb09c..d21d1d6 100644 --- a/apimanager/apimanager/settings.py +++ b/apimanager/apimanager/settings.py @@ -51,6 +51,7 @@ INSTALLED_APPS = [ 'obp', 'consumers', 'users', + 'branches', 'entitlementrequests', 'customers', 'metrics', diff --git a/apimanager/apimanager/urls.py b/apimanager/apimanager/urls.py index ea199bf..1d0da46 100644 --- a/apimanager/apimanager/urls.py +++ b/apimanager/apimanager/urls.py @@ -31,6 +31,7 @@ urlpatterns = [ url(r'^consumers/', include('consumers.urls')), url(r'^entitlementrequests/', include('entitlementrequests.urls')), url(r'^users/', include('users.urls')), + url(r'^branches/', include('branches.urls')), url(r'^customers/', include('customers.urls')), url(r'^metrics/', include('metrics.urls')), url(r'^config/', include('config.urls')), diff --git a/apimanager/base/templates/base.html b/apimanager/base/templates/base.html index 5bee771..aa46c6e 100644 --- a/apimanager/base/templates/base.html +++ b/apimanager/base/templates/base.html @@ -51,11 +51,13 @@ KPI Dashboard + {% url "branches_list" as branches_list_url %} {% url "customers-create" as customers_create_url %} {% url "config-index" as config_index_url %} diff --git a/apimanager/branches/forms.py b/apimanager/branches/forms.py new file mode 100644 index 0000000..7c55299 --- /dev/null +++ b/apimanager/branches/forms.py @@ -0,0 +1,268 @@ +""" +Forms of branches app +""" + +from django import forms + +import random + + +class CreateBranchForm(forms.Form): + + branch_id = forms.CharField( + label='Branch Id', + widget=forms.TextInput( + attrs={ + 'placeholder': 'branch-id-{}'.format(random.randint(1,1000)), + 'class': 'form-control', + } + ), + initial='branch-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_line1 = forms.CharField( + label='address_line1', + widget=forms.TextInput( + attrs={ + 'placeholder': 'No 1 the Road', + 'class': 'form-control', + } + ), + required=False + ) + + address_line2 = forms.CharField( + label='address_line2', + widget=forms.TextInput( + attrs={ + 'placeholder': 'The Place', + 'class': 'form-control', + } + ), + required=False + ) + + address_line3 = forms.CharField( + label='address_line3', + widget=forms.TextInput( + attrs={ + 'placeholder': 'The Hill', + 'class': 'form-control', + } + ), + required=False + ) + + address_city = forms.CharField( + label='city', + widget=forms.TextInput( + attrs={ + 'placeholder': 'Berlin', + 'class': 'form-control', + } + ), + required=False + ) + + address_county = forms.CharField( + label='county', + widget=forms.TextInput( + attrs={ + 'placeholder': 'String', + 'class': 'form-control', + } + ), + required=False + ) + + address_state = forms.CharField( + label='state', + widget=forms.TextInput( + attrs={ + 'placeholder': 'Brandenburg', + 'class': 'form-control', + } + ), + required=False + ) + + address_postcode = forms.CharField( + label='state', + widget=forms.TextInput( + attrs={ + 'placeholder': '13359', + 'class': 'form-control', + } + ), + required=False + ) + + address_country_code = forms.CharField( + label='country_code', + widget=forms.TextInput( + attrs={ + 'placeholder': 'DE', + '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', + widget=forms.TextInput( + attrs={ + 'placeholder': 'None', + 'class': 'form-control', + } + ), + required=False, + ) + drive_up = forms.CharField( + label='Drive Up', + widget=forms.TextInput( + attrs={ + 'placeholder': 'None', # noqa + 'class': 'form-control', + } + ), + required=False, + ) + branch_routing_scheme = forms.CharField( + label='Branch Routing Scheme', + widget=forms.TextInput( + attrs={ + 'placeholder': 'OBP', + 'class': 'form-control', + } + ), + required=False, + ) + branch_routing_address = forms.CharField( + label='Branch Routing Address', + widget=forms.TextInput( + attrs={ + 'placeholder': '123abc', + 'class': 'form-control', + } + ), + required=False, + ) + is_accessible = forms.CharField( + label='is accessible', + widget=forms.TextInput( + attrs={ + 'placeholder': 'true', + '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, + ) + branch_type = forms.CharField( + label='Branch 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(CreateBranchForm, self).__init__(*args, **kwargs) diff --git a/apimanager/branches/static/branches/css/branches.css b/apimanager/branches/static/branches/css/branches.css new file mode 100644 index 0000000..78d5370 --- /dev/null +++ b/apimanager/branches/static/branches/css/branches.css @@ -0,0 +1,18 @@ +#branches_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; +} diff --git a/apimanager/branches/static/branches/js/branches.js b/apimanager/branches/static/branches/js/branches.js new file mode 100644 index 0000000..338fe9e --- /dev/null +++ b/apimanager/branches/static/branches/js/branches.js @@ -0,0 +1,5 @@ +$(document).ready(function($) { + $('#info').click(function() { + alert("Hello World") + }); +}); diff --git a/apimanager/branches/templates/branches/index.html b/apimanager/branches/templates/branches/index.html new file mode 100644 index 0000000..55f473f --- /dev/null +++ b/apimanager/branches/templates/branches/index.html @@ -0,0 +1,215 @@ +{% extends 'base.html' %} +{% load static %} + +{% block page_title %}{{ block.super }} / Branches{% endblock page_title %} + +{% block content %} +
+

Branches

+ +
+ {% csrf_token %} + {% if form.non_field_errors %} +
+ {{ form.non_field_errors }} +
+ {% endif %} + +
+
+ {% if form.branch_id.errors %}
{{ form.branch_id.errors }}
{% endif %} +
+ {{ form.branch_id.label_tag }} + {{ form.branch_id }} +
+
+
+ {% if form.bank_id.errors %}
{{ form.bank_id.errors }}
{% endif %} +
+ {{ form.bank_id.label_tag }} + {{ form.bank_id }} +
+
+
+ {% if form.name.errors %}
{{ form.name.errors }}
{% endif %} +
+ {{ form.name.label_tag }} + {{ form.name }} +
+
+
+ +
+
+ {% if form.address_city.errors %}
{{ form.address_city.errors }}
{% endif %} +
+ {{ form.address_city.label_tag }} + {{ form.address_city }} +
+
+
+ {% if form.location_latitude.errors %}
{{ form.location_latitude.errors }}
{% endif %} +
+ {{ form.location_latitude.label_tag }} + {{ form.location_latitude }} +
+
+
+ {% if form.location_longitude.errors %}
{{ form.location_longitude.errors }}
{% endif %} +
+ {{ form.location_longitude.label_tag }} + {{ form.location_longitude }} +
+
+
+ +
+
+ {% if form.meta_license_name.errors %}
{{ form.meta_license_name.errors }}
{% endif %} +
+ {{ form.meta_license_name.label_tag }} + {{ form.meta_license_name }} +
+
+
+ {% if form.branch_routing_scheme.errors %}
{{ form.branch_routing_scheme.errors }}
{% endif %} +
+ {{ form.branch_routing_scheme.label_tag }} + {{ form.branch_routing_scheme }} +
+
+
+ {% if form.branch_routing_address.errors %}
{{ form.branch_routing_address.errors }}
{% endif %} +
+ {{ form.branch_routing_address.label_tag }} + {{ form.branch_routing_address }} +
+
+
+ +
+
+ {% if form.is_accessible.errors %}
{{ form.is_accessible.errors }}
{% endif %} +
+ {{ form.is_accessible.label_tag }} + {{ form.is_accessible }} +
+
+
+ {% if form.accessibleFeatures.errors %}
{{ form.accessibleFeatures.errors }}
{% endif %} +
+ {{ form.accessibleFeatures.label_tag }} + {{ form.accessibleFeatures }} +
+
+
+ {% if form.branch_type.errors %}
{{ form.branch_type.errors }}
{% endif %} +
+ {{ form.branch_type.label_tag }} + {{ form.branch_type }} +
+
+
+ +
+
+ {% if form.more_info.errors %}
{{ form.more_info.errors }}
{% endif %} +
+ {{ form.more_info.label_tag }} + {{ form.more_info }} +
+
+
+ {% if form.phone_number.errors %}
{{ form.phone_number.errors }}
{% endif %} +
+ {{ form.phone_number.label_tag }} + {{ form.phone_number }} +
+
+
+ +
+ +
+
+ +
+ + + + + + + + + + {% for branch in branches_list %} + {% url 'branches_update' branch.id branch.bank_id as url_branch_update %} + + + + + + + + {% endfor %} + +
Branch IdBank IdBranch NameMore_infoUpdate Button
{{ branch.id }}{{ branch.bank_id }}{{ branch.name }} +
+
    +
  • Address: +
      +
    • line1: {{branch.address.line_1}}
    • +
    • line2: {{branch.address.line_2}}
    • +
    • line3: {{branch.address.line_3}}
    • +
    • city: {{branch.address.city}}
    • +
    • county: {{branch.address.county}}
    • +
    • state: {{branch.address.state}}
    • +
    • postcode: {{branch.address.postcode}}
    • +
    • country_code: {{branch.address.country_code}}
    • +
    +
  • +
  • Location: +
      +
    • latitude: {{branch.location.latitude}}
    • +
    • longitude: {{branch.location.longitude}}
    • +
    +
  • +
  • Meta License: +
      +
    • id: {{branch.meta.license.id}}
    • +
    • name: {{branch.meta.license.name}}
    • +
    +
  • +
  • Branch Routing +
      +
    • Scheme: {{branch.branch_routing.scheme}}
    • +
    • Address: {{branch.branch_routing.address}}
    • +
    +
  • +
  • Branch Type: {{branch.branch_type}}
  • +
  • More Info: {{branch.more_info}}
  • +
  • Phone Number: {{branch.phone_number}}
  • +
+
+
Update
+
+
+{% endblock %} + +{% block extrajs %} +{% comment %} + + +{% endcomment %} +{% endblock extrajs %} + + +{% block extracss %} + +{% endblock extracss %} diff --git a/apimanager/branches/templates/branches/update.html b/apimanager/branches/templates/branches/update.html new file mode 100644 index 0000000..e2cf040 --- /dev/null +++ b/apimanager/branches/templates/branches/update.html @@ -0,0 +1,167 @@ +{% extends 'base.html' %} +{% load static %} + +{% block page_title %}{{ block.super }} / Branches{% endblock page_title %} + +{% block content %} +
+

Update Branch

+

{{ bank_id }} : {{ branch_id }}

+
+ {% csrf_token %} + {% if form.non_field_errors %} +
+ {{ form.non_field_errors }} +
+ {% endif %} + + +
+
+ {% if form.name.errors %}
{{ form.name.errors }}
{% endif %} +
+ {{ form.name.label_tag }} + {{ form.name }} +
+
+
+ {% if form.address_line1.errors %}
{{ form.address_line1.errors }}
{% endif %} +
+ {{ form.address_line1.label_tag }} + {{ form.address_line1 }} +
+
+
+ {% if form.address_line2.errors %}
{{ form.address_line2.errors }}
{% endif %} +
+ {{ form.address_line2.label_tag }} + {{ form.address_line2 }} +
+
+
+ +
+
+ {% if form.address_line3.errors %}
{{ form.address_line3.errors }}
{% endif %} +
+ {{ form.address_line3.label_tag }} + {{ form.address_line3 }} +
+
+
+ {% if form.address_city.errors %}
{{ form.address_city.errors }}
{% endif %} +
+ {{ form.address_city.label_tag }} + {{ form.address_city }} +
+
+ +
+ {% if form.address_state.errors %}
{{ form.address_state.errors }}
{% endif %} +
+ {{ form.address_state.label_tag }} + {{ form.address_state }} +
+
+
+ +
+
+ {% if form.address_postcode.errors %}
{{ form.address_postcode.errors }}
{% endif %} +
+ {{ form.address_postcode.label_tag }} + {{ form.address_postcode }} +
+
+
+ {% if form.address_country_code.errors %}
{{ form.address_country_code.errors }}
{% endif %} +
+ {{ form.address_country_code.label_tag }} + {{ form.address_country_code }} +
+
+
+ {% if form.location_latitude.errors %}
{{ form.location_latitude.errors }}
{% endif %} +
+ {{ form.location_latitude.label_tag }} + {{ form.location_latitude }} +
+
+
+ +
+ +
+ {% if form.location_longitude.errors %}
{{ form.location_longitude.errors }}
{% endif %} +
+ {{ form.location_longitude.label_tag }} + {{ form.location_longitude }} +
+
+
+ {% if form.meta_license_id.errors %}
{{ form.meta_license_id.errors }}
{% endif %} +
+ {{ form.meta_license_id.label_tag }} + {{ form.meta_license_id }} +
+
+
+ {% if form.meta_license_name.errors %}
{{ form.meta_license_name.errors }}
{% endif %} +
+ {{ form.meta_license_name.label_tag }} + {{ form.meta_license_name }} +
+
+
+ +
+
+ {% if form.lobby.errors %}
{{ form.lobby.errors }}
{% endif %} +
+ {{ form.lobby.label_tag }} + {{ form.lobby }} +
+
+ +
+ {% if form.drive_up.errors %}
{{ form.drive_up.errors }}
{% endif %} +
+ {{ form.drive_up.label_tag }} + {{ form.drive_up }} +
+
+
+ + +
+
+{% endblock content %} + +{% block extrajs %} +{% comment %} + + +{% endcomment %} +{% endblock extrajs %} + + +{% block extracss %} + +{% endblock extracss %} + diff --git a/apimanager/branches/urls.py b/apimanager/branches/urls.py new file mode 100644 index 0000000..11f3ebc --- /dev/null +++ b/apimanager/branches/urls.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +""" +URLs for metrics app +""" + +from django.conf.urls import url + +from .views import IndexBranchesView, UpdateBranchesView + +urlpatterns = [ + url(r'^$', + IndexBranchesView.as_view(), + name='branches_list'), + url(r'^update/(?P[0-9\w\@\.\+-]+)/bank/(?P[0-9\w\@\.\+-]+)/$', + UpdateBranchesView.as_view(), + name='branches_update') +] diff --git a/apimanager/users/apps.py b/apimanager/users/apps.py index f79ed4e..2515a20 100644 --- a/apimanager/users/apps.py +++ b/apimanager/users/apps.py @@ -6,6 +6,6 @@ App config for users app from django.apps import AppConfig -class UsersConfig(AppConfig): - """Config for users""" - name = 'users' +class BranchesConfig(AppConfig): + """Config for branches""" + name = 'branches' diff --git a/apimanager/users/views.py b/apimanager/users/views.py index 97f447a..b2078e7 100644 --- a/apimanager/users/views.py +++ b/apimanager/users/views.py @@ -56,7 +56,7 @@ class IndexView(LoginRequiredMixin, TemplateView): try: urlpath = '/entitlements' entitlements = api.get(urlpath) - if 'code' in entitlements and entitlements['code']==400: + if 'code' in entitlements and entitlements['code']>=400: messages.error(self.request, entitlements['message']) else: for entitlement in entitlements['list']: @@ -166,7 +166,7 @@ class DetailView(LoginRequiredMixin, FormView): try: urlpath = '/users/user_id/{}'.format(self.kwargs['user_id']) user = self.api.get(urlpath) - if 'code' in user and user['code']==403: + if 'code' in user and user['code']>=400: messages.error(self.request, user['message']) else: context['form'].fields['user_id'].initial = user['user_id'] @@ -210,17 +210,17 @@ class MyDetailView(LoginRequiredMixin, FormView): 'role_name': data['role_name'], } entitlement = self.api.post(urlpath, payload=payload) - if entitlement['code']==201: + if 'code' in entitlement and entitlement['code'] >= 400: + messages.error(self.request, entitlement['message']) + else: msg = 'Entitlement with role {} has been added.'.format(entitlement['role_name']) messages.success(self.request, msg) - else: - messages.error(self.request, entitlement['message']) self.success_url = self.request.path except APIError as err: messages.error(self.request, err) return super(MyDetailView, self).form_invalid(form) - except: - messages.error(self.request, 'Unknown Error') + except Exception as err: + messages.error(self.request, 'Unknown Error. {}'.format(err)) return super(MyDetailView, self).form_invalid(form) else: return super(MyDetailView, self).form_valid(form) @@ -236,7 +236,7 @@ class MyDetailView(LoginRequiredMixin, FormView): context['form'].fields['user_id'].initial = user['user_id'] except APIError as err: messages.error(self.request, err) - except: + except Exception as err: messages.error(self.request, 'Unknown Error') context.update({ @@ -255,7 +255,7 @@ class DeleteEntitlementView(LoginRequiredMixin, View): urlpath = '/users/{}/entitlement/{}'.format( kwargs['user_id'], kwargs['entitlement_id']) result = api.delete(urlpath) - if result is not None and 'code' in result and result['code']==400: + if result is not None and 'code' in result and result['code']>=400: messages.error(request, result['message']) else: msg = 'Entitlement with role {} has been deleted.'.format(