From 53f84db2a92af251b3ee7beb79871a8deca46211 Mon Sep 17 00:00:00 2001 From: JianweiGao Date: Thu, 27 Sep 2018 23:38:17 +0800 Subject: [PATCH 1/2] Fix the datetime problem in "KPI Dashboard" of "Metrics" --- apimanager/metrics/views.py | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index da726e6..0b3f86b 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -205,7 +205,7 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView): """ for metric in metrics: metric['date'] = datetime.datetime.strptime( - metric['date'], '%Y-%m-%dT%H:%M:%S.%fZ') + metric['date'], API_DATEFORMAT) return metrics def to_api(self, cleaned_data): @@ -392,7 +392,7 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView): if cleaned_data.get('include_obp_apps'): while date_to <= to_date: urlpath = '/management/aggregate-metrics?from_date={}&to_date={}'.format( - date_from.strftime(API_DATEFORMAT)[:-4].__add__("Z"), date_to.strftime(API_DATEFORMAT)[:-4].__add__("Z")) + date_from.strftime(API_DATEFORMAT), date_to.strftime(API_DATEFORMAT)) api = API(self.request.session.get('obp')) try: metrics = api.get(urlpath) @@ -409,7 +409,7 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView): else: while date_to <= to_date: urlpath = '/management/aggregate-metrics?from_date={}&to_date={}&exclude_app_names={}'.format( - date_from.strftime(API_DATEFORMAT)[:-4].__add__("Z"), date_to.strftime(API_DATEFORMAT)[:-4].__add__("Z"), ",".join(EXCLUDE_APPS)) + date_from.strftime(API_DATEFORMAT), date_to.strftime(API_DATEFORMAT), ",".join(EXCLUDE_APPS)) api = API(self.request.session.get('obp')) try: metrics = api.get(urlpath) @@ -625,13 +625,10 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView): api = API(self.request.session.get('obp')) try: top_apps_using_warehouse = api.get(urlpath) + top_apps_using_warehouse = top_apps_using_warehouse["top_consumers"][:2] except APIError as err: messages.error(self.request, err) - top_apps_using_warehouse = top_apps_using_warehouse["top_consumers"][:2] - - - return top_apps_using_warehouse def median_time_to_first_api_call(self, from_date, to_date): @@ -650,7 +647,7 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView): for app in apps_list: created_date = datetime.datetime.strptime(app['created'], '%Y-%m-%dT%H:%M:%SZ') - created_date = created_date.strftime(API_DATEFORMAT)[:-4].__add__("Z") + created_date = created_date.strftime(API_DATEFORMAT) created_date = datetime.datetime.strptime(created_date, API_DATEFORMAT) if created_date >= datetime.datetime.strptime(from_date, API_DATEFORMAT): new_apps_list.append(app) @@ -684,9 +681,9 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView): form = self.get_form() to_date = datetime.datetime.strptime(form.data['to_date'], '%Y-%m-%d %H:%M:%S') - to_date = to_date.strftime(API_DATEFORMAT)[:-4].__add__("Z") + to_date = to_date.strftime(API_DATEFORMAT) - from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(30)).strftime(API_DATEFORMAT)[:-4].__add__("Z") + from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(30)).strftime(API_DATEFORMAT) context = super(MetricsSummaryView, self).get_context_data(**kwargs) api_host_name = API_HOST top_apps_using_warehouse = self.get_top_apps_using_warehouse(from_date, to_date) @@ -734,8 +731,8 @@ class YearlySummaryView(MetricsSummaryView): def get_context_data(self, **kwargs): form = self.get_form() to_date = datetime.datetime.strptime(form.data['to_date'], '%Y-%m-%d %H:%M:%S') - to_date = to_date.strftime(API_DATEFORMAT)[:-4].__add__("Z") - from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(365)).strftime(API_DATEFORMAT)[:-4].__add__("Z") + to_date = to_date.strftime(API_DATEFORMAT) + from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(365)).strftime(API_DATEFORMAT) context = super(YearlySummaryView, self).get_context_data(**kwargs) api_host_name = API_HOST @@ -784,8 +781,8 @@ class QuarterlySummaryView(MetricsSummaryView): def get_context_data(self, **kwargs): form = self.get_form() to_date = datetime.datetime.strptime(form.data['to_date'], '%Y-%m-%d %H:%M:%S') - to_date = to_date.strftime(API_DATEFORMAT)[:-4].__add__("Z") - from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(90)).strftime(API_DATEFORMAT)[:-4].__add__("Z") + to_date = to_date.strftime(API_DATEFORMAT) + from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(90)).strftime(API_DATEFORMAT) context = super(QuarterlySummaryView, self).get_context_data(**kwargs) api_host_name = API_HOST @@ -838,8 +835,8 @@ class WeeklySummaryView(MetricsSummaryView): def get_context_data(self, **kwargs): form = self.get_form() to_date = datetime.datetime.strptime(form.data['to_date'], '%Y-%m-%d %H:%M:%S') - to_date = to_date.strftime(API_DATEFORMAT)[:-4].__add__("Z") - from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(7)).strftime(API_DATEFORMAT)[:-4].__add__("Z") + to_date = to_date.strftime(API_DATEFORMAT) + from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(7)).strftime(API_DATEFORMAT) context = super(WeeklySummaryView, self).get_context_data(**kwargs) api_host_name = API_HOST @@ -890,8 +887,8 @@ class DailySummaryView(MetricsSummaryView): def get_context_data(self, **kwargs): form = self.get_form() to_date = datetime.datetime.strptime(form.data['to_date'], '%Y-%m-%d %H:%M:%S') - to_date = to_date.strftime(API_DATEFORMAT)[:-4].__add__("Z") - from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(1)).strftime(API_DATEFORMAT)[:-4].__add__("Z") + to_date = to_date.strftime(API_DATEFORMAT) + from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(1)).strftime(API_DATEFORMAT) context = super(DailySummaryView, self).get_context_data(**kwargs) api_host_name = API_HOST @@ -947,10 +944,10 @@ class CustomSummaryView(MetricsSummaryView): form = self.get_form() to_date = datetime.datetime.strptime(form.data['to_date'], '%Y-%m-%d %H:%M:%S') - to_date = to_date.strftime(API_DATEFORMAT)[:-4].__add__("Z") + to_date = to_date.strftime(API_DATEFORMAT) from_date = datetime.datetime.strptime(form.data['from_date_custom'], '%Y-%m-%d %H:%M:%S') - from_date = from_date.strftime(API_DATEFORMAT)[:-4].__add__("Z") + from_date = from_date.strftime(API_DATEFORMAT) context = super(CustomSummaryView, self).get_context_data(**kwargs) api_host_name = API_HOST top_apps_using_warehouse = self.get_top_apps_using_warehouse(from_date, to_date) From 8220547ecd85d6bfc5d6b2576a75f285963128cd Mon Sep 17 00:00:00 2001 From: JianweiGao Date: Mon, 1 Oct 2018 16:23:22 +0800 Subject: [PATCH 2/2] Added pagination for the users list page No longer load all users with "/users/all" to filter usernames and email Load the all entitlements with the "/entitlements" api instead of traversing all the users Set default value for the call limits inputs --- apimanager/consumers/forms.py | 5 ++ .../users/includes/filter_pagination.html | 11 +++++ apimanager/users/templates/users/index.html | 9 ++++ apimanager/users/views.py | 46 +++++++++++++------ requirements.txt | 3 +- 5 files changed, 58 insertions(+), 16 deletions(-) create mode 100644 apimanager/users/templates/users/includes/filter_pagination.html diff --git a/apimanager/consumers/forms.py b/apimanager/consumers/forms.py index 5d8e892..79f673b 100644 --- a/apimanager/consumers/forms.py +++ b/apimanager/consumers/forms.py @@ -19,6 +19,7 @@ class ApiConsumersForm(forms.Form): 'class': 'form-control', } ), + initial=-1, required=False, ) @@ -29,6 +30,7 @@ class ApiConsumersForm(forms.Form): 'class': 'form-control', } ), + initial=-1, required=False, ) per_day_call_limit = forms.IntegerField( @@ -38,6 +40,7 @@ class ApiConsumersForm(forms.Form): 'class': 'form-control', } ), + initial=-1, required=False, ) per_week_call_limit = forms.IntegerField( @@ -47,6 +50,7 @@ class ApiConsumersForm(forms.Form): 'class': 'form-control', } ), + initial=-1, required=False, ) @@ -57,5 +61,6 @@ class ApiConsumersForm(forms.Form): 'class': 'form-control', } ), + initial=-1, required=False, ) diff --git a/apimanager/users/templates/users/includes/filter_pagination.html b/apimanager/users/templates/users/includes/filter_pagination.html new file mode 100644 index 0000000..340a898 --- /dev/null +++ b/apimanager/users/templates/users/includes/filter_pagination.html @@ -0,0 +1,11 @@ +
+
+ + +
+
+ + +
+ +
\ No newline at end of file diff --git a/apimanager/users/templates/users/index.html b/apimanager/users/templates/users/index.html index e45476f..b7b1d92 100644 --- a/apimanager/users/templates/users/index.html +++ b/apimanager/users/templates/users/index.html @@ -28,6 +28,15 @@ + +
+
+ +

Pagination

+ {% include "users/includes/filter_pagination.html" %} +
+
+

Statistics