Skip to content

Commit 8620d48

Browse files
authored
fix my submissions for admin
fix my submissions for admin and do minor tweaks
2 parents 995969a + ccd6422 commit 8620d48

File tree

8 files changed

+76
-33
lines changed

8 files changed

+76
-33
lines changed

marathon/cms_plugins.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,17 @@ class MySubmissionsPlugin(CMSPluginBase):
6565
def render(self, context, instance, placeholder):
6666
context = super().render(context, instance, placeholder)
6767
if context['request'].user.is_authenticated:
68-
player = get_player_info_for_user(context['request'].user)
68+
player_id = get_player_info_for_user(context['request'].user).get('id')
6969
else:
70-
player = {'id': -1}
70+
player_id = None
7171

72-
if instance.event:
73-
submissions = Submission.objects.filter(event=instance.event, hidden=False, players__in=[player['id']])
72+
if instance.event and player_id:
73+
submissions = Submission.objects.filter(event=instance.event, hidden=False, players__in=[player_id])
7474
else:
75-
submissions = Submission.objects.filter(hidden=False, players__in=[player['id']])
75+
submissions = {}
7676

77-
event_duration = (instance.event.end - instance.event.start).days
78-
event_days = []
79-
for d in range(event_duration + 1):
80-
event_days.append(instance.event.start + datetime.timedelta(days=d))
8177
context['require_authentication'] = True
8278
context['event'] = instance.event
83-
context['event_days'] = event_days
8479
context['submissions'] = submissions
8580
return context
8681

marathon/views.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
from operator import truediv
23

34
from django.contrib import messages
45
from django.http import Http404, HttpResponseRedirect
@@ -55,13 +56,20 @@ def new_submission(request, event):
5556

5657

5758
def edit_submission(request, event, submission_id):
59+
back = request.GET.get('r', '/')
5860
if request.user.is_authenticated:
5961
player = get_player_info_for_user(request.user)
62+
player_id = player.get('id')
63+
if not player_id:
64+
return HttpResponseRedirect(back)
6065
else:
61-
return HttpResponseRedirect('/')
66+
return HttpResponseRedirect(back)
6267
event = get_object_or_404(Event, slug=event)
63-
submission = get_object_or_404(Submission, id=submission_id, event=event, hidden=False, players__in=[player['id']])
64-
68+
submission = get_object_or_404(Submission, id=submission_id, event=event, hidden=False, players__in=[player_id])
69+
if submission:
70+
submission_found = True
71+
else:
72+
submission_found = False
6573
if request.method == 'POST':
6674
form = SubmissionForm(request.POST)
6775

@@ -83,7 +91,7 @@ def edit_submission(request, event, submission_id):
8391
else:
8492
request.session['previous_form'] = request.POST
8593
messages.add_message(request, messages.ERROR, _('Ilmoittautuminen epäonnistui, tarkista lomake.'))
86-
return HttpResponseRedirect(request.GET.get('next', '/'))
94+
return HttpResponseRedirect(request.GET.get('next', '/') + "?r=" + back)
8795

8896
if request.method == 'GET':
8997

@@ -99,6 +107,8 @@ def edit_submission(request, event, submission_id):
99107
'require_authentication': True,
100108
'form': form,
101109
'submission_id': submission_id,
110+
'back': back,
111+
'submission_found': submission_found
102112
}
103113
return render(request, 'marathon/edit_submission.html', context)
104114
raise Http404('Tämmöstä ei oo')

