Skip to content

Commit

Permalink
Merge pull request #344 from hongwei1/develop
Browse files Browse the repository at this point in the history
bugfix/fixed error handling and the time field on metrics
  • Loading branch information
simonredfern authored Nov 30, 2023
2 parents 368a695 + ff2b203 commit 6c46e9f
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 202 deletions.
3 changes: 3 additions & 0 deletions apimanager/apimanager/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 0 additions & 6 deletions apimanager/banks/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions apimanager/base/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down
4 changes: 2 additions & 2 deletions apimanager/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
101 changes: 23 additions & 78 deletions apimanager/metrics/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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'),
Expand All @@ -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'),
Expand Down
7 changes: 0 additions & 7 deletions apimanager/metrics/templates/metrics/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ <h2>{% trans "Filter" %}</h2>
{{ form.to_date }}
</div>
</div>
<div class="col-xs-6 col-sm-3">
{% if form.to_date_time.errors %}<div class="alert alert-danger">{{ form.to_date_time.errors }}</div>{% endif %}
<div class="form-group">
{{ form.to_date_time.label_tag }}
{{ form.to_date_time }}
</div>
</div>
</div>

<div class="row">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
{% load i18n %}

{% block nav_tabs %}
<ul>
<li><a href="{% url 'api-metrics' %}?{{ request.GET.urlencode }}">{% trans "List" %}</a></li>
<li><a href="{% url 'api-metrics-summary-partial-function' %}?{{ request.GET.urlencode }}">{% trans "Summary by Partial Function" %}</a></li>
</ul>
{% endblock nav_tabs %}

{% block tab_content %}
Expand Down
18 changes: 0 additions & 18 deletions apimanager/metrics/templates/metrics/custom_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ <h2>{% trans "Custom Date Range " %}</h2>
</div>
<!--<div class="col-xs-6 col-sm-3">
{% if form.from_time_custom.errors %}<div class="alert alert-danger">{{ form.from_time_custom.errors }}</div>{% endif %}
<div class="form-group">
<strong>{% trans "From Time" %} </strong>
{{ form.from_time_custom }}
</div>
</div>-->
<div class="col-xs-6 col-sm-3">
{% if form.to_date.errors %}<div class="alert alert-danger">{{ form.to_date.errors }}</div>{% endif %}
Expand All @@ -56,20 +52,6 @@ <h2>{% trans "Custom Date Range " %}</h2>
{{ form.to_date }}
</div>
</div>
<!--<div class="col-xs-6 col-sm-3">
{% if form.to_date_time.errors %}<div class="alert alert-danger">{{ form.to_date_time.errors }}</div>{% endif %}
<div class="form-group">
<strong>{% trans "To Time" %} </strong>
{{ form.to_date_time }}
</div>
</div>-->
<div class="col-xs-4 col-sm-3">
{% if form.include_app_names.errors %}<div class="alert alert-danger">{{ form.include_app_names.errors }}</div>{% endif %}
<div class="form-group">
{{ form.include_app_names.label_tag }}
{{ form.include_app_names }}
</div>
</div>
</div>
<button type="submit" class="btn btn-primary">{% trans "Search" %}</button>
</form>
Expand Down
7 changes: 0 additions & 7 deletions apimanager/metrics/templates/metrics/daily_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ <h2>{% trans "Day" %}</h2>
{{ form.to_date }}
</div>
</div>
<!--<div class="col-xs-4 col-sm-3">
{% if form.to_date_time.errors %}<div class="alert alert-danger">{{ form.to_date_time.errors }}</div>{% endif %}
<div class="form-group">
{{ form.to_date_time.label_tag }}
{{ form.to_date_time }}
</div>
</div>-->
<div class="col-xs-4 col-sm-3">
{% if form.include_app_names.errors %}<div class="alert alert-danger">{{ form.include_app_names.errors }}</div>{% endif %}
<div class="form-group">
Expand Down
7 changes: 0 additions & 7 deletions apimanager/metrics/templates/metrics/hourly_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ <h2>{% trans "Hour" %}</h2>
{{ form.to_date }}
</div>
</div>
<!--<div class="col-xs-4 col-sm-3">
{% if form.to_date_time.errors %}<div class="alert alert-danger">{{ form.to_date_time.errors }}</div>{% endif %}
<div class="form-group">
{{ form.to_date_time.label_tag }}
{{ form.to_date_time }}
</div>
</div>-->
<div class="col-xs-4 col-sm-3">
{% if form.include_app_names.errors %}<div class="alert alert-danger">{{ form.include_app_names.errors }}</div>{% endif %}
<div class="form-group">
Expand Down
9 changes: 0 additions & 9 deletions apimanager/metrics/templates/metrics/monthly_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,13 @@ <h2>{% trans "Month" %}</h2>
{% endif %}

