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..75039ef 100644 --- a/apimanager/customers/forms.py +++ b/apimanager/customers/forms.py @@ -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 diff --git a/apimanager/customers/templates/customers/create.html b/apimanager/customers/templates/customers/create.html index e19c449..d3307a1 100644 --- a/apimanager/customers/templates/customers/create.html +++ b/apimanager/customers/templates/customers/create.html @@ -5,8 +5,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 +32,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 }}
@@ -84,10 +90,17 @@
- {% 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 }} +
+
+
diff --git a/apimanager/customers/views.py b/apimanager/customers/views.py index ca4ad3f..a4113eb 100644 --- a/apimanager/customers/views.py +++ b/apimanager/customers/views.py @@ -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)