Download and raw links

This commit is contained in:
Klaas van Schelven
2023-11-13 18:35:29 +01:00
parent 42c496acbc
commit c054b48a4b
5 changed files with 34 additions and 2 deletions

View File

@@ -61,7 +61,9 @@ ROOT_URLCONF = 'bugsink.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [
BASE_DIR / "templates",
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [

View File

@@ -136,6 +136,14 @@ class Event(models.Model):
def get_absolute_url(self):
return "/events/event/%s/" % self.id
def get_raw_link(self):
# for the admin
return "/events/event/%s/raw/" % self.id
def get_download_link(self):
# for the admin
return "/events/event/%s/download/" % self.id
@classmethod
def from_json(cls, project, parsed_data, debug_info):
event, created = cls.objects.get_or_create( # NOTE immediate creation... is this what we want?

View File

@@ -1,9 +1,11 @@
from django.urls import path
from .views import event_detail, debug_get_hash
from .views import event_detail, event_download, debug_get_hash
urlpatterns = [
path('event/<uuid:pk>/', event_detail),
path('event/<uuid:pk>/raw/', event_download, kwargs={"as_attachment": False}),
path('event/<uuid:pk>/download/', event_download, kwargs={"as_attachment": True}),
path('debug_get_hash/<uuid:event_pk>/', debug_get_hash),
]

View File

@@ -1,6 +1,8 @@
import json
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse
from django.utils.http import content_disposition_header
from issues.utils import get_hash_for_data, get_issue_grouper_for_data
@@ -34,6 +36,14 @@ def event_detail(request, pk):
})
def event_download(request, pk, as_attachment=False):
obj = get_object_or_404(Event, pk=pk)
result = HttpResponse(obj.data, content_type="application/json")
result["Content-Disposition"] = content_disposition_header(
as_attachment=as_attachment, filename=obj.id.hex + ".json")
return result
def debug_get_hash(request, event_pk):
# debug view; not for eternity

View File

@@ -0,0 +1,10 @@
{% load i18n admin_urls %}
{% block object-tools-items %}
<li>
{% url opts|admin_urlname:'history' original.pk|admin_urlquote as history_url %}
<a href="{% add_preserved_filters history_url %}" class="historylink">{% translate "History" %}</a>
</li>
{% if original.get_raw_link %}<li><a href="{{ original.get_raw_link }}">{% translate "Raw" %}</a></li>{% endif %}
{% if original.get_download_link %}<li><a href="{{ original.get_download_link }}">{% translate "Download" %}</a></li>{% endif %}
{% if has_absolute_url %}<li><a href="{{ absolute_url }}" class="viewsitelink">{% translate "View on site" %}</a></li>{% endif %}
{% endblock %}