forked from CGM_Public/pretix_original
Added basic statistics
This commit is contained in:
22
src/pretix/plugins/statistics/__init__.py
Normal file
22
src/pretix/plugins/statistics/__init__.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from django.apps import AppConfig
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from pretix.base.plugins import PluginType
|
||||
|
||||
|
||||
class StatisticsApp(AppConfig):
|
||||
name = 'pretix.plugins.statistics'
|
||||
verbose_name = _("Statistics")
|
||||
|
||||
class PretixPluginMeta:
|
||||
type = PluginType.ADMINFEATURE
|
||||
name = _("Display various statistics")
|
||||
author = _("the pretix team")
|
||||
version = '1.0.0'
|
||||
description = _("This plugin shows you various statistics.")
|
||||
|
||||
def ready(self):
|
||||
from . import signals # NOQA
|
||||
|
||||
|
||||
default_app_config = 'pretix.plugins.statistics.StatisticsApp'
|
||||
36
src/pretix/plugins/statistics/signals.py
Normal file
36
src/pretix/plugins/statistics/signals.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from django.core.urlresolvers import resolve, reverse
|
||||
from django.dispatch import receiver
|
||||
from django.template import Context
|
||||
from django.template.loader import get_template
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from pretix.control.signals import nav_event, html_head
|
||||
|
||||
|
||||
@receiver(nav_event)
|
||||
def control_nav_import(sender, request=None, **kwargs):
|
||||
url = resolve(request.path_info)
|
||||
if not request.eventperm.can_view_orders:
|
||||
return []
|
||||
return [
|
||||
{
|
||||
'label': _('Statistics'),
|
||||
'url': reverse('plugins:statistics:index', kwargs={
|
||||
'event': request.event.slug,
|
||||
'organizer': request.event.organizer.slug,
|
||||
}),
|
||||
'active': (url.namespace == 'plugins:statistics'),
|
||||
'icon': 'bar-chart',
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@receiver(html_head)
|
||||
def html_head_presale(sender, request=None, **kwargs):
|
||||
url = resolve(request.path_info)
|
||||
if url.namespace == 'plugins:statistics':
|
||||
template = get_template('pretixplugins/statistics/control_head.html')
|
||||
ctx = Context({})
|
||||
return template.render(ctx)
|
||||
else:
|
||||
return ""
|
||||
@@ -0,0 +1,2 @@
|
||||
.morris-hover{position:absolute;z-index:1000}.morris-hover.morris-default-style{border-radius:10px;padding:6px;color:#666;background:rgba(255,255,255,0.8);border:solid 2px rgba(230,230,230,0.8);font-family:sans-serif;font-size:12px;text-align:center}.morris-hover.morris-default-style .morris-hover-row-label{font-weight:bold;margin:0.25em 0}
|
||||
.morris-hover.morris-default-style .morris-hover-point{white-space:nowrap;margin:0.1em 0}
|
||||
7
src/pretix/plugins/statistics/static/pretixplugins/statistics/morris.min.js
vendored
Normal file
7
src/pretix/plugins/statistics/static/pretixplugins/statistics/morris.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
10
src/pretix/plugins/statistics/static/pretixplugins/statistics/raphael-min.js
vendored
Normal file
10
src/pretix/plugins/statistics/static/pretixplugins/statistics/raphael-min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,6 @@
|
||||
{% load staticfiles %}
|
||||
{% load compress %}
|
||||
|
||||
{% compress css %}
|
||||
<link type="text/css" rel="stylesheet" href="{% static "pretixplugins/statistics/morris.css" %}">
|
||||
{% endcompress %}
|
||||
@@ -0,0 +1,24 @@
|
||||
{% extends "pretixcontrol/event/base.html" %}
|
||||
{% load i18n %}
|
||||
{% load compress %}
|
||||
{% load staticfiles %}
|
||||
{% block title %}{% trans "Statistics" %}{% endblock %}
|
||||
{% block content %}
|
||||
<h1>{% trans "Statistics" %}</h1>
|
||||
<h3>{% trans "Orders by day" %}</h3>
|
||||
<div id="obd_chart" style="height: 250px;"></div>
|
||||
{% compress js %}
|
||||
<script type="text/javascript" src="{% static "pretixplugins/statistics/raphael-min.js" %}"></script>
|
||||
<script type="text/javascript" src="{% static "pretixplugins/statistics/morris.min.js" %}"></script>
|
||||
{% endcompress %}
|
||||
<script type="text/javascript">
|
||||
new Morris.Line({
|
||||
element: 'obd_chart',
|
||||
data: {{ obd_data|safe }},
|
||||
xkey: 'date',
|
||||
ykeys: ['ordered', 'paid'],
|
||||
labels: ['{% trans "Placed orders" %}', '{% trans "Paid orders" %}']
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
8
src/pretix/plugins/statistics/urls.py
Normal file
8
src/pretix/plugins/statistics/urls.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from django.conf.urls import url
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^control/event/(?P<organizer>[^/]+)/(?P<event>[^/]+)/statistics/', views.IndexView.as_view(),
|
||||
name='index'),
|
||||
]
|
||||
44
src/pretix/plugins/statistics/views.py
Normal file
44
src/pretix/plugins/statistics/views.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import json
|
||||
from django.db.models import Count
|
||||
from django.views.generic import TemplateView
|
||||
import dateutil.parser
|
||||
import dateutil.rrule
|
||||
from pretix.base.models import Order
|
||||
|
||||
from pretix.control.permissions import EventPermissionRequiredMixin
|
||||
|
||||
|
||||
class IndexView(EventPermissionRequiredMixin, TemplateView):
|
||||
template_name = 'pretixplugins/statistics/index.html'
|
||||
permission = 'can_view_orders'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
ctx = super().get_context_data(**kwargs)
|
||||
|
||||
ordered_by_day = {
|
||||
dateutil.parser.parse(o['datetime']).date(): o['count']
|
||||
for o in
|
||||
Order.objects.current.filter(event=self.request.event).extra({'datetime': "date(datetime)"}).values(
|
||||
'datetime').annotate(count=Count('id'))
|
||||
}
|
||||
paid_by_day = {
|
||||
o['payment_date'].date(): o['count']
|
||||
for o in
|
||||
Order.objects.current.filter(event=self.request.event, payment_date__isnull=False).values(
|
||||
'payment_date').annotate(count=Count('id'))
|
||||
}
|
||||
data = []
|
||||
for d in dateutil.rrule.rrule(
|
||||
dateutil.rrule.DAILY,
|
||||
dtstart=min(ordered_by_day.keys()),
|
||||
until=max(max(ordered_by_day.keys()), max(paid_by_day.keys()))):
|
||||
d = d.date()
|
||||
data.append({
|
||||
'date': d.strftime('%Y-%m-%d'),
|
||||
'ordered': ordered_by_day.get(d, 0),
|
||||
'paid': paid_by_day.get(d, 0)
|
||||
})
|
||||
|
||||
ctx['obd_data'] = json.dumps(data)
|
||||
|
||||
return ctx
|
||||
Reference in New Issue
Block a user