diff --git a/sifrovacka/migrations/0008_auto_20210831_1055.py b/sifrovacka/migrations/0008_auto_20210831_1055.py new file mode 100644 index 0000000000000000000000000000000000000000..f21485236be6f4f6f3859aac0982dbd3bac429ad --- /dev/null +++ b/sifrovacka/migrations/0008_auto_20210831_1055.py @@ -0,0 +1,22 @@ +# Generated by Django 3.2.3 on 2021-08-31 10:55 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sifrovacka', '0007_alter_participants_unique_together'), + ] + + operations = [ + migrations.AlterField( + model_name='participants', + name='Inactive', + field=models.BooleanField(blank=True), + ), + migrations.AlterUniqueTogether( + name='stages', + unique_together={('stage_number', 'sifrovacka')}, + ), + ] diff --git a/sifrovacka/migrations/0009_alter_participants_inactive.py b/sifrovacka/migrations/0009_alter_participants_inactive.py new file mode 100644 index 0000000000000000000000000000000000000000..aab5b018fbb83358b4a32171f8a93e7c266fbb79 --- /dev/null +++ b/sifrovacka/migrations/0009_alter_participants_inactive.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.3 on 2021-08-31 11:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sifrovacka', '0008_auto_20210831_1055'), + ] + + operations = [ + migrations.AlterField( + model_name='participants', + name='Inactive', + field=models.BooleanField(default=False), + ), + ] diff --git a/sifrovacka/migrations/0010_alter_sifrovacka_pub_date.py b/sifrovacka/migrations/0010_alter_sifrovacka_pub_date.py new file mode 100644 index 0000000000000000000000000000000000000000..861feedf3baf6d956376d31aa39d58de7801c66a --- /dev/null +++ b/sifrovacka/migrations/0010_alter_sifrovacka_pub_date.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.3 on 2021-08-31 18:12 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sifrovacka', '0009_alter_participants_inactive'), + ] + + operations = [ + migrations.AlterField( + model_name='sifrovacka', + name='pub_date', + field=models.DateField(), + ), + ] diff --git a/sifrovacka/migrations/0011_alter_sifrovacka_pub_date.py b/sifrovacka/migrations/0011_alter_sifrovacka_pub_date.py new file mode 100644 index 0000000000000000000000000000000000000000..1148044bd6e8bdac3cda6edad7a56ec8c0ae6837 --- /dev/null +++ b/sifrovacka/migrations/0011_alter_sifrovacka_pub_date.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.3 on 2021-08-31 18:13 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sifrovacka', '0010_alter_sifrovacka_pub_date'), + ] + + operations = [ + migrations.AlterField( + model_name='sifrovacka', + name='pub_date', + field=models.DateTimeField(verbose_name='date published'), + ), + ] diff --git a/sifrovacka/models.py b/sifrovacka/models.py index fe5d66d680156c2645fd95ab9cb02726d2b116b5..6cf73731103779e0a53df9054db62b9f8e01c4eb 100644 --- a/sifrovacka/models.py +++ b/sifrovacka/models.py @@ -10,6 +10,7 @@ class Sifrovacka(models.Model): model which describes sifrovacka ''' sifrovacka_name = models.CharField(max_length=200) + #pub_date = models.DateField() pub_date = models.DateTimeField('date published') startdate_sifrovacka = models.DateField() enddate_sifrovacka = models.DateField() @@ -18,6 +19,8 @@ class Sifrovacka(models.Model): return self.sifrovacka_name + + class Stages(models.Model): ''' model which describes how many stages are in particular sifrovacka @@ -38,13 +41,17 @@ class Stages(models.Model): return str(self.sifrovacka) + " - Stage " + str(self.stage_number) + class Meta: + unique_together = [['stage_number', 'sifrovacka']] + + class Participants(models.Model): ''' table which connects sifrovacka with users who participate ''' - user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) - sifrovacka = models.ForeignKey(Sifrovacka, on_delete=models.CASCADE) - Inactive = models.BooleanField() + user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete = models.CASCADE) + sifrovacka = models.ForeignKey(Sifrovacka, on_delete = models.CASCADE) + Inactive = models.BooleanField(default = False) def __str__(self): return str(self.user) + " - " + str(self.sifrovacka) diff --git a/sifrovacka/templates/base.html b/sifrovacka/templates/base.html index 28bd8c555aa3cf86d984ba7804b3d9ce5b5ea8ee..58a9f665ff9bac18b4c20e78822b55c3a2e0d32e 100644 --- a/sifrovacka/templates/base.html +++ b/sifrovacka/templates/base.html @@ -51,7 +51,7 @@ <div class="navbar__brand my-4 flex items-center lg:pr-8 lg:my-0"> <a href="/"><img src="https://styleguide.pir-test.eu/2.3.x/images/logo-round-white.svg" class="w-8"></a> <span class="pl-4 font-bold text-xl lg:border-r lg:border-grey-300 lg:pr-8"> - Šifrovačky + <a href={% url "index"%}>Sifrovacky</a> {% if settings.SIFROVACKA_ENV == "dev" %}<sup class="text-cyan-100">(DEV)</sup>{% endif %} </span> </div> @@ -68,7 +68,7 @@ </div> <div class="flex items-center space-x-4"> {% if user.is_authenticated %} - <span class="head-heavy-2xs">{{ user }}</span> + <span class="head-heavy-2xs"><a href={% url "home" %}>{{ user }}</a></span> {% comment %} {% endcomment %} <form action="{% url "logout" %}" method="post"> diff --git a/sifrovacka/templates/home.html b/sifrovacka/templates/home.html index e5ff0d0d7b24743e87140dc965611ecb6eda7a7c..0770db61a841e9df02485adbedf62815a3cf89b8 100644 --- a/sifrovacka/templates/home.html +++ b/sifrovacka/templates/home.html @@ -2,31 +2,21 @@ {% if request.user.is_authenticated %} {% block content %} <ul> - <p> <b>Dostupne sifrovacky: </b> <a href={% url 'index' %}a> Zde </a></p> + <p> <b>Dostupne sifrovacky: </b> <a href={% url 'index' %}> Zde </a></p> {% comment %} - {% if available_sifrovacky_list %} - - {% for sifrovacka in avalable_sifrovacky_list %} - <li><a href={% url 'detail' sifrovacka.id %}>{{ sifrovacka }}</a></li> - {% endfor %} - </ul> -{% else %} - <p>Žádné šifrovačky nejsou aktivní.</p> - {% endif %} - {% endcomment %} - {% if participation_sifrovacky_list %} - <ul> - <p> <b>Přihlášené sifrovacky: </b> </p> - {% for sifrovacka in participation_sifrovacky_list %} - <li><a href={% url 'detail' sifrovacka.id %}>{{ sifrovacka }}</a></li> - {% endfor %} - </ul> -{% else %} - <p>Žádné šifrovačky nejsou aktivní.</p> -{% endif %} -{% endblock %} + {% if participation_sifrovacky_list %} + <ul> + <p> <b>Přihlášené sifrovacky: </b> </p> + {% for sifrovacka in participation_sifrovacky_list %} + <li><a href={% url 'detail' sifrovacka.sifrovacka_id %}>{{ sifrovacka }}</a></li> + {% endfor %} + </ul> + {% else %} + <p>Zadne sifrovacky nemate aktivní.</p> + {% endif %} + {% endblock %} {{% endif %} {% comment %} diff --git a/sifrovacka/templates/index.html b/sifrovacka/templates/index.html index f58a1ae29767c13c1c0029063f928a70aa233312..f33ceda666e63bdfb2d4ec726d867cdf999eede6 100644 --- a/sifrovacka/templates/index.html +++ b/sifrovacka/templates/index.html @@ -2,16 +2,36 @@ {% block content %} {% if sifrovacky_list %} - <ul> - <p> <b>Aktivni sifrovacky: </b> </p> - {% for sifrovacka in sifrovacky_list %} - <li><a href={% url 'detail' sifrovacka.id %}>{{ sifrovacka.sifrovacka_name }}</a></li> - {% endfor %} - {% for sifrovacka in participants.all %} - <li><a href="/sifrovacka/{{ sifrovacka.id }}">{{ sifrovacka.sifrovacka_name }}</a></li> - {% endfor %} - </ul> -{% else %} - <p>Žádné šifrovačky nejsou aktivní.</p> -{% endif %} +{% comment %} + {% if request.user.is_authenticated %} + {% for sifrovacka in available_sifrovacky_list %} +{% endcomment %} + <ul> + <p> <b>Aktivni sifrovacky: </b> </p> + {% for sifrovacka in sifrovacky_list %} + <li><a href={% url 'detail' sifrovacka.id %}>{{ sifrovacka.sifrovacka_name }}</a></li> + {% endfor %} + </ul> + {% if request.user.is_authenticated %} + <ul> + <p> <b>Prihlasene sifrovacky: </b> </p> + {% for sifrovacka in user_active_sifrovacky %} + <li><a href={% url 'detail' sifrovacka.sifrovacka.id %}>{{ sifrovacka }}</a></li> + {% endfor %} + </ul> + {% endif %} + <ul> + <p> <b>Ukoncene sifrovacky: </b> </p> + {% for sifrovacka in archived_sifrovacky %} + <li><a href={% url 'detail' sifrovacka.id %}>{{ sifrovacka.sifrovacka_name }}</a></li> + {% endfor %} + </ul> +{% comment %} + {% else %} + <p>Zadne sifrovacky nejsou aktivni nebo se ucastnite vsech dostupnych.</p> + {% endif %} +{% endcomment %} + {% else %} + <p>Je nam lito, ale zadne sifrovacky nejsou aktualne dostupne.</p> + {% endif %} {% endblock %} diff --git a/sifrovacka/templates/sifrovacka.html b/sifrovacka/templates/sifrovacka.html index 4e779f184b9cf5028280f52ab9e506b37fd1b59d..bb322a6288a6c565770dbf452259e7a227249ce0 100644 --- a/sifrovacka/templates/sifrovacka.html +++ b/sifrovacka/templates/sifrovacka.html @@ -8,6 +8,27 @@ Casova narocnost: NONE</p> </br> +{% if request.user.is_authenticated %} +<form action="{% url 'home' %}" method="post"> +{% csrf_token %} +{% comment %} +<form action="{% url 'sifrovacka:home' sifrovacka.id %}" method="post"> +{% csrf_token %} +<button type="submit" value=signupsif name='signupsif'>Prihlasit se k sifrovacce</button> +<button type="submit" value=signupsif onclick="location.href='{% url 'home' %}'" name='_signupsif'>Prihlasit se k sifrovacce</button> +<fieldset> + <legend><h1>{{ sifrovacka_detail }}</h1></legend> + {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %} + {% for choice in question.choice_set.all %} + <input type="radio" name="signupsif" id="signupsif" value="{{ sifrovacka_id }}"> + <label for="signupsif"> Začít šifrovačku</label><br> + {% endfor %} +</fieldset> +<input type="submit" name="signupsif" value={{ sifrovacka_id }}> +{% endcomment %} +<button type="submit" value={{ sifrovacka_id }} name='signupsif'>Prihlasit se k sifrovacce</button> +</form> +{% endif %} </br> </br> </br> diff --git a/sifrovacka/views.py b/sifrovacka/views.py index ddf73c5641715c614b580c5a40d28a99076a4417..c068f42fa8a8f2244dc70b73bcaafe16199a8e57 100644 --- a/sifrovacka/views.py +++ b/sifrovacka/views.py @@ -1,6 +1,7 @@ from django.shortcuts import render # Create your views here. +from django.utils import timezone from django.http import HttpResponse from django.template import loader from django.contrib.auth import login,logout @@ -23,24 +24,59 @@ def home(request): if request.user.is_authenticated: participation_sifrovacky_list = Participants.objects.filter(user = request.user).order_by('sifrovacka_id') - #request.user).order_by('sifrovacka_id') # available_sifrovacky_list = all_sifrovacky_list.difference( #participation_sifrovacky_list) + if request.method == 'POST': + if request.POST["signupsif"]: + print(request.POST["signupsif"]) + p = Participants.objects.create(user_id=1, sifrovacka_id=1) + p.save() else: participation_sifrovacky_list = None + # sifrovacka_name = Sifrovacka.objects.get(id = sifrovacka_id) context = {"active_sifrovacky_list": all_sifrovacky_list, "participation_sifrovacky_list": participation_sifrovacky_list} - + # import pdb # pdb.set_trace() return render(request, 'home.html', context) def index(request): - list_all_sifrovacky = Sifrovacka.objects.all() - context = {"sifrovacky_list": list_all_sifrovacky} + if request.user.is_authenticated: + list_user_active_sifrovacky = Participants.objects.filter( user = + request.user).order_by('sifrovacka_id') + #list_user_active_sifrovacky = request.user.participants_set.values_list( + # 'sifrovacka_id') + list_all_user_sifrovacky = request.user.participants_set.values_list( + 'sifrovacka_id', flat=True) + print(list_user_active_sifrovacky) + list_available = Sifrovacka.objects.filter( + startdate_sifrovacka__lte = timezone.now()).filter( + enddate_sifrovacka__gte = timezone.now()).exclude( + id__in=list_all_user_sifrovacky) + #print(list_available) + list_all_sifrovacky = list_available + + + else: + list_all_sifrovacky = Sifrovacka.objects.filter( + startdate_sifrovacka__lte = timezone.now()).filter( + enddate_sifrovacka__gte = timezone.now()) + list_user_active_sifrovacky = [] + + list_archived_sifrovacky = Sifrovacka.objects.filter( + startdate_sifrovacka__lte = timezone.now()).filter( + enddate_sifrovacka__lt = timezone.now()) + + + + context = {"sifrovacky_list": list_all_sifrovacky, + "archived_sifrovacky": list_archived_sifrovacky, + "user_active_sifrovacky": list_user_active_sifrovacky, + } #context = {"": ""} return render(request, 'index.html', context)