diff --git a/app/templates/base.html b/app/templates/base.html index f1b80fb..20931db 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -33,7 +33,7 @@ }); - + Konkurs Matematyczny o Puchar Dyrektora V Liceum Ogólnokształcącego w Bielsku-Białej @@ -50,6 +50,7 @@ Aktualności + O konkursie Regulamin Zadania Wyniki diff --git a/app/templates/scores.html b/app/templates/scores.html index 11d668c..e72804d 100644 --- a/app/templates/scores.html +++ b/app/templates/scores.html @@ -7,13 +7,14 @@ {% for edition in editions %} - {{ edition.roman }} {% endfor %} +{% if scores_available %} Klasyfikacja indywidualna @@ -75,4 +76,9 @@ {% endfor %} +{% else %} + + Wyniki niedostępne + +{% endif %} {% endblock %} diff --git a/app/templates/sitemap.xml b/app/templates/sitemap.xml index e7fb187..92a8fd2 100644 --- a/app/templates/sitemap.xml +++ b/app/templates/sitemap.xml @@ -3,14 +3,14 @@ https://puchar.lo5.bielsko.pl 1.0 - yearly - - - https://puchar.lo5.bielsko.pl/aktualnosci - 0.9 {{ latest.created_at | date:"Y-m-d" }} monthly + + https://puchar.lo5.bielsko.pl/konkurs + 0.9 + yearly + https://puchar.lo5.bielsko.pl/regulamin 0.8 diff --git a/app/templates/user/account.html b/app/templates/user/account.html index adb3ae2..02ac13a 100644 --- a/app/templates/user/account.html +++ b/app/templates/user/account.html @@ -15,7 +15,7 @@ {% csrf_token %} {{ form | crispy }} - Zaktualizuj + Zaktualizuj Zmień hasło diff --git a/app/templates/user/submit.html b/app/templates/user/submit.html index 315685e..f0dc5b4 100644 --- a/app/templates/user/submit.html +++ b/app/templates/user/submit.html @@ -6,7 +6,13 @@ {% block tab %} - Zgłoś uczniów + + {% if students %} + Edytuj zgłoszenie + {% else %} + Zgłoś uczniów + {% endif %} + {% csrf_token %} {{ formset.management_form | crispy }} @@ -17,6 +23,11 @@ {{ form.grade | as_crispy_field }} {% endfor %} - Zgłoś + + {% if students %} + Edytuj + {% else %} + Zgłoś + {% endif %} {% endblock %} diff --git a/app/urls.py b/app/urls.py index 5992f5b..d6c3e7e 100644 --- a/app/urls.py +++ b/app/urls.py @@ -1,13 +1,15 @@ 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 = [ - path('', HomeView.as_view(), name='home'), - path('aktualnosci/', NewsView.as_view(), name='news'), + path('', 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('zadania/', TestsView.as_view(), name='tests'), - path('wyniki/', ScoresRedirect, name='scores'), + path('wyniki/', ScoresView, name='scores'), path('wyniki//', ScoresView, name='scores'), path('kontakt/', ContactView.as_view(), name='contact'), path('rejestracja/', SignUpView.as_view(), name='signup'), diff --git a/app/views.py b/app/views.py index ab7e4d8..3ec22b4 100644 --- a/app/views.py +++ b/app/views.py @@ -34,15 +34,20 @@ def SubmitStudentsView(request): edition = Edition.current() 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: - identifier = f'{edition.year}-{request.user.id}' - 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}) + queryset = Student.objects.filter(identifier__startswith=f'{edition.year}-{request.user.id}').order_by('identifier') - 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': with transaction.atomic(): @@ -56,21 +61,27 @@ def SubmitStudentsView(request): else: 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: return redirect(reverse_lazy('account')) -class HomeView(TemplateView): +class AboutContestView(TemplateView): template_name = 'home.html' + extra_context = { + 'aboutcontest_page': 'is-active' + } class NewsView(TemplateView): template_name = 'news.html' - extra_context = { - 'news_page': 'is-active', - 'announcements': Announcement.objects.all(), - } + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['news_page'] = 'is-active' + context['announcements'] = Announcement.objects.all() + + return context class RulesView(TemplateView): @@ -82,26 +93,32 @@ class RulesView(TemplateView): class TestsView(TemplateView): template_name = 'tests.html' - extra_context = { - 'tests_page': 'is-active', - 'editions': Edition.objects.order_by('-year') - } + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['tests_page'] = 'is-active' + context['editions'] = Edition.objects.order_by('-year') + + return context -def ScoresRedirect(request): - latest = Edition.objects.filter(scores_available=True).order_by('-year').first() - - if latest is not None: - return redirect(reverse_lazy('scores', args=[latest.year])) +def ScoresView(request, year = None): + if year is not None: + edition = get_object_or_404(Edition, year=year) 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): - edition = get_object_or_404(Edition, year=year) + year = edition.year - if edition.scores_available is not True: - return redirect('scores') + context = { + 'scores_page': 'is-active', + 'year': year, + 'scores_available': edition.scores_available, + 'editions': Edition.objects.order_by('year') + } students = Student.objects.filter(identifier__startswith=year) @@ -129,11 +146,9 @@ def ScoresView(request, year): teams.append({**school, 'score': score_first * score_second}) context = { - 'scores_page': 'is-active', - 'year': year, - 'editions': Edition.objects.filter(scores_available=True), '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) @@ -154,6 +169,9 @@ class RobotsView(TemplateView): class SitemapView(TemplateView): template_name = 'sitemap.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 diff --git a/puchar/settings.py b/puchar/settings.py index d407f48..f2d436d 100644 --- a/puchar/settings.py +++ b/puchar/settings.py @@ -89,11 +89,12 @@ X_FRAME_OPTIONS = 'SAMEORIGIN' DATABASES = { 'default': { - 'ENGINE': os.getenv('DB_ENGINE'), - 'NAME': os.getenv('DB_NAME'), - 'HOST': os.getenv('DB_HOST'), + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'puchar_lo5', 'USER': os.getenv('DB_USER'), 'PASSWORD': os.getenv('DB_PASSWORD'), + 'HOST': '127.0.0.1', + 'PORT': '5432' } } diff --git a/requirements.txt b/requirements.txt index edec3fb..74eeacf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ Django django-cleanup -django-crispy-forms==1.12.0 +django-crispy-forms django-summernote django-crispy-bulma - +psycopg2-binary python-dotenv