Skip to content

Commit 6742a2f

Browse files
authored
Merge pull request #95 from Vauhtijuoksu/develop
Release: 2024 submission changes & Discord login
2 parents 11d499a + 293638c commit 6742a2f

File tree

22 files changed

+2367
-690
lines changed

22 files changed

+2367
-690
lines changed

.github/workflows/azure-deployment.yml

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ jobs:
2222
with:
2323
python-version: '3.9'
2424

25+
- name: Install compile dependencies
26+
run: sudo apt-get install -y gettext
27+
2528
- name: Create and start virtual environment
2629
run: |
2730
python -m venv venv
@@ -31,6 +34,8 @@ jobs:
3134
run: pip install -r requirements.txt
3235

3336
# Optional: Add step to run tests here (PyTest, Django test suites, etc.)
37+
- name: Compile translations
38+
run: python manage.py compilemessages
3439

3540
- name: Upload artifact for deployment jobs
3641
uses: actions/upload-artifact@v2

Pipfile

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ name = "pypi"
55

66
[packages]
77
Django = "~=3.2"
8+
django-cms = "~=3.11"
89
django-filer = "*"
910
djangocms-text-ckeditor = "*"
1011
djangocms-link = "*"
@@ -24,6 +25,7 @@ django-storages = {extras = ["azure"], version = "~=1.13"}
2425
python-dateutil = "*"
2526
requests-cache = "*"
2627
gunicorn = "*"
28+
django-allauth = "*"
2729

2830
[requires]
2931
python_version = "3.9"

Pipfile.lock

+612-625
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

marathon/cms_plugins.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from .forms import SubmissionForm, PlayerForm
55
from .models import Event, Submission, MarathonPlugin
6+
from .utils import get_player_info_for_user
67

78
@plugin_pool.register_plugin
89
class SubmissionListPlugin(CMSPluginBase):
@@ -36,8 +37,17 @@ def render(self, context, instance, placeholder):
3637
previous_data = context['request'].session.get('previous_form')
3738

3839
form = SubmissionForm(previous_data)
39-
player_form = PlayerForm(previous_data, prefix='player')
40-
40+
if previous_data:
41+
player_form = PlayerForm(previous_data, prefix='player')
42+
elif context['request'].user.is_authenticated:
43+
print('got user')
44+
player_info = get_player_info_for_user(context['request'].user)
45+
player_form = PlayerForm(initial=player_info, prefix='player')
46+
if player_info.get('discord'):
47+
player_form.fields['discord'].disabled = True
48+
else:
49+
player_form = PlayerForm(prefix='player')
50+
context['require_authentication'] = True
4151
context['form'] = form
4252
context['player_form'] = player_form
4353
context['event'] = instance.event

marathon/forms.py

+1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ class Meta:
5858
widgets = {
5959
'time_constraints': forms.Textarea(attrs=TEXTAREA_ATTRS),
6060
'description': forms.Textarea(attrs=TEXTAREA_ATTRS),
61+
'priority': forms.NumberInput(attrs={'min': '1'}),
6162
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Generated by Django 3.2.18 on 2024-01-18 17:31
2+
3+
import django.core.validators
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('marathon', '0006_submission_updates_2023'),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name='submission',
16+
name='priority',
17+
field=models.IntegerField(default=1, help_text='jos ehdotat useampaa peliä (1=mieluisin)', validators=[django.core.validators.MinValueValidator(1)], verbose_name='tärkeysjärjestys'),
18+
),
19+
migrations.AlterField(
20+
model_name='submission',
21+
name='console',
22+
field=models.CharField(max_length=29, verbose_name='laite/konsoli, jolla pelaat'),
23+
),
24+
migrations.AlterField(
25+
model_name='submission',
26+
name='estimate',
27+
field=models.CharField(help_text='Arvioi suorituksen kestolle yläraja (tunnit:minuutit) alusta loppuun. Ota arviossa huomioon terveisten lähettämiset ja mahdolliset virheet runissa.', max_length=20, verbose_name='aika-arvio'),
28+
),
29+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 3.2.18 on 2024-01-22 19:00
2+
3+
import django.core.validators
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('marathon', '0007_auto_20240118_1931'),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name='submission',
16+
name='priority',
17+
field=models.IntegerField(default=1, help_text='Jos ehdotat useampaa peliä (1=mieluisin)', validators=[django.core.validators.MinValueValidator(1)], verbose_name='tärkeysjärjestys'),
18+
),
19+
]

