repos
/ analytics-django master

analytics-django

mirror archived upstream

Self-hostable website analytics on Django: a straightforward collector API, dashboards, a world map, and PDF reports.

analyticsdjangodockerhandcodedpythonself-hostedsqliteviteweb-analytics

2.3 KB · 67 lines · Python Raw History
 1from django.shortcuts import render, redirect
 2from django.http import HttpResponse
 3
 4from properties.models import Event, Property
 5from accounts.models import User
 6
 7
 8def home(request):
 9    if request.user.is_authenticated:
10        return redirect('properties')
11
12    context = {}
13    context['title'] = 'Home'
14    context['description'] = 'Made by Isaac Bythewood, simple analytics for people who want to host their own and hack on it a bit.'
15
16    total_events = Event.objects.all().count()
17    context['total_events'] = total_events
18
19    total_properties = Property.objects.all().count()
20    context['total_properties'] = total_properties
21
22    total_users = User.objects.all().count()
23    context['total_users'] = total_users
24
25    first_event_created_at = Event.objects.all().order_by('created_at').first().created_at
26    context['first_event_created_at'] = first_event_created_at
27
28    return render(request, 'pages/home.html', context)
29
30
31def changelog(request):
32    context = {}
33    context['title'] = 'Changelog'
34    context['description'] = 'An ongoing changelog and upcoming list of features for Analytics.'
35    return render(request, 'pages/changelog.html', context)
36
37
38def documentation(request):
39    context = {}
40    context['title'] = 'Documentation'
41    context['description'] = 'Documentation for Analytics.'
42    return render(request, 'pages/documentation.html', context)
43
44
45def favicon(request):
46    # Rising-bars mark — a four-bar histogram in mossy green with an amber
47    # cap on the tallest column. Matches the in-app logo, evokes "aggregate
48    # counts over time" which is what Analytics actually tracks.
49    svg = (
50        '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">'
51        '<rect x="6"  y="38" width="10" height="22" rx="1.5" fill="#6b9e78"/>'
52        '<rect x="20" y="28" width="10" height="32" rx="1.5" fill="#6b9e78"/>'
53        '<rect x="34" y="18" width="10" height="42" rx="1.5" fill="#6b9e78"/>'
54        '<rect x="48" y="8"  width="10" height="52" rx="1.5" fill="#6b9e78"/>'
55        '<rect x="48" y="8"  width="10" height="6"  rx="1.5" fill="#c9a84c"/>'
56        "</svg>"
57    )
58    return HttpResponse(svg, content_type="image/svg+xml")
59
60
61def robots(request):
62    return render(request, 'robots.txt', content_type='text/plain')
63
64
65def sitemap(request):
66    return render(request, 'sitemap.xml', content_type='text/xml')