Fix little errors

This commit is contained in:
Nikola Kubiczek 2021-10-09 14:27:20 +02:00
parent 4147e37854
commit 3b7c106ab7
9 changed files with 92 additions and 53 deletions

View File

@ -33,7 +33,7 @@
}); });
</script> </script>
<header class="hero"> <header class="hero">
<a class="hero-body is-flex is-flex-direction-column has-text-black" href="{% url 'home' %}"> <a class="hero-body is-flex is-flex-direction-column has-text-black" href="{% url 'news' %}">
<span class="title is-2 mx-auto">Konkurs Matematyczny</span> <span class="title is-2 mx-auto">Konkurs Matematyczny</span>
<span class="subtitle is-4 mx-auto">o Puchar Dyrektora V Liceum Ogólnokształcącego w Bielsku-Białej</span> <span class="subtitle is-4 mx-auto">o Puchar Dyrektora V Liceum Ogólnokształcącego w Bielsku-Białej</span>
</a> </a>
@ -50,6 +50,7 @@
<div id="navbar" class="navbar-menu"> <div id="navbar" class="navbar-menu">
<div class="navbar-start"> <div class="navbar-start">
<a class="navbar-item {{ news_page }}" href="{% url 'news' %}">Aktualności</a> <a class="navbar-item {{ news_page }}" href="{% url 'news' %}">Aktualności</a>
<a class="navbar-item {{ aboutcontest_page }}" href="{% url 'aboutcontest' %}">O konkursie</a>
<a class="navbar-item {{ rules_page }}" href="{% url 'rules' %}">Regulamin</a> <a class="navbar-item {{ rules_page }}" href="{% url 'rules' %}">Regulamin</a>
<a class="navbar-item {{ tests_page }}" href="{% url 'tests' %}">Zadania</a> <a class="navbar-item {{ tests_page }}" href="{% url 'tests' %}">Zadania</a>
<a class="navbar-item {{ scores_page }}" href="{% url 'scores' %}">Wyniki</a> <a class="navbar-item {{ scores_page }}" href="{% url 'scores' %}">Wyniki</a>

View File

@ -7,13 +7,14 @@
<ul class="pagination-list"> <ul class="pagination-list">
{% for edition in editions %} {% for edition in editions %}
<li> <li>
<a class="pagination-link {% if edition.year == year %}is-current{% endif %}" <a class="pagination-link {% if edition.year == year %}is-current"{% elif edition.scores_available %}" href="{% url 'scores' edition.year %}"{% endif %}"
{% if edition.year != year %}href="{% url 'scores' edition.year %}"{% endif %} {% if not edition.scores_available %}disabled{% endif%}
>{{ edition.roman }}</a> >{{ edition.roman }}</a>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
</nav> </nav>
{% if scores_available %}
<div class="hero has-text-centered"> <div class="hero has-text-centered">
<span class="title my-6">Klasyfikacja indywidualna</span> <span class="title my-6">Klasyfikacja indywidualna</span>
<table class="hero-body table is-striped is-narrow is-hoverable is-fullwidth"> <table class="hero-body table is-striped is-narrow is-hoverable is-fullwidth">
@ -75,4 +76,9 @@
{% endfor %} {% endfor %}
</table> </table>
</div> </div>
{% else %}
<div class="hero has-text-centered">
<span class="title my-6">Wyniki niedostępne</span>
</div>
{% endif %}
{% endblock %} {% endblock %}

View File

@ -3,14 +3,14 @@
<url> <url>
<loc>https://puchar.lo5.bielsko.pl</loc> <loc>https://puchar.lo5.bielsko.pl</loc>
<priority>1.0</priority> <priority>1.0</priority>
<changefreq>yearly</changefreq>
</url>
<url>
<loc>https://puchar.lo5.bielsko.pl/aktualnosci</loc>
<priority>0.9</priority>
<lastmod>{{ latest.created_at | date:"Y-m-d" }}</lastmod> <lastmod>{{ latest.created_at | date:"Y-m-d" }}</lastmod>
<changefreq>monthly</changefreq> <changefreq>monthly</changefreq>
</url> </url>
<url>
<loc>https://puchar.lo5.bielsko.pl/konkurs</loc>
<priority>0.9</priority>
<changefreq>yearly</changefreq>
</url>
<url> <url>
<loc>https://puchar.lo5.bielsko.pl/regulamin</loc> <loc>https://puchar.lo5.bielsko.pl/regulamin</loc>
<priority>0.8</priority> <priority>0.8</priority>

View File

