Skip to content
Snippets Groups Projects
Commit cb416e63 authored by Zdenek Kubala's avatar Zdenek Kubala
Browse files

enhanced views of sifrovacky

* sifrovacky are now visible as ACTIVE, SUBSCRIBED, ARCHIVED
  at index page and home page
parent 642ee0c2
No related branches found
No related tags found
1 merge request!1enhanced views of sifrovacky
# 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')},
),
]
# 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),
),
]
# 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(),
),
]
# 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'),
),
]
...@@ -10,6 +10,7 @@ class Sifrovacka(models.Model): ...@@ -10,6 +10,7 @@ class Sifrovacka(models.Model):
model which describes sifrovacka model which describes sifrovacka
''' '''
sifrovacka_name = models.CharField(max_length=200) sifrovacka_name = models.CharField(max_length=200)
#pub_date = models.DateField()
pub_date = models.DateTimeField('date published') pub_date = models.DateTimeField('date published')
startdate_sifrovacka = models.DateField() startdate_sifrovacka = models.DateField()
enddate_sifrovacka = models.DateField() enddate_sifrovacka = models.DateField()
...@@ -18,6 +19,8 @@ class Sifrovacka(models.Model): ...@@ -18,6 +19,8 @@ class Sifrovacka(models.Model):
return self.sifrovacka_name return self.sifrovacka_name
class Stages(models.Model): class Stages(models.Model):
''' '''
model which describes how many stages are in particular sifrovacka model which describes how many stages are in particular sifrovacka
...@@ -38,13 +41,17 @@ class Stages(models.Model): ...@@ -38,13 +41,17 @@ class Stages(models.Model):
return str(self.sifrovacka) + " - Stage " + str(self.stage_number) return str(self.sifrovacka) + " - Stage " + str(self.stage_number)
class Meta:
unique_together = [['stage_number', 'sifrovacka']]
class Participants(models.Model): class Participants(models.Model):
''' '''
table which connects sifrovacka with users who participate table which connects sifrovacka with users who participate
''' '''
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete = models.CASCADE) user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete = models.CASCADE)
sifrovacka = models.ForeignKey(Sifrovacka, on_delete = models.CASCADE) sifrovacka = models.ForeignKey(Sifrovacka, on_delete = models.CASCADE)
Inactive = models.BooleanField() Inactive = models.BooleanField(default = False)
def __str__(self): def __str__(self):
return str(self.user) + " - " + str(self.sifrovacka) return str(self.user) + " - " + str(self.sifrovacka)
......
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
<div class="navbar__brand my-4 flex items-center lg:pr-8 lg:my-0"> <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> <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"> <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 %} {% if settings.SIFROVACKA_ENV == "dev" %}<sup class="text-cyan-100">(DEV)</sup>{% endif %}
</span> </span>
</div> </div>
...@@ -68,7 +68,7 @@ ...@@ -68,7 +68,7 @@
</div> </div>
<div class="flex items-center space-x-4"> <div class="flex items-center space-x-4">
{% if user.is_authenticated %} {% if user.is_authenticated %}
<span class="head-heavy-2xs">{{ user }}</span> <span class="head-heavy-2xs"><a href={% url "home" %}>{{ user }}</a></span>
{% comment %} {% comment %}
{% endcomment %} {% endcomment %}
<form action="{% url "logout" %}" method="post"> <form action="{% url "logout" %}" method="post">
......
...@@ -2,29 +2,19 @@ ...@@ -2,29 +2,19 @@
{% if request.user.is_authenticated %} {% if request.user.is_authenticated %}
{% block content %} {% block content %}
<ul> <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 %} {% 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 %} {% endcomment %}
{% if participation_sifrovacky_list %} {% if participation_sifrovacky_list %}
<ul> <ul>
<p> <b>Přihlášené sifrovacky: </b> </p> <p> <b>Přihlášené sifrovacky: </b> </p>
{% for sifrovacka in participation_sifrovacky_list %} {% for sifrovacka in participation_sifrovacky_list %}
<li><a href={% url 'detail' sifrovacka.id %}>{{ sifrovacka }}</a></li> <li><a href={% url 'detail' sifrovacka.sifrovacka_id %}>{{ sifrovacka }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
{% else %} {% else %}
<p>Žádné šifrovačky nejsou aktivní.</p> <p>Zadne sifrovacky nemate aktivní.</p>
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{{% endif %} {{% endif %}
......
...@@ -2,16 +2,36 @@ ...@@ -2,16 +2,36 @@
{% block content %} {% block content %}
{% if sifrovacky_list %} {% if sifrovacky_list %}
{% comment %}
{% if request.user.is_authenticated %}
{% for sifrovacka in available_sifrovacky_list %}
{% endcomment %}
<ul> <ul>
<p> <b>Aktivni sifrovacky: </b> </p> <p> <b>Aktivni sifrovacky: </b> </p>
{% for sifrovacka in sifrovacky_list %} {% for sifrovacka in sifrovacky_list %}
<li><a href={% url 'detail' sifrovacka.id %}>{{ sifrovacka.sifrovacka_name }}</a></li> <li><a href={% url 'detail' sifrovacka.id %}>{{ sifrovacka.sifrovacka_name }}</a></li>
{% endfor %} {% endfor %}
{% for sifrovacka in participants.all %} </ul>
<li><a href="/sifrovacka/{{ sifrovacka.id }}">{{ sifrovacka.sifrovacka_name }}</a></li> {% 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 %} {% endfor %}
</ul> </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 %} {% else %}
<p>Žádné šifrovačky nejsou aktivní.</p> <p>Je nam lito, ale zadne sifrovacky nejsou aktualne dostupne.</p>
{% endif %} {% endif %}
{% endblock %} {% endblock %}
...@@ -8,6 +8,27 @@ ...@@ -8,6 +8,27 @@
Casova narocnost: NONE</p> Casova narocnost: NONE</p>
</br> </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> </br>
</br> </br>
......
from django.shortcuts import render from django.shortcuts import render
# Create your views here. # Create your views here.
from django.utils import timezone
from django.http import HttpResponse from django.http import HttpResponse
from django.template import loader from django.template import loader
from django.contrib.auth import login,logout from django.contrib.auth import login,logout
...@@ -23,12 +24,17 @@ def home(request): ...@@ -23,12 +24,17 @@ def home(request):
if request.user.is_authenticated: if request.user.is_authenticated:
participation_sifrovacky_list = Participants.objects.filter(user = participation_sifrovacky_list = Participants.objects.filter(user =
request.user).order_by('sifrovacka_id') request.user).order_by('sifrovacka_id')
#request.user).order_by('sifrovacka_id')
# available_sifrovacky_list = all_sifrovacky_list.difference( # available_sifrovacky_list = all_sifrovacky_list.difference(
#participation_sifrovacky_list) #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: else:
participation_sifrovacky_list = None participation_sifrovacky_list = None
# sifrovacka_name = Sifrovacka.objects.get(id = sifrovacka_id) # sifrovacka_name = Sifrovacka.objects.get(id = sifrovacka_id)
context = {"active_sifrovacky_list": all_sifrovacky_list, context = {"active_sifrovacky_list": all_sifrovacky_list,
...@@ -39,8 +45,38 @@ def home(request): ...@@ -39,8 +45,38 @@ def home(request):
return render(request, 'home.html', context) return render(request, 'home.html', context)
def index(request): def index(request):
list_all_sifrovacky = Sifrovacka.objects.all() if request.user.is_authenticated:
context = {"sifrovacky_list": list_all_sifrovacky} 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 = {"": ""} #context = {"": ""}
return render(request, 'index.html', context) return render(request, 'index.html', context)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment