From 4f65c07fba6f7b526df3f67caa791d4ba280f3c2 Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Wed, 22 Mar 2023 09:22:26 +0100 Subject: [PATCH 1/6] date_time saparate fields in Create Customer --- apimanager/apimanager/settings.py | 2 + apimanager/customers/forms.py | 56 +++++++++++++------ .../customers/templates/customers/create.html | 30 +++++++--- apimanager/customers/views.py | 7 ++- 4 files changed, 69 insertions(+), 26 deletions(-) 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'], From 3500cc866cbd5e03926ee8f3e89ddc9ff1c23f43 Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Wed, 22 Mar 2023 09:27:09 +0100 Subject: [PATCH 2/6] date_time saparate fields in Create Customer --- apimanager/customers/forms.py | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/apimanager/customers/forms.py b/apimanager/customers/forms.py index f8fced3..863a2d2 100644 --- a/apimanager/customers/forms.py +++ b/apimanager/customers/forms.py @@ -234,22 +234,6 @@ class CreateCustomerForm(forms.Form): else: return None - """ 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_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: @@ -260,17 +244,4 @@ class CreateCustomerForm(forms.Form): def clean_username(self): 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'] - print("username is", username) """ return user_id From 8798910bead32321972cb784832ba8b6181e014d Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Wed, 22 Mar 2023 09:30:07 +0100 Subject: [PATCH 3/6] refactor/ date_time saparate fields in Create Customer --- apimanager/customers/forms.py | 3 ++- apimanager/customers/templates/customers/create.html | 1 + apimanager/customers/views.py | 1 - 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apimanager/customers/forms.py b/apimanager/customers/forms.py index 863a2d2..75039ef 100644 --- a/apimanager/customers/forms.py +++ b/apimanager/customers/forms.py @@ -6,6 +6,7 @@ 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 @@ -242,6 +243,6 @@ class CreateCustomerForm(forms.Form): return [] def clean_username(self): - self.cleaned_data['user_id'] = self.cleaned_data["username"] + self.cleaned_data['user_id'] = self.cleaned_data["user_id"] user_id = self.cleaned_data['user_id'] return user_id diff --git a/apimanager/customers/templates/customers/create.html b/apimanager/customers/templates/customers/create.html index bf6c617..37b5caf 100644 --- a/apimanager/customers/templates/customers/create.html +++ b/apimanager/customers/templates/customers/create.html @@ -4,6 +4,7 @@ {% block page_title %}{{ block.super }} / {% trans "Customers" %}{% endblock page_title %} + {% load bootstrap3 %} {% block content %}
diff --git a/apimanager/customers/views.py b/apimanager/customers/views.py index 644e5a3..47e5c07 100644 --- a/apimanager/customers/views.py +++ b/apimanager/customers/views.py @@ -44,7 +44,6 @@ class CreateView(LoginRequiredMixin, FormView): 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 From 80840f59b7f88f44985474f84920005b579040ad Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Wed, 22 Mar 2023 09:51:15 +0100 Subject: [PATCH 4/6] refactor/ date_time saparate fields in Create Customer --- apimanager/customers/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apimanager/customers/views.py b/apimanager/customers/views.py index 47e5c07..c8dce70 100644 --- a/apimanager/customers/views.py +++ b/apimanager/customers/views.py @@ -85,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 + result['customer_number'], data['user_id']) messages.success(self.request, msg) return super(CreateView, self).form_valid(form) From 545c94ac14adbd0bd7721afe07144994d9f19a01 Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Wed, 22 Mar 2023 13:06:07 +0100 Subject: [PATCH 5/6] refactor/ date_time saparate fields in Create Customer --- apimanager/customers/templates/customers/create.html | 6 +++--- apimanager/customers/views.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apimanager/customers/templates/customers/create.html b/apimanager/customers/templates/customers/create.html index 37b5caf..d3307a1 100644 --- a/apimanager/customers/templates/customers/create.html +++ b/apimanager/customers/templates/customers/create.html @@ -89,21 +89,21 @@
-
+
{% if form.date_of_birth_date.errors %}
{{ form.date_of_birth_date.errors }}
{% endif %}
{{ form.date_of_birth_date.label_tag }} {{ form.date_of_birth_date }}
-
+ -
+
{% 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 c8dce70..a4113eb 100644 --- a/apimanager/customers/views.py +++ b/apimanager/customers/views.py @@ -86,6 +86,6 @@ class CreateView(LoginRequiredMixin, FormView): messages.error(self.request, err) return super(CreateView, self).form_invalid(form) msg = 'Customer number {} for user_id {} has been created successfully!' .format( # noqa - result['customer_number'], data['user_id']) + data['customer_number'], data['user_id']) messages.success(self.request, msg) return super(CreateView, self).form_valid(form) From 5b82ab5756114cad349d45bf46f289039ec6f18c Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Wed, 22 Mar 2023 13:06:07 +0100 Subject: [PATCH 6/6] refactor/ date_time saparate fields in Create Customer --- apimanager/customers/templates/customers/create.html | 6 +++--- apimanager/customers/views.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apimanager/customers/templates/customers/create.html b/apimanager/customers/templates/customers/create.html index 37b5caf..d3307a1 100644 --- a/apimanager/customers/templates/customers/create.html +++ b/apimanager/customers/templates/customers/create.html @@ -89,21 +89,21 @@
-
+
{% if form.date_of_birth_date.errors %}
{{ form.date_of_birth_date.errors }}
{% endif %}
{{ form.date_of_birth_date.label_tag }} {{ form.date_of_birth_date }}
-
+ -
+
{% 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 c8dce70..a4113eb 100644 --- a/apimanager/customers/views.py +++ b/apimanager/customers/views.py @@ -86,6 +86,6 @@ class CreateView(LoginRequiredMixin, FormView): messages.error(self.request, err) return super(CreateView, self).form_invalid(form) msg = 'Customer number {} for user_id {} has been created successfully!' .format( # noqa - result['customer_number'], data['user_id']) + data['customer_number'], data['user_id']) messages.success(self.request, msg) return super(CreateView, self).form_valid(form)