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>
<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="subtitle is-4 mx-auto">o Puchar Dyrektora V Liceum Ogólnokształcącego w Bielsku-Białej</span>
</a>
@ -50,6 +50,7 @@
<div id="navbar" class="navbar-menu">
<div class="navbar-start">
<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 {{ tests_page }}" href="{% url 'tests' %}">Zadania</a>
<a class="navbar-item {{ scores_page }}" href="{% url 'scores' %}">Wyniki</a>

View File

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

View File

@ -3,14 +3,14 @@
<url>
<loc>https://puchar.lo5.bielsko.pl</loc>
<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>
<changefreq>monthly</changefreq>
</url>
<url>
<loc>https://puchar.lo5.bielsko.pl/konkurs</loc>
<priority>0.9</priority>
<changefreq>yearly</changefreq>
</url>
<url>
<loc>https://puchar.lo5.bielsko.pl/regulamin</loc>
<priority>0.8</priority>

View File

@ -15,7 +15,7 @@
{% csrf_token %}
{{ form | crispy }}
<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>
</div>
</form>

View File

@ -6,7 +6,13 @@
{% block tab %}
<form class="is-flex is-flex-direction-column" method="POST">
<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>
{% csrf_token %}
{{ formset.management_form | crispy }}
@ -17,6 +23,11 @@
<div class="column is-2">{{ form.grade | as_crispy_field }}</div>
</div>
{% 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>
{% endblock %}

View File

@ -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/<int:year>/', ScoresView, name='scores'),
path('kontakt/', ContactView.as_view(), name='contact'),
path('rejestracja/', SignUpView.as_view(), name='signup'),

View File

@ -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]))
else:
return redirect(reverse_lazy('home'))
def ScoresView(request, year):
def ScoresView(request, year = None):
if year is not None:
edition = get_object_or_404(Edition, year=year)
else:
edition = Edition.objects.filter(scores_available=True).order_by('-year').first()
if edition.scores_available is not True:
return redirect('scores')
if edition is None:
edition = Edition.objects.order_by('-year').first()
year = edition.year
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

View File

@ -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'
}
}

View File

@ -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