blob: 9ec7dc6409fc53cc469b4f8e50efc137615e5cad [file] [log] [blame]
Dirk Vogt62ff7f22017-05-04 16:07:21 +02001from crashreports.models import *
Dirk Vogt57a615d2017-05-04 22:29:54 +02002from django.http import HttpResponse,Http404,HttpResponseRedirect
Dirk Vogt62ff7f22017-05-04 16:07:21 +02003from django.shortcuts import render
4from django.shortcuts import render_to_response
5from django.template import loader
6from itertools import chain
7from django.db import connection
Dirk Vogtb0b8b512017-12-05 14:46:03 +01008from crashreport_stats import raw_querys
Dirk Vogt62ff7f22017-05-04 16:07:21 +02009from django.contrib.auth.decorators import user_passes_test
Dirk Vogt57a615d2017-05-04 22:29:54 +020010from django import forms
11from django.contrib import messages
12from django.urls import reverse
Dirk Vogt62ff7f22017-05-04 16:07:21 +020013
14def is_fairphone_staff(user):
15 return user.groups.filter(name='FairphoneSoftwareTeam').exists()
16
Dirk Vogt57a615d2017-05-04 22:29:54 +020017
18class DeviceUUIDForm(forms.Form):
19 uuid = forms.CharField(label='Device UUID:', max_length=100)
20
Dirk Vogt62ff7f22017-05-04 16:07:21 +020021@user_passes_test(is_fairphone_staff)
22def device_stats(request):
23 template = loader.get_template('crashreport_stats/device.html')
24 uuid = request.GET.get('uuid', "NO_UUID")
Dirk Vogt57a615d2017-05-04 22:29:54 +020025 if not Device.objects.filter(uuid=uuid).exists():
26 raise Http404("Device doesn't exist.")
Dirk Vogt62ff7f22017-05-04 16:07:21 +020027 return HttpResponse(template.render({'uuid':uuid}, request))
Dirk Vogt1accb672017-05-10 14:07:42 +020028
29@user_passes_test(is_fairphone_staff)
30def versions_all_overview(request):
31 template = loader.get_template('crashreport_stats/versions.html')
32 return HttpResponse(template.render({"is_official_release":"1"}, request))
33
34@user_passes_test(is_fairphone_staff)
35def versions_overview(request):
36 template = loader.get_template('crashreport_stats/versions.html')
37 return HttpResponse(template.render({"is_official_release":"2"}, request))
38
Dirk Vogt57a615d2017-05-04 22:29:54 +020039@user_passes_test(is_fairphone_staff)
40def home(request):
Dirk Vogtb0b8b512017-12-05 14:46:03 +010041 """ The home view allows to search for devices. """
42 devices = None
Dirk Vogt57a615d2017-05-04 22:29:54 +020043 if request.method == 'POST':
44 # create a form instance and populate it with data from the request:
45 form = DeviceUUIDForm(request.POST)
46 if form.is_valid():
47 uuid = form.cleaned_data['uuid']
48 if not Device.objects.filter(uuid=uuid).exists():
Dirk Vogtb0b8b512017-12-05 14:46:03 +010049 devices = Device.objects.filter(uuid__startswith=uuid)
50 if len(devices)==1:
51 return HttpResponseRedirect(
52 reverse("hiccup_stats_device")+'?uuid='+devices[0].uuid)
53 elif len(devices)==0:
54 messages.warning(request, "No devices found.")
Dirk Vogt57a615d2017-05-04 22:29:54 +020055 else:
Dirk Vogtb0b8b512017-12-05 14:46:03 +010056 return HttpResponseRedirect(
57 reverse("hiccup_stats_device")+'?uuid='+uuid)
Dirk Vogt57a615d2017-05-04 22:29:54 +020058 else:
59 form = DeviceUUIDForm()
60 template = loader.get_template('crashreport_stats/home.html')
Dirk Vogtb0b8b512017-12-05 14:46:03 +010061 return HttpResponse(template.render(
62 {'form':form, 'devices':devices}
63 , request))