diff --git a/apimanager/apimanager/settings.py b/apimanager/apimanager/settings.py
index 3c463c73..2331e4a8 100644
--- a/apimanager/apimanager/settings.py
+++ b/apimanager/apimanager/settings.py
@@ -48,6 +48,7 @@
'oauth',
'consumers',
'users',
+ 'metrics',
#'api_calls',
#'api_config',
]
diff --git a/apimanager/apimanager/urls.py b/apimanager/apimanager/urls.py
index 3da51c82..ddec988f 100644
--- a/apimanager/apimanager/urls.py
+++ b/apimanager/apimanager/urls.py
@@ -13,6 +13,7 @@
url(r'^oauth/', include('oauth.urls')),
url(r'^consumers/', include('consumers.urls')),
url(r'^users/', include('users.urls')),
+ url(r'^metrics/', include('metrics.urls')),
#url(r'^api_calls/', include('api_calls.urls')),
#url(r'^api_config/', include('api_config.urls')),
]
diff --git a/apimanager/base/templates/base.html b/apimanager/base/templates/base.html
index b8b31261..4d786296 100644
--- a/apimanager/base/templates/base.html
+++ b/apimanager/base/templates/base.html
@@ -28,9 +28,11 @@
{% url "consumers-index" as consumers_index_url %}
- - Consumers
+ - Consumers
{% url "users-index" as users_index_url %}
- - Users
+ - Users
+ {% url "metrics-index" as metrics_index_url %}
+ - Metrics
{% comment %}
{% url "api-calls-grouped" as api_calls_grouped_url %}
- API Calls Grouped
diff --git a/apimanager/metrics/__init__.py b/apimanager/metrics/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/apimanager/metrics/apps.py b/apimanager/metrics/apps.py
new file mode 100644
index 00000000..31fa4c58
--- /dev/null
+++ b/apimanager/metrics/apps.py
@@ -0,0 +1,12 @@
+# -*- coding: utf-8 -*-
+"""
+App config for metrics app
+"""
+
+from django.apps import AppConfig
+
+
+
+class MetricsConfig(AppConfig):
+ """Config for metrics"""
+ name = 'metrics'
diff --git a/apimanager/metrics/static/metrics/css/metrics.css b/apimanager/metrics/static/metrics/css/metrics.css
new file mode 100644
index 00000000..707f121b
--- /dev/null
+++ b/apimanager/metrics/static/metrics/css/metrics.css
@@ -0,0 +1,15 @@
+#metrics form {
+ margin-bottom: 10px;
+}
+
+#metrics #metrics-list {
+ margin-top: 20px;
+}
+
+#metrics #metrics-list ul {
+ margin-left: -25px;
+}
+
+#metrics .noborder {
+ border: none;
+}
diff --git a/apimanager/metrics/static/metrics/js/metrics.js b/apimanager/metrics/static/metrics/js/metrics.js
new file mode 100644
index 00000000..8da04639
--- /dev/null
+++ b/apimanager/metrics/static/metrics/js/metrics.js
@@ -0,0 +1,2 @@
+$(document).ready(function($) {
+});
diff --git a/apimanager/metrics/templates/metrics/index.html b/apimanager/metrics/templates/metrics/index.html
new file mode 100644
index 00000000..cef21f88
--- /dev/null
+++ b/apimanager/metrics/templates/metrics/index.html
@@ -0,0 +1,166 @@
+{% extends 'base.html' %}
+{% load static %}
+
+{% block page_title %}{{ block.super }} / Metrics{% endblock page_title %}
+
+{% block content %}
+
+
Metrics
+
+
Filter
+
+
+
+
+
+
+ # |
+ Verb |
+ URL |
+ Date |
+
+
+
+ {% for metric in metrics %}
+
+ {{ forloop.counter }} |
+ {{ metric.verb }} |
+
+ {{ metric.url }}
+ |
+ {{ metric.date|date:"Y-m-d H:m:s" }} |
+
+
+
+
+ - User Name: {{ metric.user_name }}
+ - User ID: {{ metric.user_id }}
+ - Developer Email: {{ metric.developer_email }}
+ - App Name: {{ metric.app_name }}
+ - Consumer ID: {{ metric.consumer_id }}
+ - Implemented by Partial Function: {{ metric.implemented_by_partial_function }}
+ - Implemented In Version: {{ metric.implemented_in_version }}
+
+ |
+
+ {% endfor %}
+
+
+
+
+{% endblock %}
+
+{% block extrajs %}
+{% comment %}
+
+
+{% endcomment %}
+{% endblock extrajs %}
+
+
+{% block extracss %}
+
+{% endblock extracss %}
diff --git a/apimanager/metrics/urls.py b/apimanager/metrics/urls.py
new file mode 100644
index 00000000..816d6d74
--- /dev/null
+++ b/apimanager/metrics/urls.py
@@ -0,0 +1,14 @@
+# -*- coding: utf-8 -*-
+"""
+URLs for metrics app
+"""
+
+from django.conf.urls import url
+
+from .views import IndexView
+
+urlpatterns = [
+ url(r'^$',
+ IndexView.as_view(),
+ name='metrics-index'),
+]
diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py
new file mode 100644
index 00000000..4f8ae8ca
--- /dev/null
+++ b/apimanager/metrics/views.py
@@ -0,0 +1,56 @@
+# -*- coding: utf-8 -*-
+"""
+Views of metrics app
+"""
+
+from datetime import datetime
+
+from django.conf import settings
+from django.contrib import messages
+from django.contrib.auth.mixins import LoginRequiredMixin
+from django.views.generic import TemplateView
+
+from base.api import api, APIError
+
+
+
+class IndexView(LoginRequiredMixin, TemplateView):
+ """Index view for metrics"""
+ template_name = "metrics/index.html"
+
+ def scrub(self, metrics):
+ """Scrubs data in the given consumers to adher to certain formats"""
+ for metric in metrics:
+ metric['date'] = datetime.strptime(
+ metric['date'], settings.API_DATETIMEFORMAT)
+ return metrics
+
+
+ def get_params(self, request_get):
+ """
+ API treats empty parameters as actual values, so we have to filter
+ them out
+ """
+ querydict = request_get.copy()
+ keys = list(querydict.keys())
+ for key in keys:
+ if not querydict[key]:
+ querydict.pop(key)
+ return querydict.urlencode()
+
+
+ def get_context_data(self, **kwargs):
+ context = super(IndexView, self).get_context_data(**kwargs)
+ metrics = []
+ params = self.get_params(self.request.GET)
+ try:
+ urlpath = '/management/metrics?{}'.format(params)
+ metrics = api.get(self.request, urlpath)
+ metrics = self.scrub(metrics['metrics'])
+ except APIError as err:
+ messages.error(self.request, err)
+
+ context.update({
+ 'metrics': metrics,
+ })
+ return context