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:
|
||||
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,9 +1,9 @@
|
|||
<!-- 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");
|
||||
|
@ -82,12 +82,15 @@
|
|||
.small-col {
|
||||
width: 5%;
|
||||
}
|
||||
|
||||
.medium-col {
|
||||
width: 15%;
|
||||
}
|
||||
|
||||
.big-col {
|
||||
width: 25%;
|
||||
}
|
||||
|
||||
.right-align {
|
||||
text-align: right;
|
||||
}
|
||||
|
@ -116,13 +119,13 @@
|
|||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Faktura <span class="invoice-id">2023-0001</span></h1>
|
||||
</header>
|
||||
</header>
|
||||
|
||||
<section class="parties-section">
|
||||
<section class="parties-section">
|
||||
<div class="parties">
|
||||
<h2>Dodavatel</h2>
|
||||
<ul>
|
||||
|
@ -151,9 +154,9 @@
|
|||
<li><strong>Datum splatnosti:</strong> 16. prosince 2023</li>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<section>
|
||||
<h2>Detaily faktury</h2>
|
||||
<table id="invoice">
|
||||
<thead>
|
||||
|
@ -179,11 +182,11 @@
|
|||
<div class="invoice-total">
|
||||
<p><strong>Celkem: 100,00 Kč</strong></p>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<footer>
|
||||
<footer>
|
||||
<p>Fyzická osoba zapsaná v živnostenském rejstříku.</p>
|
||||
<p>Fakturu vygenerovala aplikace Facturio</p>
|
||||
</footer>
|
||||
</body>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Reference in a new issue