mirror of
https://github.com/OpenBankProject/API-Manager.git
synced 2026-02-06 12:46:54 +00:00
Merge pull request #301 from Reena-cell/develop
refactor/ divide datetime field in Create Customer
This commit is contained in:
commit
82a52a8ef2
@ -250,6 +250,8 @@ API_DATE_FORMAT = '%Y-%m-%dT%H:%M:%S.%fZ'
|
||||
|
||||
# the API_Manager the web form date format, eg: 2020-10-11
|
||||
API_MANAGER_DATE_FORMAT= '%Y-%m-%d'
|
||||
API_FIELD_DATE_FORMAT= '%Y-%m-%d'
|
||||
API_FIELD_TIME_FORMAT= '%H-%M-%S'
|
||||
|
||||
|
||||
API_HOST = 'http://127.0.0.1:8080'
|
||||
|
||||
@ -7,9 +7,13 @@ from django import forms
|
||||
from django.conf import settings
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from apimanager.settings import API_FIELD_DATE_FORMAT, API_FIELD_TIME_FORMAT
|
||||
from bootstrap_datepicker_plus import DatePickerInput, DateTimePickerInput
|
||||
from datetime import datetime, timedelta
|
||||
from obp.api import APIError
|
||||
|
||||
PLACEHOLDER = "2013-01-22T00:08:00Z"
|
||||
PLACEHOLDER = "2013-01-22"
|
||||
PLACEHOLDER1 = "00:00:00"
|
||||
|
||||
class CreateCustomerForm(forms.Form):
|
||||
bank_id = forms.ChoiceField(
|
||||
@ -21,11 +25,11 @@ class CreateCustomerForm(forms.Form):
|
||||
),
|
||||
choices=[],
|
||||
)
|
||||
username = forms.CharField(
|
||||
label=_('Username'),
|
||||
user_id = forms.CharField(
|
||||
label=_('User Id'),
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'placeholder': _('The name of the user'),
|
||||
'placeholder': _('The ID of the user'),
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
@ -90,16 +94,22 @@ class CreateCustomerForm(forms.Form):
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
date_of_birth = forms.DateTimeField(
|
||||
label=_('Date of Birth'),
|
||||
input_formats=[settings.API_DATE_TIME_FORMAT],
|
||||
widget=forms.DateTimeInput(
|
||||
date_of_birth_date = forms.DateField(
|
||||
label=_("Date of Birth"),
|
||||
widget=DatePickerInput(format=API_FIELD_DATE_FORMAT),
|
||||
required=True,
|
||||
initial=str(datetime.now().strftime(API_FIELD_DATE_FORMAT)),
|
||||
)
|
||||
date_of_birth_time = forms.TimeField(
|
||||
label=_('Time of Birth'),
|
||||
widget=forms.TimeInput(
|
||||
format='%H:%M:%S',
|
||||
attrs={
|
||||
'placeholder': PLACEHOLDER,
|
||||
'placeholder': PLACEHOLDER1,
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=True,
|
||||
required=False,
|
||||
)
|
||||
relationship_status = forms.CharField(
|
||||
label=_('Relationship Status'),
|
||||
@ -225,13 +235,6 @@ class CreateCustomerForm(forms.Form):
|
||||
else:
|
||||
return None
|
||||
|
||||
def clean_date_of_birth(self):
|
||||
data = self.cleaned_data['date_of_birth']
|
||||
if data:
|
||||
return data.strftime(settings.API_DATE_TIME_FORMAT)
|
||||
else:
|
||||
return None
|
||||
|
||||
def clean_dob_of_dependants(self):
|
||||
data = self.cleaned_data['dob_of_dependants']
|
||||
if data:
|
||||
@ -240,13 +243,6 @@ class CreateCustomerForm(forms.Form):
|
||||
return []
|
||||
|
||||
def clean_username(self):
|
||||
username = self.cleaned_data['username']
|
||||
if not hasattr(self, 'api'):
|
||||
raise forms.ValidationError('No API object available')
|
||||
try:
|
||||
user = self.api.get('/users/username/{}'.format(username))
|
||||
except APIError as err:
|
||||
raise forms.ValidationError(err)
|
||||
else:
|
||||
self.cleaned_data['user_id'] = user['user_id']
|
||||
return username
|
||||
self.cleaned_data['user_id'] = self.cleaned_data["user_id"]
|
||||
user_id = self.cleaned_data['user_id']
|
||||
return user_id
|
||||
|
||||
@ -5,8 +5,14 @@
|
||||
{% block page_title %}{{ block.super }} / {% trans "Customers" %}{% endblock page_title %}
|
||||
|
||||
|
||||
{% load bootstrap3 %}
|
||||
{% block content %}
|
||||
<div id="customers">
|
||||
{% bootstrap_javascript jquery='full' %} {# Embed Bootstrap JS+jQuery #}
|
||||
|
||||
{% block extrahead %} {# Extra Resources Start #}
|
||||
{{ form.media }} {# Form required JS and CSS #}
|
||||
{% endblock %}
|
||||
<h1>{% trans "Create Customer" %}</h1>
|
||||
|
||||
<form action="{% url 'customers-create' %}" method="post">
|
||||
@ -26,10 +32,10 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.username.errors %}<div class="alert alert-danger">{{ form.username.errors }}</div>{% endif %}
|
||||
{% if form.user_id.errors %}<div class="alert alert-danger">{{ form.user_id.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.username.label_tag }}
|
||||
{{ form.username }}
|
||||
{{ form.user_id.label_tag }}
|
||||
{{ form.user_id }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
@ -84,10 +90,17 @@
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-6">
|
||||
{% if form.date_of_birth.errors %}<div class="alert alert-danger">{{ form.date_of_birth.errors }}</div>{% endif %}
|
||||
{% if form.date_of_birth_date.errors %}<div class="alert alert-danger">{{ form.date_of_birth_date.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.date_of_birth.label_tag }}
|
||||
{{ form.date_of_birth }}
|
||||
{{ form.date_of_birth_date.label_tag }}
|
||||
{{ form.date_of_birth_date }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4" style="display:none">
|
||||
{% if form.date_of_birth_time.errors %}<div class="alert alert-danger">{{ form.date_of_birth_time.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.date_of_birth_time.label_tag }}
|
||||
{{ form.date_of_birth_time }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-6">
|
||||
|
||||
@ -42,6 +42,10 @@ class CreateView(LoginRequiredMixin, FormView):
|
||||
return form
|
||||
|
||||
def form_valid(self, form):
|
||||
date_of_birth_date = form.cleaned_data['date_of_birth_date']
|
||||
date_of_birth_time = form.cleaned_data['date_of_birth_time']
|
||||
final_date_of_birth = str(date_of_birth_date) + "T" + str(date_of_birth_time) + "Z"
|
||||
form.cleaned_data['date_of_birth'] = final_date_of_birth
|
||||
data = form.cleaned_data
|
||||
urlpath = '/banks/{}/customers'.format(data['bank_id'])
|
||||
payload = {
|
||||
@ -54,7 +58,7 @@ class CreateView(LoginRequiredMixin, FormView):
|
||||
'url': data['face_image_url'],
|
||||
'date': data['face_image_date'],
|
||||
},
|
||||
'date_of_birth': data['date_of_birth'],
|
||||
'date_of_birth': final_date_of_birth,
|
||||
'relationship_status': data['relationship_status'],
|
||||
'dependants': data['dependants'],
|
||||
'dob_of_dependants': data['dob_of_dependants'],
|
||||
@ -81,7 +85,7 @@ class CreateView(LoginRequiredMixin, FormView):
|
||||
except Exception as err:
|
||||
messages.error(self.request, err)
|
||||
return super(CreateView, self).form_invalid(form)
|
||||
msg = 'Customer number {} for user {} has been created successfully!'.format( # noqa
|
||||
result['customer_number'], data['username'])
|
||||
msg = 'Customer number {} for user_id {} has been created successfully!' .format( # noqa
|
||||
data['customer_number'], data['user_id'])
|
||||
messages.success(self.request, msg)
|
||||
return super(CreateView, self).form_valid(form)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user