Skip to content
Snippets Groups Projects
Commit 1dc5f86f authored by zdenek.kubala's avatar zdenek.kubala
Browse files

Merge branch 'auth' into 'main'

enhanced views of sifrovacky

See merge request djz.88/sifrovacky!1
parents debc8a63 cb416e63
No related branches found
No related tags found
No related merge requests found
Showing
with 659 additions and 0 deletions
# 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'),
),
]
from django.db import models
# Create your models here.
from django.conf import settings
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()
def __str__(self):
return self.sifrovacka_name
class Stages(models.Model):
'''
model which describes how many stages are in particular sifrovacka
'''
stage_name = models.CharField(max_length=200)
sifrovacka = models.ForeignKey(Sifrovacka, on_delete=models.CASCADE)
stage_number = models.IntegerField()
# if not stage_name_text models:
# stage_name = getattr(Stages, sifrovacka_name)
# "-" + getattr(Stages, stage_number))
# else:
# stage_name = stage_name_text
# votes = models.IntegerField(default=0)
# startdate_stages = models.DateField()
# enddate_stages= models.DateField()
def __str__(self):
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(default = False)
def __str__(self):
return str(self.user) + " - " + str(self.sifrovacka)
class Meta:
unique_together = [['user', 'sifrovacka']]
{% load static %}
<!doctype html>
<html lang="cs">
<head>
<!-- Meta -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width" />
{% if settings.SIFROVACKA_ENV == "test" %}
<meta name="robots" content="noindex, nofollow">
{% endif %}
<!-- Favicon -->
{% comment%}
{% include "shared/favicon_snippet.html" %}
{% endcomment %}
<!-- Styles -->
<link href="https://styleguide.pir-test.eu/2.3.x/css/styles.css" rel="stylesheet" media="all" />
<style type="text/css">
.head-alt-md, .head-alt-lg {
line-height: 1.25;
}
.content-block a {
color: #004958;
}
.text-white a {
color: #FFFFFF;
}
a.btn {
text-decoration: none !important;
}
</style>
{% if settings.SIFROVACKA_ENV == "prod" and settings.ONBOARDING_MATOMO_ID %}
{% include "shared/matomo_snippet.html" with matomo_id=settings.ONBOARDING_MATOMO_ID %}
{% endif %}
<title>Šifrovačky</title>
</head>
<body>
{% if settings.SIFROVACKA_ENV == "test" %}
<div class="bg-yellow-200 p-2 text-center flex-grow"><b>TESTOVACÍ VERZE!</b> &nbsp;&nbsp; Informace nemusejí odpovídat skutečnosti.</div>
{% endif %}
<nav class="navbar navbar--simple __js-root">
<div>
<div class="container container--wide navbar__content navbar__content--initialized">
<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">
<a href={% url "index"%}>Sifrovacky</a>
{% if settings.SIFROVACKA_ENV == "dev" %}<sup class="text-cyan-100">(DEV)</sup>{% endif %}
</span>
</div>
<div class="navbar__menutoggle my-4 flex justify-end lg:hidden">
<a href="#" class="no-underline hover:no-underline"><i class="ico--menu text-3xl"></i></a>
</div>
<div class="navbar__main navbar__section navbar__section--expandable container-padding--zero lg:container-padding--auto flex items-center">
<div class="flex-grow">
<ul class="navbar-menu text-white">
<li class="navbar-menu__item">
<!--<a href="#" data-href="#" class="navbar-menu__link">Hlavní strana</a>-->
</li>
</ul>
</div>
<div class="flex items-center space-x-4">
{% if user.is_authenticated %}
<span class="head-heavy-2xs"><a href={% url "home" %}>{{ user }}</a></span>
{% comment %}
{% endcomment %}
<form action="{% url "logout" %}" method="post">
{% csrf_token %}
<button class="text-grey-200 hover:text-white" title="Odhlásit se"><i class="ico--log-out"></i></button>
</form>
{% else %}
{% comment %}
{% endcomment %}
<a class="btn btn--grey-125 btn--hoveractive btn--to-white" href="{% url "login" %}">
<div class="btn__body ">přihlášení</div>
</a>
<a class="btn btn--grey-125 btn--hoveractive btn--to-white" href="{% url "django_registration_register" %}">
<div class="btn__body ">registrace</div>
</a>
{% endif %}
</div>
</div>
</div>
</div>
</nav>
{% if messages %}
<div class="container container--default pt-3">
{% for message in messages %}
<div class="alert alert--{{ message.level_tag }}">{{ message }}</div>
{% endfor %}
</div>
{% endif %}
<div class="container container--default py-8 lg:py-24">
<div class="content-block">
{% block content %}{% endblock %}
</div>
</div>
<footer class="footer bg-grey-700 text-white __js-root">
<ui-app inline-template>
<div>
<div class="footer__main py-4 lg:py-16 container container--default">
<section class="footer__brand">
<a href="https://www.pirati.cz">
<img src="https://styleguide.pir-test.eu/2.3.x/images/logo-full-white.svg" alt="logo pirátské strany" class="w-32 md:w-40 pb-6" />
</a>
<p class="para hidden md:block md:mb-4 lg:mb-0 text-grey-200">
<span class="copyleft inline-block">&copy;</span> {% now "Y" %} Piráti. Všechna práva vyhlazena. Sdílejte a nechte ostatní sdílet za stejných podmínek.
</p>
</section>
<section class="footer__social lg:text-right">
<div class="mb-4">
<div class="social-icon-group space-x-2 text-white pb-4">
<a href="https://www.pirati.cz" class="social-icon "><i class="ico--home"></i></a>
<a href="https://www.facebook.com/ceska.piratska.strana/" class="social-icon "><i class="ico--facebook"></i></a>
<a href="https://twitter.com/PiratskaStrana" class="social-icon "><i class="ico--twitter"></i></a>
<a href="https://www.youtube.com/user/CeskaPiratskaStrana" class="social-icon "><i class="ico--youtube"></i></a>
<a href="https://www.instagram.com/pirati.cz/" class="social-icon "><i class="ico--instagram"></i></a>
<a href="https://www.flickr.com/photos/pirati/" class="social-icon "><i class="ico--flickr"></i></a>
</div>
</div>
<div class="flex flex-col md:flex-row lg:flex-col lg:items-end space-y-2 md:space-y-0 md:space-x-2 lg:space-x-0 lg:space-y-2">
<a href="https://dary.pirati.cz" class="btn btn--icon btn--cyan-200 btn--hoveractive text-lg btn--fullwidth sm:btn--autowidth">
<div class="btn__body-wrap">
<div class="btn__body ">Přispěj</div>
<div class="btn__icon ">
<i class="ico--pig"></i>
</div>
</div>
</a>
<a href="https://nalodeni.pirati.cz" class="btn btn--icon btn--blue-300 btn--hoveractive text-lg btn--fullwidth sm:btn--autowidth">
<div class="btn__body-wrap">
<div class="btn__body ">Naloď se</div>
<div class="btn__icon ">
<i class="ico--anchor"></i>
</div>
</div>
</a>
</div>
</section>
</div>
</div>
</ui-app>
</footer>
<script src="{% static "shared/vendor/vue/vue.2.6.11.js" %}"></script>
<script src="https://styleguide.pir-test.eu/2.3.x/js/main.bundle.js"></script>
<script src="{% static "shared/vendor/jquery/jquery-3.4.1.min.js" %}"></script>
{% block extra_js %}{% endblock %}
</body>
</html>
{% extends "base.html" %}
{% comment %}
<h2>Sign up</h2>
<form method="post">
{% csrf_token %}
{% for field in form %}
<p>
{{ field.label_tag }}<br>
{{ field }}
{% if field.help_text %}
<small style="color: grey">{{ field.help_text }}</small>
{% endif %}
{% for error in field.errors %}
<p style="color: red">{{ error }}</p>
{% endfor %}
</p>
{% endfor %}
<button type="submit">Sign up</button>
</form>
{% endblock %}
{% endcomment %}
{% extends "django_registration/registration_base.html" %}
{% load i18n %}
{% block title %}{% trans "Registration is closed" %}{% endblock %}
{% block content %}
<p>{% trans "Sorry, but registration is closed at this moment. Come back later." %}</p>
{% endblock %}
{% extends "django_registration/registration_base.html" %}
{% load i18n %}
{% block title %}{% trans "Activation email sent" %}{% endblock %}
{% block content %}
<p>{% trans "Please check your email to complete the registration process." %}</p>
{% endblock %}
{% comment %}
**registration/registration_complete.html**
Used after successful completion of the registration form. This
template has no context variables of its own, and should simply inform
the user that an email containing account-activation information has
been sent.
{% endcomment %}
{% extends "django_registration/registration_base.html" %}
{% load i18n %}
{% block title %}{% trans "Register for an account" %}{% endblock %}
{% block content %}
<form method="post" action="">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="{% trans 'Submit' %}" />
</form>
{% endblock %}
{% comment %}
**registration/registration_form.html**
Used to show the form users will fill out to register. By default, has
the following context:
``form``
The registration form. This will be an instance of some subclass
of ``django.forms.Form``; consult `Django's forms documentation
<http://docs.djangoproject.com/en/dev/topics/forms/>`_ for
information on how to display this in a template.
{% endcomment %}
{% extends "base.html" %}
{% if request.user.is_authenticated %}
{% block content %}
<ul>
<p> <b>Dostupne sifrovacky: </b> <a href={% url 'index' %}> Zde </a></p>
{% comment %}
{% 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.sifrovacka_id %}>{{ sifrovacka }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>Zadne sifrovacky nemate aktivní.</p>
{% endif %}
{% endblock %}
{{% endif %}
{% comment %}
{% block content %}
{% if active_sifrovacky_list %}
<ul>
<p> <b>Aktivni sifrovacky: </b> </p>
{% for sifrovacka in active_sifrovacky_list %}
<li><a href={% url 'detail' sifrovacka.id %}>{{ sifrovacka.sifrovacka_name }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>Žádné šifrovačky nejsou aktivní.</p>
{% endif %}
{% endblock %}
{% endcomment %}
{% extends "base.html" %}
{% block content %}
{% if sifrovacky_list %}
{% 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 %}
{% extends "base.html" %}
{% comment %}
{% extends "django_registration/registration_base.html" %}
{% endcomment %}
{% load i18n %}
{% block title %}{% trans "Log in" %}{% endblock %}
{% block content %}
<form method="post" action="">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="{% trans 'Log in' %}" />
<input type="hidden" name="next" value="{{ next }}" />
</form>
{% comment %}
<p>{% trans "Forgot your password?" %} <a href="{% url 'auth_password_reset' %}">{% trans "Reset it" %}</a>.</p>
<p>{% trans "Nemáte účet?" %} <a href="{% url 'django_registration_register' %}">{% trans "Register" %}</a>.</p>
{% endcomment %}
{% endblock %}
{% comment %}
**registration/login.html**
It's your responsibility to provide the login form in a template called
registration/login.html by default. This template gets passed four
template context variables:
``form``
A Form object representing the login form. See the forms
documentation for more on Form objects.
``next``
The URL to redirect to after successful login. This may contain a
query string, too.
``site``
The current Site, according to the SITE_ID setting. If you don't
have the site framework installed, this will be set to an instance
of RequestSite, which derives the site name and domain from the
current HttpRequest.
``site_name``
An alias for site.name. If you don't have the site framework
installed, this will be set to the value of
request.META['SERVER_NAME']. For more on sites, see The
"sites" framework.
{% endcomment %}
{% extends "django_registration/registration_base.html" %}
{% load i18n %}
{% block title %}{% trans "Logged out" %}{% endblock %}
{% block content %}
<p>{% trans "Successfully logged out" %}.</p>
{% endblock %}
{% extends "base.html" %}
{% comment %}
{% extends "django_registration/registration_base.html" %}
{% endcomment %}
{% load i18n %}
{% block title %}{% trans "Profile" %}{% endblock %}
{% block content %}
<form method="post" action="">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="{% trans 'Log in' %}" />
<input type="hidden" name="next" value="{{ next }}" />
</form>
{% comment %}
<p>{% trans "Forgot your password?" %} <a href="{% url 'auth_password_reset' %}">{% trans "Reset it" %}</a>.</p>
<p>{% trans "Not a member?" %} <a href="{% url 'registration_register' %}">{% trans "Register" %}</a>.</p>
{% endcomment %}
{% endblock %}
{% comment %}
**registration/login.html**
It's your responsibility to provide the login form in a template called
registration/login.html by default. This template gets passed four
template context variables:
``form``
A Form object representing the login form. See the forms
documentation for more on Form objects.
``next``
The URL to redirect to after successful login. This may contain a
query string, too.
``site``
The current Site, according to the SITE_ID setting. If you don't
have the site framework installed, this will be set to an instance
of RequestSite, which derives the site name and domain from the
current HttpRequest.
``site_name``
An alias for site.name. If you don't have the site framework
installed, this will be set to the value of
request.META['SERVER_NAME']. For more on sites, see The
"sites" framework.
{% endcomment %}
{% extends "base.html" %}
{% block content %}
<p> Toto je detail sifrovacky se jmenem: <b>{{sifrovacka_detail}} </b> a id: {{sifrovacka_id}}. </p>
</br>
<p> Pocet ukolu: <b> {{ sifrovacka_stage_count }} </b> </br>
Obtiznost: NONE</br>
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>
Debug:
<div>
{% for stage in sifrovacka_stages %}
{{ stage }}</br>
{% endfor %}
</div>
{% endblock %}
from django.test import TestCase
# Create your tests here.
from django.urls import include,path
from . import views
urlpatterns = [
# accounts uls
path('accounts/', include('django_registration.backends.one_step.urls')),
path('accounts/', include('django.contrib.auth.urls')),
# the 'name' value as called by the {% url %} template tag
path('<int:sifrovacka_id>/', views.detail, name='detail'),
# home page
path('home/', views.home, name='home'),
# /
path('', views.index, name='index'),
]
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
from .models import Sifrovacka, Stages, Participants
def detail(request, sifrovacka_id):
sifrovacka_detail = Sifrovacka.objects.get(id = sifrovacka_id)
sifrovacka_stages = Stages.objects.filter(sifrovacka__sifrovacka_name = sifrovacka_detail)
sifrovacka_stage_count = sifrovacka_stages.count()
context = {"sifrovacka_id": sifrovacka_id,
"sifrovacka_detail": sifrovacka_detail,
"sifrovacka_stages": sifrovacka_stages,
"sifrovacka_stage_count": sifrovacka_stage_count}
return render(request, 'sifrovacka.html', context)
def home(request):
all_sifrovacky_list = Sifrovacka.objects.order_by('id')
# only for auth users
if request.user.is_authenticated:
participation_sifrovacky_list = Participants.objects.filter(user =
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):
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment