Add PGN Archive download buttons, and API endpoint
This commit is contained in:
1 parent
468281d52e
commit
c9b889eb9c
3 files changed
+34
-1
No files matched your search
@@ -87,6 +87,7 @@ urlpatterns = [
|
||||
django.urls.path(r'api/networks/<str:engine>/', OpenBench.views.api_networks),
|
||||
django.urls.path(r'api/networks/<str:engine>/<str:identifier>/', OpenBench.views.api_network_download),
|
||||
django.urls.path(r'api/buildinfo/', OpenBench.views.api_build_info),
|
||||
django.urls.path(r'api/pgns/<int:pgn_id>/', OpenBench.views.api_pgns),
|
||||
|
||||
# Redirect anything else to the Index
|
||||
django.urls.path(r'', OpenBench.views.index),
|
||||
|
||||
+24
-1
@@ -41,12 +41,14 @@ from OpenSite.settings import MEDIA_ROOT
|
||||
|
||||
from django.db import transaction
|
||||
from django.db.models import F, Q
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
from django.http import HttpResponse, JsonResponse, FileResponse
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
from django.core.files.base import ContentFile
|
||||
from django.utils import timezone
|
||||
|
||||
from wsgiref.util import FileWrapper
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# GENERAL UTILITIES #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
@@ -889,6 +891,27 @@ def api_build_info(request):
|
||||
|
||||
return api_response(data)
|
||||
|
||||
@csrf_exempt
|
||||
def api_pgns(request, pgn_id):
|
||||
|
||||
if not api_authenticate(request):
|
||||
return api_response({ 'error' : 'API requires authentication for this server' })
|
||||
|
||||
# Possible to request a PGN that does not exist
|
||||
pgn_path = FileSystemStorage('Media/PGNs').path('%d.pgn.tar' % (pgn_id))
|
||||
if not os.path.exists(pgn_path):
|
||||
return api_response({ 'error' : 'Unable to find PGN for Workload #%d' % (pgn_id) })
|
||||
|
||||
# Craft the download HTML response
|
||||
fwrapper = FileWrapper(open(pgn_path, 'rb'), 8192)
|
||||
response = FileResponse(fwrapper, content_type='application/octet-stream')
|
||||
|
||||
# Set all headers and return response
|
||||
response['Expires'] = -1
|
||||
response['Content-Length'] = os.path.getsize(pgn_path)
|
||||
response['Content-Disposition'] = 'attachment; filename=%d.pgn.tar' % (pgn_id)
|
||||
return response
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# BUSINESS VIEWS #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
@@ -105,6 +105,15 @@
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{% if test.upload_pgns != 'FALSE' %}
|
||||
<div class="anchor-container">
|
||||
<!-- PGN Download Button -->
|
||||
<a class="mt-1 anchorbutton btn-blue" href="/api/pgns/{{test.id}}/">
|
||||
Download PGN Archive
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- Elo, (SPRT/LRR if SPRT, otherwise CONF), Games -->
|
||||
<pre class="long-statblock" id="long-statblock">{{test|longStatBlock|linebreaksbr}}</pre>
|
||||
|
||||
|
||||
Reference in new issue
Block a user