diff --git a/apimanager/apimanager/settings.py b/apimanager/apimanager/settings.py
index 7ee3427..11aac38 100644
--- a/apimanager/apimanager/settings.py
+++ b/apimanager/apimanager/settings.py
@@ -48,6 +48,7 @@ INSTALLED_APPS = [
'oauth',
'consumers',
'users',
+ 'customers',
'metrics',
#'api_config',
]
@@ -167,6 +168,14 @@ LOGGING = {
'handlers': ['console'],
'level': 'INFO',
},
+ 'customers': {
+ 'handlers': ['console'],
+ 'level': 'INFO',
+ },
+ 'metrics': {
+ 'handlers': ['console'],
+ 'level': 'INFO',
+ },
},
}
diff --git a/apimanager/apimanager/urls.py b/apimanager/apimanager/urls.py
index 4079a9e..87d9fe8 100644
--- a/apimanager/apimanager/urls.py
+++ b/apimanager/apimanager/urls.py
@@ -13,6 +13,7 @@ urlpatterns = [
url(r'^oauth/', include('oauth.urls')),
url(r'^consumers/', include('consumers.urls')),
url(r'^users/', include('users.urls')),
+ url(r'^customers/', include('customers.urls')),
url(r'^metrics/', include('metrics.urls')),
#url(r'^api_config/', include('api_config.urls')),
]
diff --git a/apimanager/base/templates/base.html b/apimanager/base/templates/base.html
index efe4c4d..846bbc3 100644
--- a/apimanager/base/templates/base.html
+++ b/apimanager/base/templates/base.html
@@ -31,6 +31,8 @@
Consumers
{% url "users-index" as users_index_url %}
Users
+ {% url "customers-create" as customers_create_url %}
+ Customers
{% url "metrics-index" as metrics_index_url %}
Metrics
{% comment %}
diff --git a/apimanager/customers/__init__.py b/apimanager/customers/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/apimanager/customers/apps.py b/apimanager/customers/apps.py
new file mode 100644
index 0000000..01aabb7
--- /dev/null
+++ b/apimanager/customers/apps.py
@@ -0,0 +1,5 @@
+from django.apps import AppConfig
+
+
+class CustomersConfig(AppConfig):
+ name = 'customers'
diff --git a/apimanager/customers/forms.py b/apimanager/customers/forms.py
new file mode 100644
index 0000000..b9c159c
--- /dev/null
+++ b/apimanager/customers/forms.py
@@ -0,0 +1,216 @@
+# -*- coding: utf-8 -*-
+"""
+Forms of customers app
+"""
+
+from django import forms
+
+DATETIME_INPUT_FORMAT = '%Y-%m-%dT%H:%M:%SZ'
+
+
+class CreateCustomerForm(forms.Form):
+ bank_id = forms.ChoiceField(
+ label='Bank',
+ widget=forms.Select(
+ attrs={
+ 'class': 'form-control',
+ }
+ ),
+ choices=[],
+ )
+ user_id = forms.ChoiceField(
+ label='User',
+ widget=forms.Select(
+ attrs={
+ 'class': 'form-control',
+ }
+ ),
+ choices=[],
+ )
+ customer_number = forms.CharField(
+ label='Customer Number',
+ widget=forms.TextInput(
+ attrs={
+ 'placeholder': 'new customer number, e.g. 687687678',
+ 'class': 'form-control',
+ }
+ ),
+ )
+ legal_name = forms.CharField(
+ label='Legal Name',
+ widget=forms.TextInput(
+ attrs={
+ 'placeholder': 'NONE',
+ 'class': 'form-control',
+ }
+ ),
+ required=False,
+ )
+ mobile_phone_number = forms.CharField(
+ label='Mobile Phone Number',
+ widget=forms.TextInput(
+ attrs={
+ 'placeholder': '+49 123 456 78 90 12',
+ 'class': 'form-control',
+ }
+ ),
+ required=False,
+ )
+ email = forms.CharField(
+ label='Email',
+ widget=forms.TextInput(
+ attrs={
+ 'placeholder': 'person@example.com',
+ 'class': 'form-control',
+ }
+ ),
+ required=False,
+ )
+ face_image_url = forms.CharField(
+ label='Face Image URL',
+ widget=forms.TextInput(
+ attrs={
+ 'placeholder': 'https://static.openbankproject.com/images/OBP/favicon.png',
+ 'class': 'form-control',
+ }
+ ),
+ required=False,
+ )
+ face_image_date = forms.DateTimeField(
+ label='Face Image Date',
+ input_formats=[DATETIME_INPUT_FORMAT],
+ widget=forms.DateTimeInput(
+ attrs={
+ 'placeholder': '2013-01-22T00:08:00Z',
+ 'class': 'form-control',
+ }
+ ),
+ required=True,
+ )
+ date_of_birth = forms.DateTimeField(
+ label='Date of Birth',
+ input_formats=[DATETIME_INPUT_FORMAT],
+ widget=forms.DateTimeInput(
+ attrs={
+ 'placeholder': '2013-01-22T00:08:00Z',
+ 'class': 'form-control',
+ }
+ ),
+ required=True,
+ )
+ relationship_status = forms.CharField(
+ label='Relationship Status',
+ widget=forms.TextInput(
+ attrs={
+ 'placeholder': 'Single',
+ 'class': 'form-control',
+ }
+ ),
+ required=False,
+ )
+ dependants = forms.IntegerField(
+ label='Dependants',
+ widget=forms.TextInput(
+ attrs={
+ 'placeholder': '0',
+ 'class': 'form-control',
+ }
+ ),
+ initial=0,
+ required=True,
+ )
+ dob_of_dependants = forms.CharField(
+ label='Date of Birth of Dependants',
+ widget=forms.TextInput(
+ attrs={
+ 'placeholder': '2013-01-22T00:08:00Z, 2010-01-22T00:08:00Z',
+ 'class': 'form-control',
+ }
+ ),
+ required=False,
+ )
+ credit_rating_rating = forms.CharField(
+ label='Credit Rating (Rating)',
+ widget=forms.TextInput(
+ attrs={
+ 'placeholder': 'OBP',
+ 'class': 'form-control',
+ }
+ ),
+ required=False,
+ )
+ credit_rating_source = forms.CharField(
+ label='Credit Rating (Source)',
+ widget=forms.TextInput(
+ attrs={
+ 'placeholder': 'OBP',
+ 'class': 'form-control',
+ }
+ ),
+ required=False,
+ )
+ credit_limit_currency = forms.CharField(
+ label='Credit Limit (Currency)',
+ widget=forms.TextInput(
+ attrs={
+ 'placeholder': 'EUR',
+ 'class': 'form-control',
+ }
+ ),
+ required=False,
+ )
+ credit_limit_amount = forms.CharField(
+ label='Credit Limit (Amount)',
+ widget=forms.TextInput(
+ attrs={
+ 'placeholder': '10',
+ 'class': 'form-control',
+ }
+ ),
+ required=False,
+ )
+ highest_education_attained = forms.CharField(
+ label='Highest Education Attained',
+ widget=forms.TextInput(
+ attrs={
+ 'placeholder': 'Bachelor’s Degree',
+ 'class': 'form-control',
+ }
+ ),
+ required=False,
+ )
+ employment_status = forms.CharField(
+ label='Employment Status',
+ widget=forms.TextInput(
+ attrs={
+ 'placeholder': 'Employed',
+ 'class': 'form-control',
+ }
+ ),
+ required=False,
+ )
+ kyc_status = forms.BooleanField(
+ label='KYC Status',
+ widget=forms.CheckboxInput(
+ attrs={
+ 'class': 'form-control',
+ }
+ ),
+ initial=True,
+ required=False,
+ )
+ last_ok_date = forms.DateTimeField(
+ label='Last OK Date',
+ input_formats=[DATETIME_INPUT_FORMAT],
+ widget=forms.DateTimeInput(
+ attrs={
+ 'placeholder': '2013-01-22T00:08:00Z',
+ 'class': 'form-control',
+ }
+ ),
+ required=True,
+ )
+
+ def __init__(self, *args, **kwargs):
+ kwargs.setdefault('label_suffix', '')
+ super(CreateCustomerForm, self).__init__(*args, **kwargs)
diff --git a/apimanager/customers/static/customers/css/customers.css b/apimanager/customers/static/customers/css/customers.css
new file mode 100644
index 0000000..94ec978
--- /dev/null
+++ b/apimanager/customers/static/customers/css/customers.css
@@ -0,0 +1,8 @@
+#customers {
+ margin-bottom: 10px;
+}
+
+input#id_kyc_status {
+ width: auto;
+ margin: -4px 0;
+}
diff --git a/apimanager/customers/static/customers/js/customers.js b/apimanager/customers/static/customers/js/customers.js
new file mode 100644
index 0000000..8da0463
--- /dev/null
+++ b/apimanager/customers/static/customers/js/customers.js
@@ -0,0 +1,2 @@
+$(document).ready(function($) {
+});
diff --git a/apimanager/customers/templates/customers/create.html b/apimanager/customers/templates/customers/create.html
new file mode 100644
index 0000000..dc4da99
--- /dev/null
+++ b/apimanager/customers/templates/customers/create.html
@@ -0,0 +1,201 @@
+{% extends 'base.html' %}
+{% load static %}
+
+{% block page_title %}{{ block.super }} / Customers{% endblock page_title %}
+
+
+{% block content %}
+
+{% endblock content %}
+
+
+{% block extrajs %}
+{% comment %}
+
+
+{% endcomment %}
+{% endblock extrajs %}
+
+
+{% block extracss %}
+
+{% endblock extracss %}
diff --git a/apimanager/customers/urls.py b/apimanager/customers/urls.py
new file mode 100644
index 0000000..b0d72c6
--- /dev/null
+++ b/apimanager/customers/urls.py
@@ -0,0 +1,14 @@
+# -*- coding: utf-8 -*-
+"""
+URLs for customers app
+"""
+
+from django.conf.urls import url
+
+from .views import CreateView
+
+urlpatterns = [
+ url(r'^$',
+ CreateView.as_view(),
+ name='customers-create'),
+]
diff --git a/apimanager/customers/views.py b/apimanager/customers/views.py
new file mode 100644
index 0000000..a091b6d
--- /dev/null
+++ b/apimanager/customers/views.py
@@ -0,0 +1,101 @@
+# -*- coding: utf-8 -*-
+"""
+Views of customers app
+"""
+
+import datetime
+
+from django.contrib import messages
+from django.contrib.auth.mixins import LoginRequiredMixin
+from django.http import HttpResponseRedirect
+from django.urls import reverse_lazy
+from django.views.generic import FormView
+
+from base.api import api, APIError
+
+from .forms import CreateCustomerForm, DATETIME_INPUT_FORMAT
+
+
+class CreateView(LoginRequiredMixin, FormView):
+ """View to create a customer"""
+ form_class = CreateCustomerForm
+ template_name = 'customers/create.html'
+ success_url = reverse_lazy('customers-create')
+
+ def get_bank_id_choices(self):
+ choices = [('', 'Choose ...')]
+ try:
+ result = api.get(self.request, '/banks')
+ for bank in result['banks']:
+ choices.append((bank['id'], bank['short_name']))
+ except APIError as err:
+ messages.error(err)
+ return choices
+
+ def get_user_id_choices(self):
+ choices = [('', 'Choose ...')]
+ try:
+ result = api.get(self.request, '/users')
+ for user in result['users']:
+ choices.append((user['user_id'], user['username']))
+ except APIError as err:
+ messages.error(err)
+ return choices
+
+ def get_form(self, *args, **kwargs):
+ form = super(CreateView, self).get_form(*args, **kwargs)
+ fields = form.fields
+ fields['bank_id'].choices = self.get_bank_id_choices()
+ fields['user_id'].choices = self.get_user_id_choices()
+ fields['last_ok_date'].initial =\
+ datetime.datetime.now().strftime(DATETIME_INPUT_FORMAT)
+ return form
+
+ def form_valid(self, form):
+ try:
+ data = form.cleaned_data
+ urlpath = '/banks/{}/customers'.format(data['bank_id'])
+ if data['dob_of_dependants']:
+ dob_of_dependants = data['dob_of_dependants'].split(',')
+ else:
+ dob_of_dependants = []
+ payload = {
+ 'user_id': data['user_id'],
+ 'customer_number': data['customer_number'],
+ 'legal_name': data['legal_name'],
+ 'mobile_phone_number': data['mobile_phone_number'],
+ 'email': data['email'],
+ 'face_image': {
+ 'url': data['face_image_url'],
+ 'date':
+ data['face_image_date'].strftime(DATETIME_INPUT_FORMAT),
+ },
+ 'date_of_birth':
+ data['date_of_birth'].strftime(DATETIME_INPUT_FORMAT),
+ 'relationship_status': data['relationship_status'],
+ 'dependants': data['dependants'],
+ 'dob_of_dependants': dob_of_dependants,
+ 'credit_rating': {
+ 'rating': data['credit_rating_rating'],
+ 'source': data['credit_rating_source'],
+ },
+ 'credit_limit': {
+ 'currency': data['credit_limit_currency'],
+ 'amount': data['credit_limit_amount'],
+ },
+ 'highest_education_attained':
+ data['highest_education_attained'],
+ 'employment_status': data['employment_status'],
+ 'kyc_status': data['kyc_status'],
+ 'last_ok_date':
+ data['last_ok_date'].strftime(DATETIME_INPUT_FORMAT),
+ }
+ result = api.post(self.request, urlpath, payload=payload)
+ except APIError as err:
+ messages.error(self.request, err)
+ return super(CreateView, self).form_invalid(form)
+
+ msg = 'Customer number {} has been created successfully!'.format(
+ result['customer_number'])
+ messages.success(self.request, msg)
+ return super(CreateView, self).form_valid(form)