diff --git a/apimanager/apimanager/settings.py b/apimanager/apimanager/settings.py index 39af906a..2781d3cf 100644 --- a/apimanager/apimanager/settings.py +++ b/apimanager/apimanager/settings.py @@ -251,6 +251,9 @@ #Map Java: yyyy-MM-dd'T'HH:mm:ss.SSS'Z' API_DATE_FORMAT_WITH_MILLISECONDS = '%Y-%m-%dT%H:%M:%S.%fZ' +# the API_Manager the web form datetime format, eg: 2023-11-28 10:49:27 +API_DATE_FORMAT_WITH_DAY_DATE_TIME = '%Y-%m-%d %H:%M:%S' + # the API_Manager the web form date format, eg: 2020-10-11 API_DATE_FORMAT_WITH_DAY = '%Y-%m-%d' API_FIELD_TIME_FORMAT = '%H-%M-%S' diff --git a/apimanager/banks/views.py b/apimanager/banks/views.py index c0a9514f..1e48b14e 100644 --- a/apimanager/banks/views.py +++ b/apimanager/banks/views.py @@ -111,8 +111,6 @@ def get_form(self, *args, **kwargs): fields['bank_routings_scheme'].initial = result['bank_routings'][0]["scheme"] fields['bank_routings_address'].initial = result['bank_routings'][0]["address"] except Exception as err: - if DEBUG: - raise(err) messages.error(self.request, "Unknown Error {}".format(err)) return form @@ -138,13 +136,9 @@ def form_valid(self, form): messages.error(self.request, result['message']) return super(UpdateBanksView, self).form_invalid(form) except APIError as err: - if DEBUG: - raise(err) messages.error(self.request, err) return super(UpdateBanksView, self).form_invalid(form) except Exception as e: - if DEBUG: - raise(err) messages.error(self.request, e) return super(UpdateBanksView, self).form_invalid(form) msg = 'Bank {} has been updated successfully!'.format( # noqa diff --git a/apimanager/base/utils.py b/apimanager/base/utils.py index 108e945a..16c04519 100644 --- a/apimanager/base/utils.py +++ b/apimanager/base/utils.py @@ -4,7 +4,8 @@ """ from django.contrib.humanize.templatetags.humanize import naturaltime from datetime import datetime, timedelta -from apimanager.settings import API_DATE_FORMAT_WITH_MILLISECONDS, API_DATE_FORMAT_WITH_DAY +from apimanager.settings import API_DATE_FORMAT_WITH_MILLISECONDS, API_DATE_FORMAT_WITH_DAY, \ + API_DATE_FORMAT_WITH_DAY_DATE_TIME from base import context_processors from django.contrib import messages import functools @@ -61,7 +62,7 @@ def convert_form_date_to_obpapi_datetime_format(form_to_date_string): """ convert the String 2020-10-22 to 2020-10-22T00:00:00.000000Z """ - return datetime.strptime(form_to_date_string, API_DATE_FORMAT_WITH_DAY).strftime(API_DATE_FORMAT_WITH_MILLISECONDS) + return datetime.strptime(form_to_date_string, API_DATE_FORMAT_WITH_DAY_DATE_TIME).strftime(API_DATE_FORMAT_WITH_MILLISECONDS) def return_to_days_ago(date, days): """ diff --git a/apimanager/base/views.py b/apimanager/base/views.py index d63c3f42..058b70d9 100644 --- a/apimanager/base/views.py +++ b/apimanager/base/views.py @@ -31,7 +31,7 @@ def get_consumers(request): else: return [] except APIError as err: - messages.error(self.request, err) + messages.error(request, err) return [] def get_api_versions(request): @@ -44,7 +44,7 @@ def get_api_versions(request): else: return [] except APIError as err: - messages.error(self.request, err) + messages.error(request, err) return [] class HomeView(TemplateView): diff --git a/apimanager/metrics/forms.py b/apimanager/metrics/forms.py index d161e0c9..4a370912 100644 --- a/apimanager/metrics/forms.py +++ b/apimanager/metrics/forms.py @@ -10,54 +10,32 @@ from datetime import datetime, timedelta from django.utils.translation import ugettext_lazy as _ -from bootstrap_datepicker_plus import DatePickerInput, DateTimePickerInput -from apimanager.settings import API_DATE_FORMAT_WITH_DAY, API_DATE_FORMAT_WITH_MILLISECONDS -from apimanager.settings import API_DATE_FORMAT_WITH_DAY, API_FIELD_TIME_FORMAT +from bootstrap_datepicker_plus import DateTimePickerInput +from apimanager.settings import API_DATE_FORMAT_WITH_DAY_DATE_TIME API_DATE_FORMAT_WITH_MILLISECONDS_PLACEHOLDER = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" FORM_CONTROL = 'form-control' -FROM_DATE = 'From Date' -TO_DATE = 'To Date' +FROM_DATE = 'From Date Time' +TO_DATE = 'To Date Time' PLACEHOLDER = "2013-01-22" -PLACEHOLDER1 = "23:59:59" +PLACEHOLDER1 = "2022-01-01 12:30:45" PLACEHOLDER2 = "00:00:00" class MetricsForm(forms.Form): from_date = forms.DateTimeField( label=_(FROM_DATE), - widget=DatePickerInput(format=API_DATE_FORMAT_WITH_DAY), + widget=DateTimePickerInput(format=API_DATE_FORMAT_WITH_DAY_DATE_TIME), required=True, - initial=(datetime.now() - timedelta(1)).strftime(API_DATE_FORMAT_WITH_DAY), - ) - from_time = forms.TimeField( - label=_('From Time'), - widget=forms.TimeInput( - format='%H:%M:%S', - attrs={ - 'placeholder': PLACEHOLDER2, - 'class': 'form-control', - } - ), - required=False, + initial=(datetime.now() - timedelta(1)).strftime(API_DATE_FORMAT_WITH_DAY_DATE_TIME), ) to_date = forms.DateTimeField( label=_(TO_DATE), - widget=DatePickerInput(format=API_DATE_FORMAT_WITH_DAY), + widget=DateTimePickerInput(format=API_DATE_FORMAT_WITH_DAY_DATE_TIME), required=True, - initial=(datetime.now() - timedelta()).strftime(API_DATE_FORMAT_WITH_DAY), - ) - to_date_time = forms.TimeField( - label=_('To Time'), - widget=forms.TimeInput( - format='%H:%M:%S', - attrs={ - 'placeholder': PLACEHOLDER1, - 'class': 'form-control', - } - ), - required=False, + initial=(datetime.now() - timedelta()).strftime(API_DATE_FORMAT_WITH_DAY_DATE_TIME), ) + limit = forms.IntegerField( label=_('Limit'), widget=forms.NumberInput( @@ -179,9 +157,9 @@ class ConnectorMetricsForm(MetricsForm): # override from_date until API returns values without given date from_date = forms.DateTimeField( label=_(FROM_DATE), - widget=DatePickerInput(format=API_DATE_FORMAT_WITH_DAY), + widget=DateTimePickerInput(format=API_DATE_FORMAT_WITH_DAY_DATE_TIME), required=True, - initial=(datetime.now() - timedelta(6)).strftime(API_DATE_FORMAT_WITH_DAY), + initial=(datetime.now() - timedelta(6)).strftime(API_DATE_FORMAT_WITH_DAY_DATE_TIME), ) connector_name = forms.CharField( label=_('Connector Name'), @@ -213,39 +191,17 @@ class ConnectorMetricsForm(MetricsForm): class CustomSummaryForm(forms.Form): - to_date = forms.DateField( - label=_("Date"), - widget=DatePickerInput(format=API_DATE_FORMAT_WITH_DAY), + to_date = forms.DateTimeField( + label=_(TO_DATE), + widget=DateTimePickerInput(format=API_DATE_FORMAT_WITH_DAY_DATE_TIME), required=True, - initial=str(datetime.now().strftime(API_DATE_FORMAT_WITH_DAY)), + initial=(datetime.now()).strftime(API_DATE_FORMAT_WITH_DAY_DATE_TIME), ) - to_date_time = forms.TimeField( - label=_('Time'), - widget=forms.TimeInput( - format='%H:%M:%S', - attrs={ - 'placeholder': PLACEHOLDER2, - 'class': 'form-control', - } - ), - required=False, - ) - from_date_custom = forms.DateField( + from_date_custom = forms.DateTimeField( label=_(FROM_DATE), - widget=DatePickerInput(format=API_DATE_FORMAT_WITH_DAY), + widget=DateTimePickerInput(format=API_DATE_FORMAT_WITH_DAY_DATE_TIME), required=True, - initial=(datetime.now() - timedelta(6)).strftime(API_DATE_FORMAT_WITH_DAY), - ) - from_time_custom = forms.TimeField( - label=_('Time'), - widget=forms.TimeInput( - format='%H:%M:%S', - attrs={ - 'placeholder': PLACEHOLDER1, - 'class': 'form-control', - } - ), - required=False, + initial=(datetime.now() - timedelta(6)).strftime(API_DATE_FORMAT_WITH_DAY_DATE_TIME), ) include_app_names = forms.CharField( label=_('Include App Names'), @@ -263,22 +219,11 @@ def __init__(self, *args, **kwargs): super(CustomSummaryForm, self).__init__(*args, **kwargs) class MonthlyMetricsSummaryForm(forms.Form): - to_date = forms.DateField( - label=_("To Date"), - widget=DatePickerInput(format=API_DATE_FORMAT_WITH_DAY), + to_date = forms.DateTimeField( + label=_(TO_DATE), + widget=DateTimePickerInput(format=API_DATE_FORMAT_WITH_DAY_DATE_TIME), required=True, - initial=str(datetime.now().strftime(API_DATE_FORMAT_WITH_DAY)), - ) - to_date_time = forms.TimeField( - label=_('Time'), - widget=forms.TimeInput( - format='%H:%M:%S', - attrs={ - 'placeholder': PLACEHOLDER1, - 'class': 'form-control', - } - ), - required=False, + initial=(datetime.now()).strftime(API_DATE_FORMAT_WITH_DAY_DATE_TIME), ) include_app_names = forms.CharField( label=_('Include App Names'), diff --git a/apimanager/metrics/templates/metrics/api.html b/apimanager/metrics/templates/metrics/api.html index 2c21e069..24d13c52 100644 --- a/apimanager/metrics/templates/metrics/api.html +++ b/apimanager/metrics/templates/metrics/api.html @@ -44,13 +44,6 @@