Trying to add the django fucking forms
This commit is contained in:
parent
4f22f97952
commit
fe0ae92c6e
7 changed files with 327 additions and 167 deletions
|
@ -3,6 +3,4 @@ from django.contrib.auth.admin import UserAdmin
|
|||
|
||||
from .models import User
|
||||
|
||||
# Register your models here.
|
||||
|
||||
admin.site.register(User, UserAdmin)
|
||||
|
|
13
account/forms.py
Normal file
13
account/forms.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
from django.contrib.auth.forms import AuthenticationForm, UserCreationForm
|
||||
|
||||
# from .models import User
|
||||
|
||||
|
||||
class LoginForm(AuthenticationForm):
|
||||
pass
|
||||
|
||||
#
|
||||
# class RegisterForm(UserCreationForm):
|
||||
# class Meta(UserCreationForm.Meta):
|
||||
# model = User
|
||||
# fields = UserCreationForm.Meta.fields
|
131
account/migrations/0001_initial.py
Normal file
131
account/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,131 @@
|
|||
# Generated by Django 5.0 on 2023-12-18 21:42
|
||||
|
||||
import django.contrib.auth.models
|
||||
import django.contrib.auth.validators
|
||||
import django.utils.timezone
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
("auth", "0012_alter_user_first_name_max_length"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="User",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("password", models.CharField(max_length=128, verbose_name="password")),
|
||||
(
|
||||
"last_login",
|
||||
models.DateTimeField(
|
||||
blank=True, null=True, verbose_name="last login"
|
||||
),
|
||||
),
|
||||
(
|
||||
"is_superuser",
|
||||
models.BooleanField(
|
||||
default=False,
|
||||
help_text="Designates that this user has all permissions without explicitly assigning them.",
|
||||
verbose_name="superuser status",
|
||||
),
|
||||
),
|
||||
(
|
||||
"username",
|
||||
models.CharField(
|
||||
error_messages={
|
||||
"unique": "A user with that username already exists."
|
||||
},
|
||||
help_text="Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.",
|
||||
max_length=150,
|
||||
unique=True,
|
||||
validators=[
|
||||
django.contrib.auth.validators.UnicodeUsernameValidator()
|
||||
],
|
||||
verbose_name="username",
|
||||
),
|
||||
),
|
||||
(
|
||||
"first_name",
|
||||
models.CharField(
|
||||
blank=True, max_length=150, verbose_name="first name"
|
||||
),
|
||||
),
|
||||
(
|
||||
"last_name",
|
||||
models.CharField(
|
||||
blank=True, max_length=150, verbose_name="last name"
|
||||
),
|
||||
),
|
||||
(
|
||||
"email",
|
||||
models.EmailField(
|
||||
blank=True, max_length=254, verbose_name="email address"
|
||||
),
|
||||
),
|
||||
(
|
||||
"is_staff",
|
||||
models.BooleanField(
|
||||
default=False,
|
||||
help_text="Designates whether the user can log into this admin site.",
|
||||
verbose_name="staff status",
|
||||
),
|
||||
),
|
||||
(
|
||||
"is_active",
|
||||
models.BooleanField(
|
||||
default=True,
|
||||
help_text="Designates whether this user should be treated as active. Unselect this instead of deleting accounts.",
|
||||
verbose_name="active",
|
||||
),
|
||||
),
|
||||
(
|
||||
"date_joined",
|
||||
models.DateTimeField(
|
||||
default=django.utils.timezone.now, verbose_name="date joined"
|
||||
),
|
||||
),
|
||||
(
|
||||
"groups",
|
||||
models.ManyToManyField(
|
||||
blank=True,
|
||||
help_text="The groups this user belongs to. A user will get all permissions granted to each of their groups.",
|
||||
related_name="user_set",
|
||||
related_query_name="user",
|
||||
to="auth.group",
|
||||
verbose_name="groups",
|
||||
),
|
||||
),
|
||||
(
|
||||
"user_permissions",
|
||||
models.ManyToManyField(
|
||||
blank=True,
|
||||
help_text="Specific permissions for this user.",
|
||||
related_name="user_set",
|
||||
related_query_name="user",
|
||||
to="auth.permission",
|
||||
verbose_name="user permissions",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"verbose_name": "user",
|
||||
"verbose_name_plural": "users",
|
||||
"abstract": False,
|
||||
},
|
||||
managers=[
|
||||
("objects", django.contrib.auth.models.UserManager()),
|
||||
],
|
||||
),
|
||||
]
|
0
account/migrations/__init__.py
Normal file
0
account/migrations/__init__.py
Normal file
|
@ -16,5 +16,17 @@
|
|||
</div>
|
||||
<button type="submit" class="btn btn-primary">Login</button>
|
||||
</form>
|
||||
{# <form class="col-md-6 offset-md-3" action="{% url 'login' %}" method="post">#}
|
||||
{# {% csrf_token %}#}
|
||||
{# <div class="mb-3">#}
|
||||
{# <label for="username" class="form-label">Username</label>#}
|
||||
{# <input type="text" class="form-control" name="username" id="username" required>#}
|
||||
{# </div>#}
|
||||
{# <div class="mb-3">#}
|
||||
{# <label for="password" class="form-label">Password</label>#}
|
||||
{# <input type="password" class="form-control" name="password" id="password" required>#}
|
||||
{# </div>#}
|
||||
{# <button type="submit" class="btn btn-primary">Login</button>#}
|
||||
{# </form>#}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,28 +1,30 @@
|
|||
from django.conf import settings
|
||||
from django.contrib.auth import authenticate, login, logout
|
||||
from django.contrib.auth import login, logout
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.http import HttpRequest, HttpResponse, JsonResponse
|
||||
from django.shortcuts import redirect, render
|
||||
|
||||
from . import forms
|
||||
|
||||
|
||||
def auth_login(req: HttpRequest) -> HttpResponse:
|
||||
if req.method == "POST":
|
||||
username = req.POST["username"]
|
||||
password = req.POST["password"]
|
||||
user = authenticate(req, username=username, password=password)
|
||||
if not user:
|
||||
return JsonResponse(
|
||||
{
|
||||
"message": "Invalid cretendials"
|
||||
},
|
||||
status=401
|
||||
)
|
||||
else:
|
||||
login(req, user)
|
||||
redirect_url = getattr(req.GET, "next", settings.LOGIN_REDIRECT_URL)
|
||||
return redirect(redirect_url)
|
||||
form = forms.LoginForm(req, req.POST)
|
||||
|
||||
if not form.is_valid():
|
||||
return render(req, "account/login.html", dict(form=form))
|
||||
|
||||
user = form.get_user()
|
||||
login(req, user)
|
||||
|
||||
redirect_url = getattr(req.GET, "next", settings.LOGIN_REDIRECT_URL)
|
||||
return redirect(redirect_url)
|
||||
|
||||
elif req.method == "GET":
|
||||
return render(req, "account/login.html")
|
||||
|
||||
form = forms.LoginForm(req)
|
||||
return render(req, "account/login.html", dict(form=form))
|
||||
|
||||
return HttpResponse(status=405)
|
||||
|
||||
|
||||
|
@ -35,6 +37,7 @@ def auth_logout(req: HttpRequest) -> HttpResponse:
|
|||
def auth_register(req: HttpRequest) -> HttpResponse:
|
||||
return render(req, "account/register.html")
|
||||
|
||||
|
||||
@login_required
|
||||
def me(req: HttpRequest) -> HttpResponse:
|
||||
return render(req, "account/me.html")
|
||||
|
|
|
@ -1,189 +1,192 @@
|
|||
<!-- Vaše faktura s aktualizacemi -->
|
||||
<!DOCTYPE html>
|
||||
<html lang="cs">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<title>Faktura</title>
|
||||
<style>
|
||||
@import url("https://fonts.googleapis.com/css2?family=Ubuntu&display=swap");
|
||||
|
||||
:root {
|
||||
--font-family: "Ubuntu", sans-serif;
|
||||
--main-color: #333;
|
||||
--secondary-color: #888;
|
||||
--border-color: #ddd;
|
||||
--background-color: #fff;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: var(--font-family);
|
||||
margin: 20px;
|
||||
color: var(--main-color);
|
||||
background-color: var(--background-color);
|
||||
}
|
||||
|
||||
header {
|
||||
text-align: left;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.parties ul {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.parties li {
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.parties h2 {
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
padding-bottom: 8px;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
.invoice-id {
|
||||
color: var(--secondary-color);
|
||||
}
|
||||
|
||||
#invoice {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#invoice th,
|
||||
#invoice td {
|
||||
padding: 12px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.invoice-total {
|
||||
margin-top: 20px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.parties-section {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.parties {
|
||||
width: 48%;
|
||||
}
|
||||
|
||||
#invoice tbody tr {
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.small-col {
|
||||
width: 5%;
|
||||
}
|
||||
.medium-col {
|
||||
width: 15%;
|
||||
}
|
||||
.big-col {
|
||||
width: 25%;
|
||||
}
|
||||
.right-align {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
footer {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
left: 0;
|
||||
right: 0;
|
||||
padding: 0;
|
||||
margin-top: 20px;
|
||||
color: var(--main-color);
|
||||
background-color: var(--background-color);
|
||||
}
|
||||
|
||||
@media print {
|
||||
@page {
|
||||
size: auto;
|
||||
margin: 0;
|
||||
--font-family: "Ubuntu", sans-serif;
|
||||
--main-color: #333;
|
||||
--secondary-color: #888;
|
||||
--border-color: #ddd;
|
||||
--background-color: #fff;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 10mm 10mm;
|
||||
font-family: var(--font-family);
|
||||
margin: 20px;
|
||||
color: var(--main-color);
|
||||
background-color: var(--background-color);
|
||||
}
|
||||
|
||||
header {
|
||||
text-align: left;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.parties ul {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.parties li {
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.parties h2 {
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
padding-bottom: 8px;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
.invoice-id {
|
||||
color: var(--secondary-color);
|
||||
}
|
||||
|
||||
#invoice {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#invoice th,
|
||||
#invoice td {
|
||||
padding: 12px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.invoice-total {
|
||||
margin-top: 20px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.parties-section {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.parties {
|
||||
width: 48%;
|
||||
}
|
||||
|
||||
#invoice tbody tr {
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.small-col {
|
||||
width: 5%;
|
||||
}
|
||||
|
||||
.medium-col {
|
||||
width: 15%;
|
||||
}
|
||||
|
||||
.big-col {
|
||||
width: 25%;
|
||||
}
|
||||
|
||||
.right-align {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
footer {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
left: 0;
|
||||
right: 0;
|
||||
padding: 0;
|
||||
margin-top: 20px;
|
||||
color: var(--main-color);
|
||||
background-color: var(--background-color);
|
||||
}
|
||||
|
||||
@media print {
|
||||
@page {
|
||||
size: auto;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 10mm 10mm;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Faktura <span class="invoice-id">2023-0001</span></h1>
|
||||
</header>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Faktura <span class="invoice-id">2023-0001</span></h1>
|
||||
</header>
|
||||
|
||||
<section class="parties-section">
|
||||
<div class="parties">
|
||||
<section class="parties-section">
|
||||
<div class="parties">
|
||||
<h2>Dodavatel</h2>
|
||||
<ul>
|
||||
<li>Název Vaší společnosti nebo jméno</li>
|
||||
<li>Vaše adresa</li>
|
||||
<li>Vaše město, PSČ</li>
|
||||
<p></p>
|
||||
<li>IČO: 123456789</li>
|
||||
<li>DIČ: CZ123456789 jestli jste plátce DPH</li>
|
||||
<p></p>
|
||||
<li>Bankovní účet: 123-456789</li>
|
||||
<li>Název Vaší společnosti nebo jméno</li>
|
||||
<li>Vaše adresa</li>
|
||||
<li>Vaše město, PSČ</li>
|
||||
<p></p>
|
||||
<li>IČO: 123456789</li>
|
||||
<li>DIČ: CZ123456789 jestli jste plátce DPH</li>
|
||||
<p></p>
|
||||
<li>Bankovní účet: 123-456789</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="parties">
|
||||
<div class="parties">
|
||||
<h2>Odběratel</h2>
|
||||
<ul>
|
||||
<li>Název společnosti nebo jméno zákazníka</li>
|
||||
<li>Adresa zákazníka</li>
|
||||
<li>Město zákazníka, PSČ</li>
|
||||
<p></p>
|
||||
<li>IČO zákazníka: 987654321</li>
|
||||
<li>DIČ zákazníka: CZ987654321 jestli je plátce DPH</li>
|
||||
<p></p>
|
||||
<li><strong>Datum vystavení:</strong> 16. prosince 2023</li>
|
||||
<li><strong>Datum splatnosti:</strong> 16. prosince 2023</li>
|
||||
<li>Název společnosti nebo jméno zákazníka</li>
|
||||
<li>Adresa zákazníka</li>
|
||||
<li>Město zákazníka, PSČ</li>
|
||||
<p></p>
|
||||
<li>IČO zákazníka: 987654321</li>
|
||||
<li>DIČ zákazníka: CZ987654321 jestli je plátce DPH</li>
|
||||
<p></p>
|
||||
<li><strong>Datum vystavení:</strong> 16. prosince 2023</li>
|
||||
<li><strong>Datum splatnosti:</strong> 16. prosince 2023</li>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>Detaily faktury</h2>
|
||||
<table id="invoice">
|
||||
<section>
|
||||
<h2>Detaily faktury</h2>
|
||||
<table id="invoice">
|
||||
<thead>
|
||||
<tr>
|
||||
<tr>
|
||||
<th class="small-col">#</th>
|
||||
<th class="small-col">Jednotka</th>
|
||||
<th class="big-col">Popis položky</th>
|
||||
<th class="medium-col right-align">Cena za MJ</th>
|
||||
<th class="medium-col right-align">Celkem</th>
|
||||
</tr>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<tr>
|
||||
<td>1</td>
|
||||
<td>ks</td>
|
||||
<td>Položka 1</td>
|
||||
<td class="right-align">50,00 Kč</td>
|
||||
<td class="right-align">50,00 Kč</td>
|
||||
</tr>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</table>
|
||||
|
||||
<div class="invoice-total">
|
||||
<div class="invoice-total">
|
||||
<p><strong>Celkem: 100,00 Kč</strong></p>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<footer>
|
||||
<p>Fyzická osoba zapsaná v živnostenském rejstříku.</p>
|
||||
<p>Fakturu vygenerovala aplikace Facturio</p>
|
||||
</footer>
|
||||
</body>
|
||||
<footer>
|
||||
<p>Fyzická osoba zapsaná v živnostenském rejstříku.</p>
|
||||
<p>Fakturu vygenerovala aplikace Facturio</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Reference in a new issue