mirror of
https://github.com/OpenBankProject/API-Manager.git
synced 2026-02-06 10:59:00 +00:00
date_time saparate fields in Create Customer
This commit is contained in:
parent
0debdc88a5
commit
4f65c07fba
@ -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'
|
||||
|
||||
@ -6,10 +6,13 @@ Forms of customers app
|
||||
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 +24,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 +93,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 +234,22 @@ class CreateCustomerForm(forms.Form):
|
||||
else:
|
||||
return None
|
||||
|
||||
def clean_date_of_birth(self):
|
||||
data = self.cleaned_data['date_of_birth']
|
||||
""" def clean_date_of_birth_date(self):
|
||||
print("Hello from clean_date_of_birth_date")
|
||||
data = self.cleaned_data['date_of_birth_date']
|
||||
print("data is:::::", data)
|
||||
if data:
|
||||
return data.strftime(settings.API_DATE_TIME_FORMAT)
|
||||
return data.strftime(settings.API_FIELD_DATE_FORMAT)
|
||||
else:
|
||||
return None
|
||||
|
||||
def clean_date_of_birth_time(self):
|
||||
data = self.cleaned_data['date_of_birth_time']
|
||||
if data:
|
||||
return data.strftime(settings.API_FIELD_TIME_FORMAT)
|
||||
else:
|
||||
return None"""
|
||||
|
||||
def clean_dob_of_dependants(self):
|
||||
data = self.cleaned_data['dob_of_dependants']
|
||||
if data:
|
||||
@ -240,13 +258,19 @@ class CreateCustomerForm(forms.Form):
|
||||
return []
|
||||
|
||||
def clean_username(self):
|
||||
username = self.cleaned_data['username']
|
||||
self.cleaned_data['user_id'] = self.cleaned_data["username"]
|
||||
user_id = self.cleaned_data['user_id']
|
||||
""" print("username is::.", username)
|
||||
if not hasattr(self, 'api'):
|
||||
print("Hello World")
|
||||
raise forms.ValidationError('No API object available')
|
||||
try:
|
||||
print("Hello world1")
|
||||
user = self.api.get('/users/username/{}'.format(username))
|
||||
except APIError as err:
|
||||
print("Hello world1")
|
||||
raise forms.ValidationError(err)
|
||||
else:
|
||||
self.cleaned_data['user_id'] = user['user_id']
|
||||
return username
|
||||
print("username is", username) """
|
||||
return user_id
|
||||
|
||||
@ -4,9 +4,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 +31,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">
|
||||
@ -83,14 +88,21 @@
|
||||
</div>
|
||||
|
||||
<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 %}
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% 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-6">
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% 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-4">
|
||||
{% if form.relationship_status.errors %}<div class="alert alert-danger">{{ form.relationship_status.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.relationship_status.label_tag }}
|
||||
|
||||
@ -42,6 +42,11 @@ 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']
|
||||
print("date_of_birth", dob_date, dob_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 +59,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'],
|
||||
|
||||
Loading…
Reference in New Issue
Block a user