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 @@

{% trans "Filter" %}

{{ form.to_date }} -
- {% if form.to_date_time.errors %}
{{ form.to_date_time.errors }}
{% endif %} -
- {{ form.to_date_time.label_tag }} - {{ form.to_date_time }} -
-
diff --git a/apimanager/metrics/templates/metrics/api_summary_partial_function.html b/apimanager/metrics/templates/metrics/api_summary_partial_function.html index 733068c6..5c7766fb 100644 --- a/apimanager/metrics/templates/metrics/api_summary_partial_function.html +++ b/apimanager/metrics/templates/metrics/api_summary_partial_function.html @@ -3,8 +3,10 @@ {% load i18n %} {% block nav_tabs %} + {% endblock nav_tabs %} {% block tab_content %} diff --git a/apimanager/metrics/templates/metrics/custom_summary.html b/apimanager/metrics/templates/metrics/custom_summary.html index 5949688d..0313f5c3 100644 --- a/apimanager/metrics/templates/metrics/custom_summary.html +++ b/apimanager/metrics/templates/metrics/custom_summary.html @@ -44,10 +44,6 @@

{% trans "Custom Date Range " %}

{% if form.to_date.errors %}
{{ form.to_date.errors }}
{% endif %} @@ -56,20 +52,6 @@

{% trans "Custom Date Range " %}

{{ form.to_date }}
- -
- {% if form.include_app_names.errors %}
{{ form.include_app_names.errors }}
{% endif %} -
- {{ form.include_app_names.label_tag }} - {{ form.include_app_names }} -
-
diff --git a/apimanager/metrics/templates/metrics/daily_summary.html b/apimanager/metrics/templates/metrics/daily_summary.html index bff34f1c..17053b6a 100644 --- a/apimanager/metrics/templates/metrics/daily_summary.html +++ b/apimanager/metrics/templates/metrics/daily_summary.html @@ -49,13 +49,6 @@

{% trans "Day" %}

{{ form.to_date }} -
{% if form.include_app_names.errors %}
{{ form.include_app_names.errors }}
{% endif %}
diff --git a/apimanager/metrics/templates/metrics/hourly_summary.html b/apimanager/metrics/templates/metrics/hourly_summary.html index 5abd80ef..be0d6416 100644 --- a/apimanager/metrics/templates/metrics/hourly_summary.html +++ b/apimanager/metrics/templates/metrics/hourly_summary.html @@ -48,13 +48,6 @@

{% trans "Hour" %}

{{ form.to_date }}
-
{% if form.include_app_names.errors %}
{{ form.include_app_names.errors }}
{% endif %}
diff --git a/apimanager/metrics/templates/metrics/monthly_summary.html b/apimanager/metrics/templates/metrics/monthly_summary.html index 8bae1f1e..d5d2724d 100644 --- a/apimanager/metrics/templates/metrics/monthly_summary.html +++ b/apimanager/metrics/templates/metrics/monthly_summary.html @@ -36,7 +36,6 @@

{% trans "Month" %}

{% endif %}
-
{% if form.to_date.errors %}
{{ form.to_date.errors }}
{% endif %}
@@ -44,14 +43,6 @@

{% trans "Month" %}

{{ form.to_date }}
- -
{% if form.include_app_names.errors %}
{{ form.include_app_names.errors }}
{% endif %}
diff --git a/apimanager/metrics/templates/metrics/quarterly_summary.html b/apimanager/metrics/templates/metrics/quarterly_summary.html index 4a9d759c..d65b1868 100644 --- a/apimanager/metrics/templates/metrics/quarterly_summary.html +++ b/apimanager/metrics/templates/metrics/quarterly_summary.html @@ -48,14 +48,6 @@

{% trans "Quarter" %}

{{ form.to_date }}
- -
{% if form.include_app_names.errors %}
{{ form.include_app_names.errors }}
{% endif %}
diff --git a/apimanager/metrics/templates/metrics/weekly_summary.html b/apimanager/metrics/templates/metrics/weekly_summary.html index 9812cd1c..78095708 100644 --- a/apimanager/metrics/templates/metrics/weekly_summary.html +++ b/apimanager/metrics/templates/metrics/weekly_summary.html @@ -50,14 +50,6 @@

{% trans "Week" %}

{{ form.to_date }}
- -
{% if form.include_app_names.errors %}
{{ form.include_app_names.errors }}
{% endif %}
diff --git a/apimanager/metrics/templates/metrics/yearly_summary.html b/apimanager/metrics/templates/metrics/yearly_summary.html index 2dd93228..acc45e04 100644 --- a/apimanager/metrics/templates/metrics/yearly_summary.html +++ b/apimanager/metrics/templates/metrics/yearly_summary.html @@ -50,13 +50,6 @@

{% trans "Year" %}