static/css/_form.scss

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,11 @@
133133
.tc-day-input {
134134
margin: auto;
135135
line-height: 0.9em;
136+
&:not(:hover){
137+
transform: rotate(90deg);
138+
}
136139
&:after{
137-
content: ""
140+
content: ""
138141
}
139142
}
140143
.tc-hour-input {
@@ -165,9 +168,21 @@
165168
width: 600px;
166169
max-width: 100%;
167170
margin: auto;
171+
padding-bottom: 1rem;
168172
}
169173
.form-header{
170174
text-align: left;
175+
display: flex;
176+
flex-direction: row;
177+
justify-content: space-between;
178+
flex-wrap: wrap;
179+
align-items: center;
180+
.link {
181+
font-family: $font-family-sans-serif;
182+
font-size: 1rem;
183+
text-align: right;
184+
flex-grow: 1;
185+
}
171186
}
172187
.action-button{
173188
display: inline-block;

static/css/_globals.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ body {
9797
content: $triangle-logo-image;
9898
}
9999

100+
100101
@import 'menu';
101102
@import 'donatebar';
102103
@import 'incentives';

templates/marathon/edit_submission.html

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,39 @@
66
{% provider_login_url "discord" next=request.path as href %}
77
{% bootstrap_button "Kirjaudu Discord-tunnuksilla" button_type="link" href=href %}
88
{% else %}
9-
<div class="custom-form">
10-
<form class="form" action="{% url 'edit-submission' event=event.slug submission_id=submission_id %}?next={{ request.path }}" method="post" novalidate>
11-
{% csrf_token %}
12-
<!-- Submission form -->
13-
<div id="game-form" class="custom-form-holder">
14-
<h3 class="form-header">
15-
Muokkaa suoritusta
16-
</h3>
17-
{% include 'marathon/plugins/game_form.html' with form=form event=event event_days=event_days %}
18-
<button class="action-button" type="submit">Lähetä</button>
19-
</div>
20-
</form>
21-
</div>
9+
{% if submission_found %}
10+
<div class="custom-form">
11+
<form class="form" action="{% url 'edit-submission' event=event.slug submission_id=submission_id %}?next={{ request.path }}&r={{ back }}" method="post" novalidate>
12+
{% csrf_token %}
13+
<!-- Submission form -->
14+
<div id="game-form" class="custom-form-holder">
15+
<h3 class="form-header">
16+
<div>Muokkaa suoritusta</div>
17+
{% if back %}
18+
<div class="link">
19+
<a href="{{ back }}">{% if back == '/' %}Takaisin{% else %}Palaa listaukseen{% endif %}</a>
20+
</div>
21+
{% endif %}
22+
</h3>
23+
{% include 'marathon/plugins/game_form.html' with form=form event=event event_days=event_days %}
24+
<button class="action-button" type="submit">Lähetä</button>
25+
</div>
26+
</form>
27+
</div>
28+
{% else %}
29+
<div class="custom-form">
30+
<div class="custom-form-holder">
31+
<h3 class="form-header">
32+
<div>Muokkaa suoritusta</div>
33+
{% if back %}
34+
<div class="link">
35+
<a href="{{ back }}">{% if back == '/' %}Takaisin{% else %}Palaa listaukseen{% endif %}</a>
36+
</div>
37+
{% endif %}
38+
</h3>
39+
</div>
40+
</div>
41+
{% endif %}
2242
{% endif %}
2343
{% block content %}
2444
{% endblock content %}

templates/marathon/plugins/fields/timeConstraints.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<div class="field-row">
99
<div class="field-label tc-label-row">
1010
<label for="{{ field.id_for_label }}">{{ field.label }}{% if field.field.required %}*{% endif %}</label>
11-
<div class="tc-legend"><div class="ok"></div> Käy,<div class="notok"></div> Ei käy, <div class="maybe"></div> Ehkä</div>
11+
<div class="tc-legend"><div class="ok"></div> Käy, <div class="notok"></div> Ei käy, <div class="maybe"></div> Ehkä</div>
1212
</div>
1313
{% include 'marathon/plugins/fields/errors.html' with errors=field.errors %}
1414
<script>

templates/marathon/plugins/my_submissions.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
{% load bootstrap5 sekizai_tags socialaccount %}
12
{% if require_authentication and not user.is_authenticated %}
3+
{% provider_login_url "discord" next=request.path as href %}
4+
{% bootstrap_button "Kirjaudu Discord-tunnuksilla" button_type="link" href=href %}
25
{% else %}
3-
<h2>Omat ilmoitukset</h2>
4-
{% if submissions %}
6+
{% if submissions and event %}
57
{% for submission in submissions|dictsort:"priority" %}
68
<div class="game-submission my-submission">
79
<div class="game-title">
@@ -18,7 +20,7 @@ <h2>Omat ilmoitukset</h2>
1820
<div class="game-category"><div class="label">Kategoria:</div> {{ submission.category }}</div>
1921
<div class="game-console"><div class="label">Laite:</div> {{ submission.console }}{% if submission.console_display %} / {{ submission.console_display }}{% endif %}</div>
2022
<div class="game-estimate"><div class="label">Arvio:</div> {{ submission.estimate }}</div>
21-
<div class="buttons"><a href="{% url 'edit-submission' event=event.slug submission_id=submission.id %}">Muokkaa ✎</a></div>
23+
<div class="buttons"><a href="{% url 'edit-submission' event=event.slug submission_id=submission.id %}?r={{ request.path }}">Muokkaa ✎</a></div>
2224
</div>
2325
</div>
2426
{% if not forloop.last %}

templates/marathon/plugins/submission_list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<div class="game-category">
2929
<div class="label">Kategoria:</div>
3030
<div class="value">
31-
{% include 'macros/long_text.html' with text=submission.category long=15 increment=6 %}
31+
{% include 'macros/long_text.html' with text=submission.category long=12 increment=5 %}
3232
</div>
3333
</div>
3434
<div class="game-estimate">

0 commit comments

Comments
 (0)