Skip to content

Commit 9573c54

Browse files
committed
Try to fix player names in submissions
1 parent 62e8f23 commit 9573c54

File tree

4 files changed

+58
-5
lines changed

4 files changed

+58
-5
lines changed

marathon/cms_plugins.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from cms.plugin_pool import plugin_pool
55

66
from .forms import SubmissionForm, PlayerForm
7-
from .models import Event, Submission, MarathonPlugin
7+
from .models import Event, Submission, MarathonPlugin, Player
88
from .utils import get_player_info_for_user
99

1010
class SubmissionListSubmission:
@@ -13,8 +13,14 @@ def __init__(self, submission):
1313
self.category = submission.category
1414
self.players = []
1515
self.estimate = submission.estimate
16+
self.ptest = ""
17+
self.ntest = ""
1618
for player in submission.players.all():
17-
self.players.append(SubmissionListPlayer(player))
19+
self.ptest += str(player.user_id) + " "
20+
self.ntest += player.nickname + " "
21+
self.atest = player
22+
p = Player.objects.filter(user_id=player.user_id).first()
23+
self.players.append(SubmissionListPlayer(p))
1824

1925
def update(self, submission):
2026
for player in submission.players.all():

marathon/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
path('<slug:event>/', views.event_detail),
88
path('<slug:event>/submission/', views.new_submission, name='new-submission'),
99
path('<slug:event>/edit/<slug:submission_id>', views.edit_submission, name='edit-submission'),
10+
path('<slug:event>/datadump/', views.data_dump, name='data-dump'),
1011
path('thanks', views.thanks),
1112
]

marathon/views.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from operator import truediv
33

44
from django.contrib import messages
5-
from django.http import Http404, HttpResponseRedirect
5+
from django.contrib.auth.decorators import permission_required
6+
from django.http import Http404, HttpResponseRedirect, JsonResponse
67
from django.shortcuts import render, get_object_or_404
78
from django.utils.translation import gettext_lazy as _
89

@@ -113,5 +114,49 @@ def edit_submission(request, event, submission_id):
113114
return render(request, 'marathon/edit_submission.html', context)
114115
raise Http404('Tämmöstä ei oo')
115116

117+
118+
@permission_required('marathon.delete_submission')
119+
def data_dump(request, event):
120+
121+
if request.user.is_authenticated:
122+
perms = request.user.get_user_permissions()
123+
if 'marathon.delete_submission' in perms:
124+
event = get_object_or_404(Event, slug=event)
125+
submissions = Submission.objects.filter(event=event, hidden=False)
126+
subs = []
127+
players = {}
128+
for s in submissions:
129+
sub = {
130+
'id': s.id,
131+
'players': [],
132+
'game_title': s.game_title,
133+
'publish_year': s.publish_year,
134+
'console': s.console,
135+
'console_display': s.console_display,
136+
'category': s.category,
137+
'estimate': s.estimate,
138+
'personal_best': s.personal_best,
139+
'time_constraints': s.time_constraints,
140+
'description': s.description,
141+
'priority': s.priority,
142+
}
143+
for p in s.players.all():
144+
sub['players'].append(p.user_id)
145+
if p.user_id not in players:
146+
players[p.user_id] = {
147+
'id': p.user_id,
148+
'nickname': p.nickname,
149+
'discord': p.discord,
150+
'twitch': p.twitch,
151+
'gmail': p.gmail,
152+
'games': [s.id]
153+
}
154+
else:
155+
players[p.user_id]['games'].append(s.id)
156+
subs.append(sub)
157+
158+
return JsonResponse({"submissions": subs, "players": players})
159+
raise Http404('Tämmöstä ei oo')
160+
116161
def thanks(request):
117162
return

templates/marathon/plugins/submission_list.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
<div class="runner">
1616
<div class="label">Juoksija:</div>
1717
<div class="value">
18-
{% for player in submission.players.all %}
18+
<span style="display: none">{{ submission.ptest }} {{ submission.ntest}} {{submission.atest}}</span>
19+
{% for player in submission.players %}
1920
{% if not forloop.first %}{% if forloop.last %} & {% else %}, {% endif %}{% endif %}
2021
{% if player.twitch %}
21-
<a class="twitch-link" target="_blank" href="https://www.twitch.tv/{{ player.twitch }}">{% include 'macros/long_text.html' with text=player.nickname long=18 increment=3 %} <img class="twitch-icon" /></a>
22+
<a class="twitch-link" target="_blank" href="https://www.twitch.tv/{{ player.twitch }}">{% include 'macros/long_text.html' with text=player.nickname long=12 increment=4 %} <img class="twitch-icon" /></a>
2223
{% else %}
2324
{% include 'macros/long_text.html' with text=player.nickname long=15 increment=4 %}
2425
{% endif %}

0 commit comments

Comments
 (0)