{{ form.to_date }}
-
{% if form.include_app_names.errors %}
{{ form.include_app_names.errors }}
{% endif %}
diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index c493c614..587e3b14 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -149,16 +149,10 @@ def get_metrics(self, cleaned_data): metrics = api.get(urlpath) metrics = self.to_django(metrics['metrics']) except APIError as err: - if DEBUG: - raise(err) error_once_only(self.request, err) except KeyError as err: - if DEBUG: - raise(err) error_once_only(self.request, metrics['message']) except Exception as err: - if DEBUG: - raise(err) error_once_only(self.request, err) return metrics @@ -352,12 +346,8 @@ def get_aggregate_metrics(self, from_date, to_date, include_app_names): api_calls_total, average_response_time, cache_key, from_date, metrics, to_date, url_path) return api_calls_total, average_response_time, int(average_calls_per_day) except APIError as err: - if DEBUG: - raise(err) error_once_only(self.request, err) except Exception as err: - if DEBUG: - raise(err) error_once_only(self.request, err) def get_internal_api_call_metrics(self, api_calls_total, average_response_time, cache_key, from_date, metrics, @@ -389,8 +379,6 @@ def get_active_apps(self, from_date, to_date): except APIError as err: error_once_only(self.request, err) except Exception as err: - if DEBUG: - raise(err) error_once_only(self.request, err) else: urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}&exclude_implemented_by_partial_functions={}&exclude_url_pattern={}'.format( @@ -400,12 +388,8 @@ def get_active_apps(self, from_date, to_date): apps = api.get(urlpath) active_apps_list = list(apps['top_consumers']) except APIError as err: - if DEBUG: - raise(err) error_once_only(self.request, err) except Exception as err: - if DEBUG: - raise(err) error_once_only(self.request, err) return active_apps_list @@ -469,12 +453,8 @@ def get_all_consumers(self): LOGGER.warning('{0}: {1}'.format(CACHE_SETTING_URL_MSG, urlpath)) LOGGER.warning('{0}: {1}'.format(CACHE_SETTING_KEY_MSG, cache_key)) except APIError as err: - if DEBUG: - raise(err) error_once_only(self.request, err) except Exception as err: - if DEBUG: - raise(err) error_once_only(self.request, err) return apps_list @@ -504,8 +484,6 @@ def calls_per_delta(self, from_date_string, to_date_string, include_app_names, * result_list.append('{} - {} # {}'.format(from_datetime_object, time_delta_in_loop, result)) date_list.append(from_datetime_object) except Exception as err: - if DEBUG: - raise(err) error_once_only(self.request, err) break @@ -688,8 +666,6 @@ def get_users_cansearchwarehouse(self): except KeyError as err: messages.error(self.request, 'KeyError: {}'.format(err)) except Exception as err: - if DEBUG: - raise(err) error_once_only(self.request, err) user_email_cansearchwarehouse = dict(zip(users_with_cansearchwarehouse, email_with_cansearchwarehouse)) @@ -714,12 +690,8 @@ def _api_data(self, urlpath, data_key): else: data = data[data_key] except APIError as err: - if DEBUG: - raise(err) error_once_only(self.request, err) except Exception as err: - if DEBUG: - raise(err) error_once_only(self.request, err) return data @@ -772,12 +744,8 @@ def get_top_warehouse_calls(self, cleaned_data, from_date, to_date): if "elasticSearchWarehouse" in api['Implemented_by_partial_function']: top_warehouse_calls.append(api) except APIError as err: - if DEBUG: - raise(err) error_once_only(self.request, err) except Exception as err: - if DEBUG: - raise(err) error_once_only(self.request, err) return top_warehouse_calls @@ -795,12 +763,8 @@ def get_top_apps_using_warehouse(self, from_date, to_date): else: top_apps_using_warehouse = top_apps_using_warehouse["top_consumers"][:2] except APIError as err: - if DEBUG: - raise(err) error_once_only(self.request, err) except Exception as err: - if DEBUG: - raise(err) error_once_only(self.request, err) return top_apps_using_warehouse @@ -857,12 +821,8 @@ def median_time_to_first_api_call(self, from_date, to_date): except APIError as err: - if DEBUG: - raise(err) error_once_only(self.request, err) except Exception as err: - if DEBUG: - raise(err) error_once_only(self.request, 'Unknown Error. {}'.format(err)) if times_to_first_call: @@ -893,7 +853,6 @@ def prepare_general_context(self, web_page_type, **kwargs): print(form.data, "Form data") to_date = convert_form_date_to_obpapi_datetime_format(form_to_date_string) print("to_date", to_date) - #to_date = datetime.datetime.strptime(f"{form.data['to_date']}T{form.data['to_date_time']}Z", API_DATE_FORMAT_WITH_SECONDS ).strftime(API_DATE_FORMAT_WITH_MILLISECONDS) if (web_page_type == SummaryType.DAILY): # for one day, the from_date is 1 day ago. from_date = return_to_days_ago(to_date, 0) @@ -981,8 +940,6 @@ def prepare_general_context(self, web_page_type, **kwargs): else: error_once_only(self.request, str(form.errors)) except Exception as err: - if DEBUG: - raise(err) error_once_only(self.request, err) def _daily_and_weekly(self, web_page_type,to_date, per_hour_chart, per_day_chart, from_date): if (web_page_type == SummaryType.DAILY):