Skip to content

Commit

Permalink
Make it so combatlogs are currently not retained after upload.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kraust committed Feb 24, 2024
1 parent eec5639 commit 308dec2
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 22 deletions.
9 changes: 6 additions & 3 deletions OSCR_django/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""

# from django.contrib import admin
from django.conf import settings
from django.contrib import admin
from django.urls import include, path
from drf_yasg.views import get_schema_view

Expand All @@ -29,10 +30,12 @@


urlpatterns = [
# path("admin/", admin.site.urls),
# path("swagger/", schema_view.with_ui("swagger")),
# path("", include("user.urls")),
path("", include("combatlog.urls.combatlog")),
path("", include("ladder.urls.ladder")),
path("", include("ladder.urls.ladder_entry")),
]

if settings.ENABLE_DEBUG:
urlpatterns.append(path("admin/", admin.site.urls))
urlpatterns.append(path("swagger/", schema_view.with_ui("swagger")))
16 changes: 16 additions & 0 deletions combatlog/migrations/0005_remove_combatlog_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 4.2.9 on 2024-02-24 03:53

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("combatlog", "0004_metadata_date_time"),
]

operations = [
migrations.RemoveField(
model_name="combatlog",
name="data",
),
]
10 changes: 6 additions & 4 deletions combatlog/models/combatlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
class CombatLog(BaseModel):
"""CombatLog Model"""

data = models.BinaryField(null=True, default=None)

metadata = models.ForeignKey(
Metadata,
on_delete=models.CASCADE,
Expand Down Expand Up @@ -138,13 +136,17 @@ def update_metadata_file(self, file):

return results

def update_metadata(self):
def update_metadata(self, data):
"""Parse the Combat Log and create Metadata"""
with tempfile.NamedTemporaryFile() as file:
file.write(self.data)
file.write(data)
file.flush()
return self.update_metadata_file(file)

def data(self):
"""Fetch the Combat Log data"""
return b""

def __str__(self):
if not self.metadata:
return f"Combat Log without Metadata ({self.pk})"
Expand Down
7 changes: 3 additions & 4 deletions combatlog/serializers/combatlog.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
""" CombatLog Serializers """

from combatlog.models import CombatLog
from rest_framework import serializers

from combatlog.models import CombatLog

from .metadata import MetadataSerializer


Expand All @@ -13,9 +14,7 @@ class CombatLogSerializer(serializers.ModelSerializer):

class Meta:
model = CombatLog
exclude = [
"data",
]
fields = "__all__"


class CombatLogUploadSerializer(serializers.Serializer):
Expand Down
22 changes: 12 additions & 10 deletions combatlog/views/combatlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

import logging

from combatlog.models import CombatLog
from combatlog.serializers import (
CombatLogSerializer,
CombatLogUploadResponseSerializer,
CombatLogUploadSerializer,
)
from core.pagination import PageNumberPagination
from django.db import transaction
from django.http import HttpResponse
from drf_yasg import openapi
Expand All @@ -19,6 +12,14 @@
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet

from combatlog.models import CombatLog
from combatlog.serializers import (
CombatLogSerializer,
CombatLogUploadResponseSerializer,
CombatLogUploadSerializer,
)
from core.pagination import PageNumberPagination

LOGGER = logging.getLogger("django")


Expand Down Expand Up @@ -56,8 +57,8 @@ def upload(self, request):
data = serializer.validated_data["file"].read()

with transaction.atomic():
instance = CombatLog.objects.create(data=data)
res = instance.update_metadata()
instance = CombatLog.objects.create()
res = instance.update_metadata(data)
serializer = CombatLogUploadResponseSerializer(data=res, many=True)
serializer.is_valid(raise_exception=True)

Expand All @@ -83,9 +84,10 @@ def download(self, request, pk=None):
"""

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

response = HttpResponse()
response["Content-Disposition"] = f'attachment; filename="{instance}.log"'
response["Content-Transfer-Encoding"] = "binary"
response.write(instance.data)
response.write(data)
return response
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ Django==4.2.9
djangorestframework==3.14.0
drf_yasg==1.21.7
django_filter==23.5
STO-OSCR==2024.2b201
STO-OSCR>=2024.2b201
whitenoise==6.6.0
psycopg[binary,pool]==3.1.18

1 comment on commit 308dec2

@vercel
Copy link

@vercel vercel bot commented on 308dec2 Feb 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.