@ -15,7 +15,7 @@
{% csrf_token %} {% csrf_token %}
{{ form | crispy }} {{ form | crispy }}
<div class="buttons mx-auto my-3"> <div class="buttons mx-auto my-3">
<button class="button is-success" type="submit">Zaktualizuj</button> <button class="button is-info" type="submit">Zaktualizuj</button>
<a class="button is-link" href="{% url 'password_change' %}" target="_blank" rel="noopener noreferrer">Zmień hasło</a> <a class="button is-link" href="{% url 'password_change' %}" target="_blank" rel="noopener noreferrer">Zmień hasło</a>
</div> </div>
</form> </form>

View File

@ -6,7 +6,13 @@
{% block tab %} {% block tab %}
<form class="is-flex is-flex-direction-column" method="POST"> <form class="is-flex is-flex-direction-column" method="POST">
<div class="my-6 has-text-centered is-flex is-flex-direction-column"> <div class="my-6 has-text-centered is-flex is-flex-direction-column">
<span class="title">Zgłoś uczniów</span> <span class="title">
{% if students %}
Edytuj zgłoszenie
{% else %}
Zgłoś uczniów
{% endif %}
</span>
</div> </div>
{% csrf_token %} {% csrf_token %}
{{ formset.management_form | crispy }} {{ formset.management_form | crispy }}
@ -17,6 +23,11 @@
<div class="column is-2">{{ form.grade | as_crispy_field }}</div> <div class="column is-2">{{ form.grade | as_crispy_field }}</div>
</div> </div>
{% endfor %} {% endfor %}
<button class="button is-success mx-auto" type="submit">Zgłoś</button>
{% if students %}
<button class="button is-info mx-auto" type="submit">Edytuj</button>
{% else %}
<button class="button is-link mx-auto" type="submit">Zgłoś</button>
{% endif %}
</form> </form>
{% endblock %} {% endblock %}

View File

