Enable serving of crashreport logfiles.
diff --git a/crashreports/admin.py b/crashreports/admin.py
index 76ecf6b..0697de1 100644
--- a/crashreports/admin.py
+++ b/crashreports/admin.py
@@ -4,5 +4,5 @@
@admin.register(Crashreport)
class CrashreportAdmin(admin.ModelAdmin):
- list_display = ['build_fingerprint', 'boot_reason', 'power_on_reason', 'power_off_reason', 'aux_data', 'date', 'uuid']
+ list_display = ['report_type', 'build_fingerprint', 'boot_reason', 'power_on_reason', 'power_off_reason', 'aux_data', 'date', 'uuid', 'crashreport_file_link']
pass
diff --git a/crashreports/models.py b/crashreports/models.py
index 2b72774..38d86ff 100644
--- a/crashreports/models.py
+++ b/crashreports/models.py
@@ -3,7 +3,7 @@
import datetime
def crashreport_file_name(instance, filename):
- return '/'.join(['saved_crashreports', instance.uuid, str(datetime.date.today().year), str(datetime.date.today().month), str(datetime.date.today().day), filename])
+ return '/'.join(["crashreport_uploads", instance.uuid, str(datetime.date.today().year), str(datetime.date.today().month), str(datetime.date.today().day), filename])
class Crashreport(models.Model):
@@ -17,4 +17,13 @@
power_off_reason = models.CharField(max_length=200)
aux_data = models.CharField(max_length=200)
date = models.DateTimeField()
- crashreport_file = models.FileField(upload_to=crashreport_file_name,null=True, blank=True)
+ crashreport_file = models.FileField(upload_to=crashreport_file_name, null=True, blank=True)
+
+ def crashreport_file_link(self):
+ if self.crashreport_file:
+ return '<a href="/hiccup/' + str(self.crashreport_file.url) + '">' + 'Logfile' + '</a>'
+ else:
+ return '<a href="''"></a>'
+
+ crashreport_file_link.allow_tags = True
+ crashreport_file_link.short_description = "File Link"
diff --git a/crashreports/urls.py b/crashreports/urls.py
index e121032..c07c620 100644
--- a/crashreports/urls.py
+++ b/crashreports/urls.py
@@ -3,11 +3,13 @@
from rest_framework import routers
from rest_framework import filters
+
router = routers.DefaultRouter()
router.register(r'crashreports', views.CrashreportViewSet)
urlpatterns = [
url(r'^crashreport/', views.index, name='index'),
url(r'^crashreports/hiccup_stats/', views.hiccup_stats, name='home'),
+ url(r'^crashreport_uploads/(?P<path>.*)$', views.serve_saved_crashreport, name='serve_saved_crashreport'),
url(r'^', include(router.urls)),
]
diff --git a/crashreports/views.py b/crashreports/views.py
index 068330e..96e8301 100644
--- a/crashreports/views.py
+++ b/crashreports/views.py
@@ -1,30 +1,35 @@
# -*- coding: utf-8 -*-
-from django.shortcuts import render_to_response
-from django.shortcuts import render
-from django.http import HttpResponseRedirect
-from django.http import HttpResponse
-from django.core.urlresolvers import reverse
-
-from crashreports.models import Crashreport
-from crashreports.forms import CrashreportForm
-from django.views.decorators.csrf import csrf_exempt
-from django.http import Http404
-
-from django.contrib.auth.decorators import login_required
-from django.db.models import Count
-from rest_framework import viewsets
-from serializers import CrashReportSerializer
-from rest_framework.permissions import BasePermission
-from rest_framework import filters
-from rest_framework import generics
-import django_filters
-from django.template import loader
import datetime
+import django_filters
+import os
import time
+from django.conf import settings
+from django.contrib.auth.decorators import login_required
+from django.core.urlresolvers import reverse
+from django.db.models import Count
+from django.http import Http404
+from django.http import HttpResponse
+from django.http import HttpResponseRedirect
+from django.shortcuts import render
+from django.shortcuts import render_to_response
+from django.template import loader
+from django.views.decorators.csrf import csrf_exempt
+from django.views.static import serve
+
from ratelimit.decorators import ratelimit
+from rest_framework import filters
+from rest_framework import generics
+from rest_framework import viewsets
+from rest_framework.permissions import BasePermission
+
+from crashreports.forms import CrashreportForm
+from crashreports.models import Crashreport
+from serializers import CrashReportSerializer
+
+
@ratelimit( key='ip', rate='100/h')
@csrf_exempt
def index(request):
@@ -71,6 +76,19 @@
template = loader.get_template('crashreports/hiccup_stats.html')
return HttpResponse(template.render({}, request))
+
+@login_required
+def serve_saved_crashreport (request, path):
+ if settings.DEBUG == False:
+ response = HttpResponse()
+ response["Content-Disposition"] = "attachment; filename={0}".format(
+ os.path.basename(path))
+ response['X-Accel-Redirect'] = "/hiccup/protected/{0}".format(path)
+ return response
+ else:
+ return serve(request, os.path.basename(path), os.path.dirname(settings.BASE_DIR + "/crashreport_uploads/" + path))
+
+
class IsCreationOrIsAuthenticated(BasePermission):
def has_permission(self, request, view):
if not request.user.is_authenticated():