<div class="row">

<div class="col-xs-6 col-sm-3">
{% if form.to_date.errors %}<div class="alert alert-danger">{{ form.to_date.errors }}</div>{% endif %}
<div class="form-group">
<strong>{% trans "To Date" %} </strong>
{{ form.to_date }}
</div>
</div>
<!--<div class="col-xs-4 col-sm-3">
{% if form.to_date_time.errors %}<div class="alert alert-danger">{{ form.to_date_time.errors }}</div>{% endif %}
<div class="form-group">
{{ form.to_date_time.label_tag }}
{{ form.to_date_time }}
</div>
</div>-->

<div class="col-xs-4 col-sm-3">
{% if form.include_app_names.errors %}<div class="alert alert-danger">{{ form.include_app_names.errors }}</div>{% endif %}
<div class="form-group">
Expand Down
8 changes: 0 additions & 8 deletions apimanager/metrics/templates/metrics/quarterly_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ <h2>{% trans "Quarter" %}</h2>
{{ form.to_date }}
</div>
</div>
<!--<div class="col-xs-4 col-sm-3">
{% if form.to_date_time.errors %}<div class="alert alert-danger">{{ form.to_date_time.errors }}</div>{% endif %}
<div class="form-group">
{{ form.to_date_time.label_tag }}
{{ form.to_date_time }}
</div>
</div>-->

<div class="col-xs-4 col-sm-3">
{% if form.include_app_names.errors %}<div class="alert alert-danger">{{ form.include_app_names.errors }}</div>{% endif %}
<div class="form-group">
Expand Down
8 changes: 0 additions & 8 deletions apimanager/metrics/templates/metrics/weekly_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ <h2>{% trans "Week" %}</h2>
{{ form.to_date }}
</div>
</div>
<!--<div class="col-xs-4 col-sm-3">
{% if form.to_date_time.errors %}<div class="alert alert-danger">{{ form.to_date_time.errors }}</div>{% endif %}
<div class="form-group">
{{ form.to_date_time.label_tag }}
{{ form.to_date_time }}
</div>
</div>-->

<div class="col-xs-4 col-sm-3">
{% if form.include_app_names.errors %}<div class="alert alert-danger">{{ form.include_app_names.errors }}</div>{% endif %}
<div class="form-group">
Expand Down
7 changes: 0 additions & 7 deletions apimanager/metrics/templates/metrics/yearly_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ <h2>{% trans "Year" %}</h2>
{{ form.to_date }}
</div>
</div>
<!--<div class="col-xs-4 col-sm-3">
{% if form.to_date_time.errors %}<div class="alert alert-danger">{{ form.to_date_time.errors }}</div>{% endif %}
<div class="form-group">
{{ form.to_date_time.label_tag }}
{{ form.to_date_time }}
</div>
</div>-->
<div class="col-xs-4 col-sm-3">
{% if form.include_app_names.errors %}<div class="alert alert-danger">{{ form.include_app_names.errors }}</div>{% endif %}
<div class="form-group">
Expand Down
Loading

0 comments on commit 6c46e9f

Please sign in to comment.