+ {% if messages %} + {% for message in messages %} +
{{ message }}
+ {% endfor %} + {% endif %} {% block content %} {% endblock %}
diff --git a/TSDMaster/TSDMaster/templates/login.html b/TSDMaster/TSDMaster/templates/login.html index c245c89..2eae0cb 100644 --- a/TSDMaster/TSDMaster/templates/login.html +++ b/TSDMaster/TSDMaster/templates/login.html @@ -8,7 +8,7 @@
{% csrf_token %} -

Use a local account to log in.

+

Use a local account to log in. Or register


diff --git a/TSDMaster/TSDMaster/templates/loginpartial.html b/TSDMaster/TSDMaster/templates/loginpartial.html index f5fb075..4bbdb50 100644 --- a/TSDMaster/TSDMaster/templates/loginpartial.html +++ b/TSDMaster/TSDMaster/templates/loginpartial.html @@ -1,14 +1,13 @@ {% load i18n %} {% if user.is_authenticated %} - + {% csrf_token %} - + {{ user }} + {% if user.is_staff %} + Admin + {% endif %} + {% trans "Logout" %} {% else %} - + {% trans "Login" %} {% endif %} diff --git a/TSDMaster/TSDMaster/templates/register.html b/TSDMaster/TSDMaster/templates/register.html new file mode 100644 index 0000000..a05f768 --- /dev/null +++ b/TSDMaster/TSDMaster/templates/register.html @@ -0,0 +1,30 @@ +{% extends 'layout.html' %} +{% block content %} +

Registration

+ {% if errors %} +
{{ errors }}
+ {% endif %} +
+
+ {% csrf_token %} +
+ +
+ {{ form.username }} +
+
+
+ +
+ {{ form.password1 }} +
+
+
+ +
+ {{ form.password2 }} +
+
+ +
+{% endblock %} diff --git a/TSDMaster/TSDMaster/urls.py b/TSDMaster/TSDMaster/urls.py index 43da21f..40fd0bc 100644 --- a/TSDMaster/TSDMaster/urls.py +++ b/TSDMaster/TSDMaster/urls.py @@ -17,11 +17,15 @@ from datetime import datetime from django.conf.urls import url, include from django.contrib import admin import django.contrib.auth.views +from django.conf import settings from TSDMaster import views from TSDMaster import forms urlpatterns = [ url(r'^$', views.home, name='home'), + url(r'^all_contests$', views.all_contests, name='all_contests'), + url(r'^enter_contest$', views.enter_contest, name='enter_contest'), + url(r'^contest$', views.contest, name='contest'), url(r'^login/$', django.contrib.auth.views.login, { @@ -30,7 +34,7 @@ urlpatterns = [ 'extra_context': { 'title': 'Log in', - 'year': datetime.now().year, + 'company_name': settings.COMPANY_NAME, } }, name='login'), @@ -40,5 +44,6 @@ urlpatterns = [ 'next_page': '/', }, name='logout'), + url(r'^register$', views.register, name='register'), url(r'^admin/', admin.site.urls), ] diff --git a/TSDMaster/TSDMaster/views.py b/TSDMaster/TSDMaster/views.py index 15298de..ee842b5 100644 --- a/TSDMaster/TSDMaster/views.py +++ b/TSDMaster/TSDMaster/views.py @@ -1,5 +1,8 @@ -from django.shortcuts import render +from django.shortcuts import render, redirect from django.conf import settings +from django.contrib.messages import add_message, SUCCESS +from TSDMaster import forms +from TSDMaster.models import Contest, UserContest, Try, Problem # TestSys views here. @@ -10,3 +13,73 @@ def home(request): 'title': 'Home', 'company_name': settings.COMPANY_NAME, }) + + +def register(request): + if request.method == 'POST': + form = forms.BootstrapUserCreationForm(request.POST) + if form.is_valid(): + form.save() + add_message(request, SUCCESS, 'You may login now') + return redirect('login') + return render(request, 'register.html', + { + 'errors': form.errors, + 'form': forms.BootstrapUserCreationForm, + 'title': 'Register', + 'company_name': settings.COMPANY_NAME, + }) + else: + return render(request, 'register.html', + { + 'form': forms.BootstrapUserCreationForm, + 'title': 'Register', + 'company_name': settings.COMPANY_NAME, + }) + + +def all_contests(request): + return render(request, 'all_contests.html', { + 'contests': Contest.objects.filter(opened=True), + 'title': 'All contests', + 'company_name': settings.COMPANY_NAME, + }) + + +def enter_contest(request): + # TODO: Check contest available + try: + conq = UserContest.objects.get(user=request.user) + conq.contest_id = int(request.GET['id']) + conq.save() + except Exception: + UserContest(user=request.user, contest_id=int(request.GET['id'])).save() + return redirect('/contest') + + +def contest(request): + cur_contest = UserContest.objects.get(user=request.user).contest + problems = Problem.objects.filter(contest=cur_contest) + trys = Try.objects.filter(contest=cur_contest) + users = set() + problems_trys = {} + for tryi in trys: + if tryi.owner not in users: + users.add(tryi.owner) + problems_trys[tryi.owner] = {} + for problem in problems: + problems_trys[tryi.owner][problem] = [0, False] + if not problems_trys[tryi.owner][tryi.problem]: + if tryi.status == 'PE' or tryi.status == 'WA' or tryi.status == 'TL' or tryi.status == 'ML' or tryi.status == 'AR': + problems_trys[tryi.owner][tryi.problem][0] += 1 + elif tryi.status == 'OK': + problems_trys[tryi.owner][tryi.problem][1] = True + # TODO: Presentation + return render(request, 'contest.html', { + 'contest': cur_contest, + 'problems': problems, + 'competitors': users, + 'problem_trys': problems_trys, + 'title': 'Contest', + 'company_name': settings.COMPANY_NAME, + }) diff --git a/TSDMaster/manage.py b/TSDMaster/manage.py index 89cf823..c48f1dd 100755 --- a/TSDMaster/manage.py +++ b/TSDMaster/manage.py @@ -3,7 +3,7 @@ import os import sys if __name__ == "__main__": - if os.path.isfile('settings'): + if os.path.isfile('settings.py'): os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") else: os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings_example")