diff --git a/apimanager/apimanager/settings.py b/apimanager/apimanager/settings.py index 9c918ae..ad52a2a 100644 --- a/apimanager/apimanager/settings.py +++ b/apimanager/apimanager/settings.py @@ -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' diff --git a/apimanager/customers/forms.py b/apimanager/customers/forms.py index 925375e..f8fced3 100644 --- a/apimanager/customers/forms.py +++ b/apimanager/customers/forms.py @@ -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 diff --git a/apimanager/customers/templates/customers/create.html b/apimanager/customers/templates/customers/create.html index e19c449..bf6c617 100644 --- a/apimanager/customers/templates/customers/create.html +++ b/apimanager/customers/templates/customers/create.html @@ -4,9 +4,14 @@ {% block page_title %}{{ block.super }} / {% trans "Customers" %}{% endblock page_title %} - +{% load bootstrap3 %} {% block content %}
+ {% bootstrap_javascript jquery='full' %} {# Embed Bootstrap JS+jQuery #} + + {% block extrahead %} {# Extra Resources Start #} + {{ form.media }} {# Form required JS and CSS #} + {% endblock %}

{% trans "Create Customer" %}

@@ -26,10 +31,10 @@
- {% if form.username.errors %}
{{ form.username.errors }}
{% endif %} + {% if form.user_id.errors %}
{{ form.user_id.errors }}
{% endif %}
- {{ form.username.label_tag }} - {{ form.username }} + {{ form.user_id.label_tag }} + {{ form.user_id }}
@@ -83,14 +88,21 @@
-
- {% if form.date_of_birth.errors %}
{{ form.date_of_birth.errors }}
{% endif %} +
+ {% if form.date_of_birth_date.errors %}
{{ form.date_of_birth_date.errors }}
{% endif %}
- {{ form.date_of_birth.label_tag }} - {{ form.date_of_birth }} + {{ form.date_of_birth_date.label_tag }} + {{ form.date_of_birth_date }}
-
+
+ {% if form.date_of_birth_time.errors %}
{{ form.date_of_birth_time.errors }}
{% endif %} +
+ {{ form.date_of_birth_time.label_tag }} + {{ form.date_of_birth_time }} +
+
+
{% if form.relationship_status.errors %}
{{ form.relationship_status.errors }}
{% endif %}
{{ form.relationship_status.label_tag }} diff --git a/apimanager/customers/views.py b/apimanager/customers/views.py index ca4ad3f..644e5a3 100644 --- a/apimanager/customers/views.py +++ b/apimanager/customers/views.py @@ -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'],