marathon/models.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from cms.models import CMSPlugin
22
from django.db import models
33
from django.conf import settings
4-
from django.core.validators import RegexValidator
4+
from django.core.validators import MinValueValidator
55
from django.utils.text import slugify
66
from django.utils.translation import gettext_lazy as _
77

8-
discord_validator = RegexValidator(r'^.{3,32}#[0-9]{4}$', _('Anna discord-tunnus muodossa <nimi>#<sarjanumero>'))
98

109
class Player(models.Model):
1110
user = models.OneToOneField(
@@ -15,7 +14,7 @@ class Player(models.Model):
1514
)
1615

1716
nickname = models.CharField(_('nimimerkki'), max_length=30)
18-
discord = models.CharField(_('discord-tunnus'), max_length=50, validators=[discord_validator])
17+
discord = models.CharField(_('discord-tunnus'), max_length=50)
1918
twitch = models.CharField(_('twitch-tunnus'), max_length=50, blank=True)
2019
gmail = models.EmailField(
2120
_('sähköpostiosoite'),
@@ -81,6 +80,13 @@ class Submission(models.Model):
8180
# Mandatory
8281
gdpr = models.BooleanField(default=False)
8382

83+
priority = models.IntegerField(
84+
_('tärkeysjärjestys'),
85+
help_text=_('Jos ehdotat useampaa peliä (1=mieluisin)'),
86+
default=1,
87+
validators=[MinValueValidator(1)],
88+
)
89+
8490
# Meta
8591
hidden = models.BooleanField(default=False)
8692

marathon/utils.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from django.conf import settings
2+
from django.core.exceptions import ObjectDoesNotExist
3+
from django.forms.models import model_to_dict
4+
from allauth.account.models import EmailAddress
5+
from .models import Player
6+
7+
8+
def get_user_discord(user: settings.AUTH_USER_MODEL):
9+
if hasattr(user, 'socialaccount_set'):
10+
for account in user.socialaccount_set.all():
11+
if account.provider == 'discord':
12+
username = account.extra_data.get('username', None)
13+
nickname = account.extra_data.get('global_name', None)
14+
return {
15+
'discord': username,
16+
'nickname': nickname
17+
}
18+
return None
19+
20+
def get_user_primary_email(user: settings.AUTH_USER_MODEL):
21+
return EmailAddress.objects.get_primary_email(user)
22+
23+
def get_player_info_for_user(user: settings.AUTH_USER_MODEL):
24+
try:
25+
player = user.player
26+
return model_to_dict(player)
27+
except ObjectDoesNotExist:
28+
pass
29+
30+
player_info = {}
31+
32+
discord_info = get_user_discord(user) or {}
33+
player_info.update(discord_info)
34+
35+
email = get_user_primary_email(user)
36+
player_info['gmail'] = email
37+
38+
return player_info

marathon/views.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ def event_detail(request, event):
2525
def new_submission(request, event):
2626
if request.method == 'POST':
2727
event = get_object_or_404(Event, slug=event)
28-
player_form = PlayerForm(request.POST, prefix='player')
28+
29+
player = None
30+
if request.user.is_authenticated:
31+
player, created = Player.objects.get_or_create(user=request.user)
32+
player_form = PlayerForm(request.POST, prefix='player', instance=player)
33+
2934
form = SubmissionForm(request.POST)
3035

3136
if form.is_valid() and player_form.is_valid():

requirements.txt

+53-50
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,72 @@
11
-i https://pypi.org/simple
2-
asgiref==3.6.0 ; python_version >= '3.7'
3-
attrs==22.2.0 ; python_version >= '3.6'
4-
azure-core==1.26.3 ; python_version >= '3.7'
5-
azure-storage-blob==12.15.0
6-
beautifulsoup4==4.12.0 ; python_full_version >= '3.6.0'
7-
brotli==1.0.9
8-
cattrs==22.2.0 ; python_version >= '3.7'
9-
certifi==2022.12.7 ; python_version >= '3.6'
10-
cffi==1.15.1
11-
charset-normalizer==3.1.0 ; python_full_version >= '3.7.0'
12-
cryptography==40.0.1 ; python_version >= '3.6'
2+
asgiref==3.7.2 ; python_version >= '3.7'
3+
attrs==23.2.0 ; python_version >= '3.7'
4+
azure-core==1.29.7 ; python_version >= '3.7'
5+
azure-storage-blob==12.19.0
6+
beautifulsoup4==4.12.3 ; python_full_version >= '3.6.0'
7+
brotli==1.1.0
8+
cattrs==23.2.3 ; python_version >= '3.8'
9+
certifi==2023.11.17 ; python_version >= '3.6'
10+
cffi==1.16.0 ; python_version >= '3.8'
11+
chardet==5.2.0 ; python_version >= '3.7'
12+
charset-normalizer==3.3.2 ; python_full_version >= '3.7.0'
13+
cryptography==41.0.7 ; python_version >= '3.7'
1314
cssselect2==0.7.0 ; python_version >= '3.7'
14-
django==3.2.18
15-
django-appconf==1.0.5 ; python_version >= '3.6'
15+
defusedxml==0.7.1 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
16+
django==3.2.23
17+
django-allauth==0.60.1
18+
django-appconf==1.0.6 ; python_version >= '3.7'
1619
django-bootstrap-v5==1.0.11
17-
django-classy-tags==4.0.0 ; python_version >= '3.7'
18-
django-cms==3.11.1 ; python_version >= '3.7'
19-
django-compressor==4.3.1
20-
django-filer==2.2.4
21-
django-formtools==2.4 ; python_version >= '3.6'
22-
django-js-asset==2.0.0 ; python_version >= '3.6'
23-
django-mptt==0.14.0 ; python_version >= '3.6'
20+
django-classy-tags==4.1.0 ; python_version >= '3.8'
21+
django-cms==3.11.4
22+
django-compressor==4.4
23+
django-filer==3.1.1
24+
django-formtools==2.5.1 ; python_version >= '3.8'
2425
django-polymorphic==3.1.0
2526
django-sass-processor==1.1
26-
django-sekizai==4.0.0 ; python_version >= '3.8'
27-
django-storages[azure]==1.13.2
28-
django-treebeard==4.4 ; python_version >= '3.6'
29-
djangocms-admin-style==3.2.3 ; python_version >= '3.7'
30-
djangocms-attributes-field==2.1.0
31-
djangocms-file==3.0.0
27+
django-sekizai==4.1.0 ; python_version >= '3.8'
28+
django-storages[azure]==1.14.2
29+
django-treebeard==4.7 ; python_version >= '3.8'
30+
djangocms-admin-style==3.2.7 ; python_version >= '3.7'
31+
djangocms-attributes-field==3.0.0
32+
djangocms-file==3.0.1
3233
djangocms-link==3.1.1
33-
djangocms-picture==4.0.0
34-
djangocms-snippet==3.1.0
35-
djangocms-style==3.0.0
36-
djangocms-text-ckeditor==5.1.2
34+
djangocms-picture==4.1.1
35+
djangocms-snippet==3.1.1
36+
djangocms-style==3.1.0
37+
djangocms-text-ckeditor==5.1.5
3738
easy-thumbnails[svg]==2.8.5 ; python_version >= '3.6'
38-
exceptiongroup==1.1.1 ; python_version < '3.11'
39-
gunicorn==20.1.0
39+
exceptiongroup==1.2.0 ; python_version < '3.11'
40+
gunicorn==21.2.0
4041
html5lib==1.1 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
41-
idna==3.4 ; python_version >= '3.5'
42+
idna==3.6 ; python_version >= '3.5'
4243
isodate==0.6.1
43-
libsass==0.22.0
44-
lxml==4.9.2 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
45-
packaging==23.0 ; python_version >= '3.7'
46-
pillow==9.4.0 ; python_version >= '3.7'
47-
platformdirs==3.2.0 ; python_version >= '3.7'
48-
psycopg2==2.9.5
44+
libsass==0.23.0
45+
lxml==5.1.0 ; python_version >= '3.6'
46+
oauthlib==3.2.2 ; python_version >= '3.6'
47+
packaging==23.2 ; python_version >= '3.7'
48+
pillow==10.2.0 ; python_version >= '3.8'
49+
platformdirs==4.1.0 ; python_version >= '3.8'
50+
psycopg2==2.9.9
4951
pycparser==2.21 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
52+
pyjwt[crypto]==2.8.0 ; python_version >= '3.7'
5053
python-dateutil==2.8.2
5154
python-decouple==3.8
52-
pytz==2023.3
55+
python3-openid==3.2.0
56+
pytz==2023.3.post1
5357
rcssmin==1.1.1
54-
reportlab==3.6.12 ; python_version >= '3.7' and python_version < '4.0'
55-
requests==2.28.2
56-
requests-cache==1.0.1
58+
reportlab==4.0.9 ; python_version >= '3.7' and python_version < '4.0'
59+
requests==2.31.0
60+
requests-cache==1.1.1
61+
requests-oauthlib==1.3.1 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
5762
rjsmin==1.2.1
58-
setuptools==67.6.1 ; python_version >= '3.7'
5963
six==1.16.0 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
60-
soupsieve==2.4 ; python_version >= '3.7'
61-
sqlparse==0.4.3 ; python_version >= '3.5'
64+
soupsieve==2.5 ; python_version >= '3.8'
65+
sqlparse==0.4.4 ; python_version >= '3.5'
6266
svglib==1.5.1 ; python_version >= '3.7'
6367
tinycss2==1.2.1 ; python_version >= '3.7'
64-
typing-extensions==4.5.0 ; python_version >= '3.7'
65-
unidecode==1.1.2
68+
typing-extensions==4.9.0 ; python_version < '3.11'
6669
url-normalize==1.4.3 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'
67-
urllib3==1.26.15 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'
70+
urllib3==2.1.0 ; python_version >= '3.8'
6871
webencodings==0.5.1
69-
whitenoise[brotli]==6.4.0
72+
whitenoise[brotli]==6.6.0

scripts/docker_entrypoint_gunicorn.sh

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ done
99

1010
echo "PostgreSQL started"
1111

12+
python manage.py compilemessages
1213
python manage.py compilescss --use-storage
1314
python manage.py collectstatic --noinput --ignore=*.scss
1415

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{% load allauth %}
2+
{% comment %} djlint:off {% endcomment %}
3+
<{% if attrs.href %}a href="{{ attrs.href }}"{% else %}button{% endif %}
4+
class="btn {% if attrs.classes %}{{ attrs.classes }}{% else %}btn-primary{% endif %}"
5+
{% if attrs.form %}form="{{ attrs.form }}"{% endif %}
6+
{% if attrs.id %}id="{{ attrs.id }}"{% endif %}
7+
{% if attrs.name %}name="{{ attrs.name }}"{% endif %}
8+
{% if attrs.type %}type="{{ attrs.type }}"{% endif %}
9+
>
10+
{% slot %}
11+
{% endslot %}
12+
</{% if attrs.href %}a{% else %}button{% endif %}>

templates/allauth/layouts/base.html

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{% extends "vauhtijuoksu/vauhtijuoksu.html" %}
2+
{% load i18n %}
3+
{% block override %}
4+
{% if messages %}
5+
<div>
6+
<strong>{% trans "Messages:" %}</strong>
7+
<ul>
8+
{% for message in messages %}<li>{{ message }}</li>{% endfor %}
9+
</ul>
10+
</div>
11+
{% endif %}
12+
<div>
13+
<ul>
14+
{% if user.is_authenticated %}
15+
<li>
16+
<a href="{% url 'account_logout' %}">{% trans "Sign Out" %}</a>
17+
</li>
18+
{% endif %}
19+
</ul>
20+
</div>
21+
{% block content %}
22+
{% endblock content %}
23+
{% endblock override %}
24+
{% block extra_body %}
25+
{% endblock extra_body %}

0 commit comments

Comments
 (0)