@ -1,13 +1,15 @@
from django.urls import path from django.urls import path
from django.views.generic.base import RedirectView
from .views import SignUpView, SubmitStudentsView, UpdateAccountView, ScoresRedirect, HomeView, NewsView, ScoresView, RulesView, TestsView, ContactView, RobotsView, SitemapView from .views import SignUpView, SubmitStudentsView, UpdateAccountView, AboutContestView, NewsView, ScoresView, RulesView, TestsView, ContactView, RobotsView, SitemapView
urlpatterns = [ urlpatterns = [
path('', HomeView.as_view(), name='home'), path('', NewsView.as_view(), name='news'),
path('aktualnosci/', NewsView.as_view(), name='news'), path('aktualnosci/', RedirectView.as_view(url='/')),
path('konkurs/', AboutContestView.as_view(), name='aboutcontest'),
path('regulamin/', RulesView.as_view(), name='rules'), path('regulamin/', RulesView.as_view(), name='rules'),
path('zadania/', TestsView.as_view(), name='tests'), path('zadania/', TestsView.as_view(), name='tests'),
path('wyniki/', ScoresRedirect, name='scores'), path('wyniki/', ScoresView, name='scores'),
path('wyniki/<int:year>/', ScoresView, name='scores'), path('wyniki/<int:year>/', ScoresView, name='scores'),
path('kontakt/', ContactView.as_view(), name='contact'), path('kontakt/', ContactView.as_view(), name='contact'),
path('rejestracja/', SignUpView.as_view(), name='signup'), path('rejestracja/', SignUpView.as_view(), name='signup'),

View File

@ -34,15 +34,20 @@ def SubmitStudentsView(request):
edition = Edition.current() edition = Edition.current()
if edition is not None: if edition is not None:
identifier = f'{edition.year}-{request.user.id}-'
queryset = Student.objects.filter(identifier__startswith=identifier) context = {
'account_page': 'is-active',
'submission_tab': 'is-active',
'ongoing': edition,
}
if edition.submissions is not True: if edition.submissions is not True:
identifier = f'{edition.year}-{request.user.id}' queryset = Student.objects.filter(identifier__startswith=f'{edition.year}-{request.user.id}').order_by('identifier')
queryset = Student.objects.filter(identifier__startswith=identifier).order_by('identifier')
return render(request, 'user/submission.html', {'account_page': 'is-active', 'submission_tab': 'is-active', 'ongoing': edition, 'students': queryset})
ArticleFormSet = formset_factory(StudentForm, extra=2, max_num=3, min_num=1) return render(request, 'user/submission.html', {'students': queryset, **context})
queryset = Student.objects.filter(identifier__startswith=f'{edition.year}-{request.user.id}-')
ArticleFormSet = formset_factory(StudentForm, extra=3, max_num=3, min_num=0)
if request.method == 'POST': if request.method == 'POST':
with transaction.atomic(): with transaction.atomic():
@ -56,21 +61,27 @@ def SubmitStudentsView(request):
else: else:
formset = ArticleFormSet(initial=list(map(lambda x: x.__dict__, queryset))) formset = ArticleFormSet(initial=list(map(lambda x: x.__dict__, queryset)))
return render(request, 'user/submit.html', {'account_page': 'is-active', 'submission_tab': 'is-active', 'ongoing': True, 'formset': formset}) return render(request, 'user/submit.html', {'formset': formset, 'students': len(queryset), **context})
else: else:
return redirect(reverse_lazy('account')) return redirect(reverse_lazy('account'))
class HomeView(TemplateView): class AboutContestView(TemplateView):
template_name = 'home.html' template_name = 'home.html'
extra_context = {
'aboutcontest_page': 'is-active'
}
class NewsView(TemplateView): class NewsView(TemplateView):
template_name = 'news.html' template_name = 'news.html'
extra_context = {
'news_page': 'is-active', def get_context_data(self, **kwargs):
'announcements': Announcement.objects.all(), context = super().get_context_data(**kwargs)
} context['news_page'] = 'is-active'
context['announcements'] = Announcement.objects.all()
return context
class RulesView(TemplateView): class RulesView(TemplateView):
@ -82,26 +93,32 @@ class RulesView(TemplateView):
class TestsView(TemplateView): class TestsView(TemplateView):
template_name = 'tests.html' template_name = 'tests.html'
extra_context = {
'tests_page': 'is-active', def get_context_data(self, **kwargs):
'editions': Edition.objects.order_by('-year') context = super().get_context_data(**kwargs)
} context['tests_page'] = 'is-active'
context['editions'] = Edition.objects.order_by('-year')
return context
def ScoresRedirect(request): def ScoresView(request, year = None):
latest = Edition.objects.filter(scores_available=True).order_by('-year').first() if year is not None:
edition = get_object_or_404(Edition, year=year)
if latest is not None:
return redirect(reverse_lazy('scores', args=[latest.year]))
else: else:
return redirect(reverse_lazy('home')) edition = Edition.objects.filter(scores_available=True).order_by('-year').first()
if edition is None:
edition = Edition.objects.order_by('-year').first()
def ScoresView(request, year): year = edition.year
edition = get_object_or_404(Edition, year=year)
if edition.scores_available is not True: context = {
return redirect('scores') 'scores_page': 'is-active',
'year': year,
'scores_available': edition.scores_available,
'editions': Edition.objects.order_by('year')
}
students = Student.objects.filter(identifier__startswith=year) students = Student.objects.filter(identifier__startswith=year)
@ -129,11 +146,9 @@ def ScoresView(request, year):
teams.append({**school, 'score': score_first * score_second}) teams.append({**school, 'score': score_first * score_second})
context = { context = {
'scores_page': 'is-active',
'year': year,
'editions': Edition.objects.filter(scores_available=True),
'individual': sorted(individual, key=lambda x: -x['score']), 'individual': sorted(individual, key=lambda x: -x['score']),
'teams': sorted(teams, key=lambda x: -x['score']) 'teams': sorted(teams, key=lambda x: -x['score']),
**context
} }
return render(request, 'scores.html', context) return render(request, 'scores.html', context)
@ -154,6 +169,9 @@ class RobotsView(TemplateView):
class SitemapView(TemplateView): class SitemapView(TemplateView):
template_name = 'sitemap.xml' template_name = 'sitemap.xml'
content_type = 'text/xml' content_type = 'text/xml'
extra_context = {
'latest': Announcement.objects.first() def get_context_data(self, **kwargs):
} context = super().get_context_data(**kwargs)
context['latest'] = Announcement.objects.first()
return context

View File

@ -89,11 +89,12 @@ X_FRAME_OPTIONS = 'SAMEORIGIN'
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': os.getenv('DB_ENGINE'), 'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.getenv('DB_NAME'), 'NAME': 'puchar_lo5',
'HOST': os.getenv('DB_HOST'),
'USER': os.getenv('DB_USER'), 'USER': os.getenv('DB_USER'),
'PASSWORD': os.getenv('DB_PASSWORD'), 'PASSWORD': os.getenv('DB_PASSWORD'),
'HOST': '127.0.0.1',
'PORT': '5432'
} }
} }

View File

@ -1,7 +1,7 @@
Django Django
django-cleanup django-cleanup
django-crispy-forms==1.12.0 django-crispy-forms
django-summernote django-summernote
django-crispy-bulma django-crispy-bulma
psycopg2-binary
python-dotenv python-dotenv