From dbfc48da165d8559937030e7a6c69d8ecc4a94c5 Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Mon, 24 Oct 2022 15:16:26 +0200 Subject: [PATCH] Correction in Account Page --- .../accounts/templates/accounts/update.html | 162 ----------------- apimanager/accounts/urls.py | 8 +- apimanager/accounts/views.py | 171 ------------------ 3 files changed, 3 insertions(+), 338 deletions(-) delete mode 100644 apimanager/accounts/templates/accounts/update.html diff --git a/apimanager/accounts/templates/accounts/update.html b/apimanager/accounts/templates/accounts/update.html deleted file mode 100644 index 5fc17bc..0000000 --- a/apimanager/accounts/templates/accounts/update.html +++ /dev/null @@ -1,162 +0,0 @@ -{% extends 'base.html' %} {% load static %} {% load i18n %} {% block page_title %}{{ block.super }} / Account{% endblock page_title %} {% block content %} -
-

{% trans "Account Create" %}

- -
- {% csrf_token %} {% if form.non_field_errors %} -
{{ form.non_field_errors }}
- {% endif %} -
-
- {% if form.account_id.errors %} -
{{ form.account_id.errors }}
- {% endif %} -
- {{ form.account_id.label_tag }} {{ form.account_id }} -
-
-
- {% if form.user_id.errors %} -
{{ form.user_id.errors }}
- {% endif %} -
- {{ form.user_id.label_tag }} {{ form.user_id }} -
-
-
- {% if form.label.errors %} -
{{ form.label.errors }}
- {% endif %} -
- {{ form.label.label_tag }} {{ form.label }} -
-
-
-
-
- {% if form.product_code.errors %} -
- {{ form.product_code.errors }} -
- {% endif %} -
- {{ form.product_code.label_tag }} {{ form.product_code }} -
-
-
- {% if form.balance_currency.errors %} -
- {{ form.balance_currency.errors }} -
- {% endif %} -
- {{ form.balance_currency.label_tag }} {{ form.balance_currency }} -
-
-
- {% if form.balance_amount.errors %} -
- {{ form.balance_amount.errors }} -
- {% endif %} -
- {{ form.balance_amount.label_tag }} {{ form.balance_amount }} -
-
-
-
-
- {% if form.branch_id.errors %} -
{{ form.branch_id.errors }}
- {% endif %} -
- {{ form.branch_id.label_tag }} {{ form.branch_id }} -
-
-
- {% if form.account_routings_scheme.errors %} -
- {{ form.account_routings_scheme.errors }} -
- {% endif %} -
- {{ form.account_routings_scheme.label_tag }} {{ form.account_routings_scheme }} -
-
-
- {% if form.account_routings_address.errors %} -
{{ form.account_routings_address.errors }}
- {% endif %} -
- {{ form.account_routings_address.label_tag }} {{ form.account_routings_address }} -
-
-
-
-
- {% if form.account_attributes_product_code.errors %} -
- {{ form.account_attributes_product_code.errors }} -
- {% endif %} -
- {{ form.account_attributes_product_code.label_tag }} {{ form.account_attributes_product_code }} -
-
-
- {% if form.account_attributes_id.errors %} -
{{ form.account_attributes_id.errors }}
- {% endif %} -
- {{ form.account_attributes_id.label_tag }} {{ form.account_attributes_id }} -
-
-
- {% if form.account_attributes_name.errors %} -
{{ form.account_attributes_name.errors }}
- {% endif %} -
- {{ form.account_attributes_name.label_tag }} {{ form.account_attributes_name }} -
-
-
-
-
- {% if form.bank_id.errors %} -
{{ form.bank_id.errors }}
- {% endif %} -
- {{ form.bank_id.label_tag }} {{ form.bank_id }} -
-
-
- {% if form.account_attributes_value.errors %} -
- {{ form.account_attributes_value.errors }} -
- {% endif %} -
- {{ form.account_attributes_value.label_tag }} {{ form.account_attributes_value }} -
-
-
- {% if form.account_attributes_instance_code.errors %} -
- {{ form.account_attributes_instance_code.errors }} -
- {% endif %} -
- {{ form.account_attributes_instance_code.label_tag }} {{ form.account_attributes_instance_code }} -
-
-
- -
-
- - -{% endblock content %} {% block extrajs %} {% comment %} - -{% endcomment %} {% endblock extrajs %} {% block extracss %} - {% endblock extracss %} - diff --git a/apimanager/accounts/urls.py b/apimanager/accounts/urls.py index 7880cfd..1b49947 100644 --- a/apimanager/accounts/urls.py +++ b/apimanager/accounts/urls.py @@ -1,16 +1,14 @@ # -*- coding: utf-8 -*- """ -URLs for metrics app +URLs for Account app """ from django.conf.urls import url -from .views import IndexAccountsView, UpdateAccountsView +from .views import IndexAccountsView urlpatterns = [ url(r'^create', IndexAccountsView.as_view(), name='accounts-create'), - url(r'^update/(?P[ 0-9\w|\W\@\.\+-]+)/bank/(?P[0-9\w\@\.\+-]+)/$', - UpdateAccountsView.as_view(), - name='accounts_update'), + ] diff --git a/apimanager/accounts/views.py b/apimanager/accounts/views.py index 16c55a7..a8bb57d 100644 --- a/apimanager/accounts/views.py +++ b/apimanager/accounts/views.py @@ -69,174 +69,3 @@ class IndexAccountsView(LoginRequiredMixin, FormView): msg = 'Account has been created successfully!' messages.success(self.request, msg) return super(IndexAccountsView, self).form_valid(form) - -class UpdateAccountsView(LoginRequiredMixin, FormView): - template_name = "accounts/update.html" - success_url = '/accounts/list' - form_class = CreateAccountForm - - def dispatch(self, request, *args, **kwargs): - self.api = API(request.session.get('obp')) - return super(UpdateAccountsView, self).dispatch(request, *args, **kwargs) - - def get_form(self, *args, **kwargs): - form = super(UpdateAccountsView, 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['minimum_withdrawal'].initial = result['minimum_withdrawal'] - fields['branch_identification'].initial = result['branch_identification'] - if result['is_accessible'].lower()=='true': - fields['is_accessible'].choices = [(True, True), (False, False)] - else: - fields['is_accessible'].choices = [(False, False), (True, True)] - if result['has_deposit_capability'].lower()=='true': - fields['has_deposit_capability'].choices = [(True, True), (False, False)] - else: - fields['has_deposit_capability'].choices = [(False, False), (True, True)] - fields['has_deposit_capability'].initial = result['accessibility_features'] - fields['site_identification'].initial = result['site_identification'] - fields['site_name'].initial = result['site_name'] - fields['cash_withdrawal_national_fee'].initial = result['cash_withdrawal_national_fee'] - fields['cash_withdrawal_international_fee'].initial = result['cash_withdrawal_international_fee'] - fields['balance_inquiry_fee'].initial = result['balance_inquiry_fee'] - fields['services'].initial = result['services'] - fields['located_at'].initial = result['located_at'] - fields['more_info'].initial = result['more_info'] - fields['located_at'].initial = result['located_at'] - if result['supported_languages'][0].lower()=='en': - fields['supported_languages'].choices = [("en", "en"), ("fr", "fr"), ("de", "de")] - elif result['supported_languages'][0].lower()=='fr': - fields['supported_languages'].choices = [("fr", "fr"), ("en", "en"), ("de", "de")] - else: - fields['supported_languages'].choices = [("de", "de"),("fr", "fr"), ("en", "en")] - fields['supported_languages'].initial = result['supported_languages'] - if result['supported_currencies'][0].lower()=='EUR': - fields['supported_currencies'].choices = [("EUR", "EUR"), ("MXN", "MXN"), ("USD", "USD")] - elif result['supported_currencies'][0].lower()=='MXN': - fields['supported_currencies'].choices = [("MXN", "MXN"), ("EUR", "EUR"), ("USD", "USD")] - else: - fields['supported_currencies'].choices = [("USD", "USD"),("MXN", "MXN"), ("EUR", "EUR")] - fields['supported_currencies'].initial = result['supported_currencies'] - if result['notes'][0].lower()=='string1': - fields['notes'].choices = [("String1", "String1"),("String2", "String2")] - else: - fields['notes'].choices = [("String2", "String2"),("String1", "String1")] - fields['notes'].initial = result['notes'] - if result['location_categories'][0].lower()=='atbi': - fields['location_categories'].choices = [("ATBI", "ATBI"),("ATBE", "ATBE")] - else: - fields['location_categories'].choices = [("ATBE", "ATBE"),("ATBI", "ATBI")] - fields['location_categories'].initial = result['location_categories'] - 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["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 "", - "longitude": float(data["location_longitude"]) if data["location_longitude"] is not None else "" - }, - "meta": { - "license": { - "id": "ODbL-1.0", - "name": data["meta_license_name"] if data["meta_license_name"]!="" else "license name" - } - }, - "monday": { - "opening_time": " ", - "closing_time": " " - }, - "tuesday": { - "opening_time": " ", - "closing_time": " " - }, - "wednesday": { - "opening_time": " ", - "closing_time": " " - }, - "thursday": { - "opening_time": " ", - "closing_time": " " - }, - "friday": { - "opening_time": " ", - "closing_time": " " - }, - "saturday": { - "opening_time": " ", - "closing_time": " " - }, - "sunday": { - "opening_time": " ", - "closing_time": " " - }, - "is_accessible": data["is_accessible"] if data["is_accessible"]!="" else "false", - "located_at": data["located_at"] if data["located_at"]!="no-example-provided" else " ", - "more_info": data["more_info"] if data["more_info"]!="" else "false", - "has_deposit_capability": data["has_deposit_capability"] if data["has_deposit_capability"]!="" else "false", - "supported_languages":[data["supported_languages"]], - "services":[data["services"]], - "accessibility_features":[data["accessibility_features"]], - "supported_currencies":[data["supported_currencies"]], - "notes":[data["notes"]], - "location_categories":[data["location_categories"]], - "minimum_withdrawal": data["minimum_withdrawal"] if data["minimum_withdrawal"]!="" else "false", - "branch_identification": data["branch_identification"] if data["branch_identification"]!="" else "false", - "site_identification": data["site_identification"] if data["site_identification"]!="" else "false", - "site_name": data["site_name"] if data["site_name"]!="" else "false", - "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", - } - try: - result = self.api.put(urlpath, payload=payload) - if 'code' in result and result['code']>=400: - messages.error(self.request, result['message']) - return super(UpdateAccountsView, self).form_invalid(form) - except APIError as err: - messages.error(self.request, err) - return super(UpdateAccountsView, self).form_invalid(form) - except Exception as e: - messages.error(self.request, e) - return super(UpdateAccountsView, self).form_invalid(form) - msg = 'Atm {} for Bank {} has been updated successfully!'.format( # noqa - data["atm_id"], data["bank_id"]) - messages.success(self.request, msg) - return super(UpdateAccountsView, self).form_valid(form) - - def get_context_data(self, **kwargs): - context = super(UpdateAccountsView, 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 -