Skip to content

Commit

Permalink
Admin Changes + Allow for Downloading Uncompressed Logs (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kraust authored Oct 19, 2024
1 parent ed76344 commit 8f3e7df
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 7 deletions.
17 changes: 15 additions & 2 deletions combatlog/admin.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
""" CombatLog admin """
"""CombatLog admin"""

from django.contrib import admin
from django.db.models import JSONField
from django_json_widget.widgets import JSONEditorWidget

from ladder.models import LadderEntry

from .models import CombatLog, Metadata

admin.site.register(CombatLog)

class LadderEntryInline(admin.StackedInline):
model = LadderEntry
extra = 1
formfield_overrides = {
JSONField: {"widget": JSONEditorWidget},
}


@admin.register(Metadata)
class MetadataAdmin(admin.ModelAdmin):
formfield_overrides = {
JSONField: {"widget": JSONEditorWidget},
}


@admin.register(CombatLog)
class CombatLogAdmin(admin.ModelAdmin):
inlines = [LadderEntryInline]
2 changes: 1 addition & 1 deletion combatlog/templates/combatlog.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div data-bs-theme="dark">
<h2 style="display: inline-block;">{{object.metadata.map}} {% if object.metadata.difficulty is not None %}({{object.metadata.difficulty}}){% endif %}</h2>&nbsp;
<h5 style="display: inline-block;">{{object.metadata.date_time|date:"DATETIME_FORMAT"}}</h5>
<a href="{% url 'combatlog-download' object.pk %}"><div class="float-end"><img src="{% static 'img/download.svg' %}" data-toggle="tooltip" data-placement="top" title="Download"></img></div></a>
<a href="{% url 'combatlog-download-raw' object.pk %}"><div class="float-end"><img src="{% static 'img/download.svg' %}" data-toggle="tooltip" data-placement="top" title="Download"></img></div></a>
<hr>
<table class="table table-dark table-hover table-sm table-responsive">
<thead>
Expand Down
29 changes: 29 additions & 0 deletions combatlog/views/combatlog.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""CombatLog Views"""

import gzip
import logging

from django.db import transaction
Expand Down Expand Up @@ -139,6 +140,34 @@ def download(self, request, pk=None):
response.write(data)
return response

@swagger_auto_schema(
responses={
"200": openapi.Response(
"File Attachment", schema=openapi.Schema(type=openapi.TYPE_FILE)
)
},
)
@action(
detail=True,
methods=["GET"],
permission_classes=(),
)
def download_raw(self, request, pk=None):
"""
Combat Log Download
Download the saved Combat Log
"""

instance = self.get_object()
data = instance.get_data()

response = HttpResponse()
response["Content-Disposition"] = f'attachment; filename="{instance}.log"'
response["Content-Transfer-Encoding"] = "binary"
response.write(gzip.decompress(data))
return response


class CombatLogDetailView(DetailView):
"""Combat Log Detail View"""
Expand Down
25 changes: 21 additions & 4 deletions ladder/admin.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
""" CombatLog admin """
"""CombatLog admin"""

from django.contrib import admin
from django.db.models import JSONField
from django_json_widget.widgets import JSONEditorWidget

from .models import Ladder, LadderEntry, Variant

admin.site.register(Ladder)
admin.site.register(Variant)


@admin.register(LadderEntry)
class LadderEntryAdmin(admin.ModelAdmin):
Expand All @@ -26,6 +23,13 @@ class LadderEntryAdmin(admin.ModelAdmin):
formfield_overrides = {
JSONField: {"widget": JSONEditorWidget},
}
search_fields = [
"player",
"ladder__name",
"ladder__difficulty",
"ladder__variant__name",
"data__build",
]

@admin.display(ordering="ladder__name")
def ladder__name(self, obj):
Expand Down Expand Up @@ -58,3 +62,16 @@ def build(self, obj):
@admin.display(ordering="visible")
def visible(self, obj):
return obj.data.get("visible")


@admin.register(Ladder)
class LadderAdmin(admin.ModelAdmin):
search_fields = [
"name",
"variant__name",
]


@admin.register(Variant)
class VarientAdmin(admin.ModelAdmin):
search_fields = []

0 comments on commit 8f3e7df

Please sign in to comment.