Add migration and books

This commit is contained in:
gabatxo1312
2026-01-28 00:38:24 +01:00
parent 30be91390b
commit 4cd32831c1
19 changed files with 805 additions and 231 deletions
+68 -38
View File
@@ -1,49 +1,79 @@
{% extends "base.html" %}
{% import "components/typography.html" as typography %}
{% import "components/cards.html" as cards %}
{% block main %}
{{ typography::heading("Editer La petite derniere") }}
{{ typography::heading("Editer") }}
<form>
<div class="mb-3">
<label class="form-label">Name</label>
<input type="text" class="form-control" value="La petite derniere">
</div>
{% call cards::card() %}
<form method="post" action="/books/{{ book.id }}">
<div class="mb-3">
<label class="form-label" for="title">Name</label>
<input type="text" name="title" class="form-control" value="{{ book.title }}" required>
</div>
<div class="mb-3">
<label class="form-label">Author(s)</label>
<input type="text" class="form-control" value="Fatima Daas">
</div>
<div class="mb-3">
<label for="authors" class="form-label">Author(s)</label>
<input type="text" name="authors" class="form-control" value="{{ book.authors }}" required>
</div>
<div class="mb-3">
<label class="form-label">Owner</label>
<select class="form-control">
<option selected>Jean</option>
<option>Simon</option>
</select>
</div>
<div class="mb-3">
<label for="owner_id" class="form-label">Owner</label>
<select name="owner_id" class="form-control" required>
{% for user in users %}
{% if book.owner_id == user.id %}
<option value="{{ user.id }}" selected>{{ user.name }}</option>
{% else %}
<option value="{{ user.id }}">{{ user.name }}</option>
{% endif %}
{% endfor %}
</select>
</div>
<div class="mb-3">
<label class="form-label">Current Holder</label>
<select class="form-control">
<option></option>
<option>Jean</option>
<option selected>Simon</option>
</select>
</div>
<div class="mb-3">
<label for="current_holder_id" class="form-label">Current Holder</label>
<select class="form-control" name="current_holder_id">
<option></option>
{% match book.current_holder_id %}
{% when Some with (current_holder_id) %}
{% for user in users %}
{% if *current_holder_id == user.id %}
<option value="{{ user.id }}" selected>{{ user.name }}</option>
{% else %}
<option value="{{ user.id }}">{{ user.name }}</option>
{% endif %}
{% endfor %}
{% when None %}
{% for user in users %}
<option value="{{ user.id }}">{{ user.name }}</option>
{% endfor %}
{% endmatch %}
</select>
</div>
<div class="mb-3">
<label class="form-label">Description</label>
<textarea class="form-control">dsjfskdljf</textarea>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
{% match book.description %}
{% when Some with (description) %}
<textarea name="description" class="form-control">{{ description }}</textarea>
{% when None %}
<textarea name="description" class="form-control"></textarea>
{% endmatch %}
</div>
<div class="mb-3">
<label class="form-label">Comment</label>
<textarea class="form-control">sdsfjsdkfjsdklfj</textarea>
</div>
<div class="mb-3">
<label class="form-label" for="comment">Comment</label>
{% match book.comment %}
{% when Some with (comment) %}
<textarea name="comment" class="form-control">{{ comment }}</textarea>
{% when None %}
<textarea name="comment" class="form-control"></textarea>
{% endmatch %}
</div>
<div class="mt-4 text-center">
<input type="submit" value="Create book" class="btn btn-success">
</div>
</form>
{% endblock %}
<div class="mt-4 text-center">
<input type="submit" value="Edit book" class="btn btn-success">
</div>
</form>
{% endcall %}
{% endblock %}
+43 -38
View File
@@ -1,49 +1,54 @@
{% extends "base.html" %}
{% import "components/typography.html" as typography %}
{% import "components/cards.html" as cards %}
{% block main %}
{{ typography::heading("New book") }}
{{ typography::heading("New book") }}
<form>
<div class="mb-3">
<label class="form-label">Name</label>
<input type="text" class="form-control">
</div>
{% call cards::card() %}
<form method="post" action="/books">
<div class="mb-3">
<label for="title" class="form-label">Name</label>
<input type="text" name="title" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label">Author(s)</label>
<input type="text" class="form-control">
</div>
<div class="mb-3">
<label for="authors" class="form-label">Author(s)</label>
<input type="text" name="authors" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label">Owner</label>
<select class="form-control">
<option>Jean</option>
<option>Simon</option>
</select>
</div>
<div class="mb-3">
<label for="owner_id" class="form-label">Owner</label>
<select name="owner_id" class="form-control" required>
{% for user in users %}
<option value="{{ user.id }}">{{ user.name }}</option>
{% endfor %}
</select>
</div>
<div class="mb-3">
<label class="form-label">Current Holder</label>
<select class="form-control">
<option></option>
<option>Jean</option>
<option>Simon</option>
</select>
</div>
<div class="mb-3">
<label for="current_holder_id" class="form-label">Current Holder</label>
<select name="current_holder_id" class="form-control">
<option></option>
{% for user in users %}
<option value="{{ user.id }}">{{ user.name }}</option>
{% endfor %}
</select>
</div>
<div class="mb-3">
<label class="form-label">Description</label>
<textarea class="form-control"></textarea>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea name="description" class="form-control"></textarea>
</div>
<div class="mb-3">
<label class="form-label">Comment</label>
<textarea class="form-control"></textarea>
</div>
<div class="mb-3">
<label for="comment" class="form-label">Comment</label>
<textarea name="comment" class="form-control"></textarea>
</div>
<div class="mt-4 text-center">
<input type="submit" value="Create book" class="btn btn-success">
</div>
</form>
{% endblock %}
<div class="mt-4 text-center">
<input type="submit" value="Create book" class="btn btn-success">
</div>
</form>
{% endcall %}
{% endblock %}
+34 -22
View File
@@ -2,30 +2,42 @@
{% import "components/typography.html" as typography %}
{% import "components/dropdown.html" as dropdown %}
{% import "components/fields.html" as fields %}
{% import "components/cards.html" as cards %}
{% block main %}
{% call typography::heading("La petite derniere") %}
{{ dropdown::dropdown_button("Actions", [("Edit", "/books/1/edit"), ("Delete", "/books/1")]) }}
{% endcall %}
{{ typography::book_heading(book.title, book, show = false) }}
<div class="mt-4">
<h5 class="mt-4 fw-bold">Book details</h5>
{{ fields::field("Name", "La petite derniere") }}
{{ fields::field("Authors", "Fatima Daas") }}
{{ fields::field("Authors", "Je mappelle Fatima Daas. Je suis la mazoziya, la petite dernière. Celle à laquelle on ne
sest pas préparé. Française dorigine algérienne. Musulmane pratiquante. Clichoise qui passe plus de trois heures par
jour dans les transports. Une touriste. Une banlieusarde qui observe les comportements parisiens. Je suis une
menteuse, une pécheresse. Adolescente, je suis une élève instable. Adulte, je suis hyper-inadaptée. J’écris des
histoires pour éviter de vivre la mienne. Jai fait quatre ans de thérapie. Cest ma plus longue relation. Lamour,
c’était tabou à la maison, les marques de tendresse, la sexualité aussi. Je me croyais polyamoureuse. Lorsque Nina a
débarqué dans ma vie, je ne savais plus du tout ce dont javais besoin et ce quil me manquait. Je mappelle Fatima
Daas. Je ne sais pas si je porte bien mon prénom.") }}
{% call cards::card() %}
<div class="mt-4">
<h5 class="mt-4 fw-bold">Book details</h5>
{{ fields::field("Name", book.title) }}
{{ fields::field("Authors", book.authors) }}
<h5 class="mt-50px fw-bold">User Details</h5>
{{ fields::field("Owner", "Jean") }}
{{ fields::field("Current Holder", "Pierre") }}
{% match book.description %}
{% when Some with (description) %}
{{ fields::field("Description", description) }}
{% when None %}
{{ fields::field("Description", "-") }}
{% endmatch %}
<h5 class="mt-50px fw-bold">More Informations</h5>
{{ fields::field("Comment", "J'adore ce livre ca parle de plein de choses !") }}
</div>
{% endblock %}
<h5 class="mt-50px fw-bold">User Details</h5>
{{ fields::field("Owner", owner.name) }}
{% match current_holder %}
{% when Some with (current_holder) %}
{{ fields::field("Current Holder", current_holder.name) }}
{% when None %}
{{ fields::field("Current Holder", "-") }}
{% endmatch %}
<h5 class="mt-50px fw-bold">More Informations</h5>
{% match book.comment %}
{% when Some with (comment) %}
{{ fields::field("Comment", comment) }}
{% when None %}
{{ fields::field("Comment", "-") }}
{% endmatch %}
</div>
{% endcall %}
{% endblock %}
+7
View File
@@ -0,0 +1,7 @@
{% macro card() %}
<div class="card my-3">
<div class="card-body">
{{ caller() }}
</div>
</div>
{% endmacro %}
+21 -2
View File
@@ -5,8 +5,27 @@
</button>
<ul class="dropdown-menu">
{% for item in items %}
<li><a class="dropdown-item" href="{{ item.1 }}">{{ item.0 }}</a></li>
<li><a class="dropdown-item" href="{{ item.1 }}">{{ item.0 }}</a></li>
{% endfor %}
</ul>
</div>
{% endmacro %}
{% endmacro %}
{% macro book_dropdown_button(book, show = true) %}
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Actions
</button>
<ul class="dropdown-menu">
{% if show %}
<li><a class="dropdown-item" href="/books/{{ book.id }}">Voir</a></li>
{% endif %}
<li><a class="dropdown-item" href="/books/{{ book.id }}/edit">Edit</a></li>
<li>
<form method="post" action="/books/{{ book.id }}/delete">
<input class="dropdown-item" type="submit" value="Delete">
</form>
</li>
</ul>
</div>
{% endmacro %}
+12 -12
View File
@@ -1,14 +1,14 @@
{% macro field(name, value) %}
<div class="row mt-4">
<div class="col-md-3">
<p class="mb-0 fw-regular">
{{ name }}:
</p>
<div class="row mt-4">
<div class="col-md-3">
<p class="mb-0 fw-regular">
{{ name }}:
</p>
</div>
<div class="col-md-9">
<p class="mb-0">
{{ value }}
</p>
</div>
</div>
<div class="col-md-9">
<p class="mb-0">
{{ value }}
</p>
</div>
</div>
{% endmacro %}
{% endmacro %}
+25 -11
View File
@@ -1,13 +1,27 @@
{% macro heading(title) %}
<div class="d-flex justify-content-between align-items-center">
<h1 class="mb-4">
{{ title }}
</h1>
{% import "components/dropdown.html" as dropdown %}
{% if caller is defined %}
<div>
{{ caller() }}
{% macro heading(title) %}
<div class="d-flex justify-content-between align-items-center">
<h1 class="mb-4">
{{ title }}
</h1>
{% if caller is defined %}
<div>
{{ caller() }}
</div>
{% endif %}
</div>
{% endif %}
</div>
{% endmacro %}
{% endmacro %}
{% macro book_heading(title, book, show = false) %}
<div class="d-flex justify-content-between align-items-center">
<h1 class="mb-4">
{{ title }}
</h1>
<div>
{{ dropdown::book_dropdown_button(book, show) }}
</div>
</div>
{% endmacro %}
+37 -34
View File
@@ -1,41 +1,44 @@
{% extends "base.html" %}
{% import "components/typography.html" as typography %}
{% import "components/dropdown.html" as dropdown %}
{% import "components/cards.html" as cards %}
{% block main %}
{{ typography::heading("All books") }}
{{ typography::heading("All books") }}
<table class="table table-hover">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Author(s)</th>
<th scope="col">Owner</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>La petite derniere</td>
<td>Fatima Daas</td>
<td>Jean</td>
<td>
{{ dropdown::dropdown_button("Actions", [("Voir", "/books/1"), ("Edit", "/books/1/edit"), ("Delete",
"/books/1")]) }}
</td>
</tr>
<tr>
<th scope="row">2</th>
<td>La petite derniere</td>
<td>Fatima Daas</td>
<td>Jean</td>
<td>
{{ dropdown::dropdown_button("Actions", [("Voir", "/books/1"), ("Edit", "/books/1/edit"), ("Delete",
"/books/1")]) }}
</td>
</tr>
</tbody>
</table>
{% call cards::card() %}
<table class="table table-hover">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Author(s)</th>
<th scope="col">Owner</th>
<th scope="col">Current Holder</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
{% for book_with_user in books_with_user %}
<tr>
<th scope="row">{{ book_with_user.book.id }}</th>
<td>{{ book_with_user.book.title }}</td>
<td>{{ book_with_user.book.authors }}</td>
<td>{{ book_with_user.owner.name }}</td>
<td>
{% match book_with_user.current_holder %}
{% when Some with (current_holder) %}
{{ current_holder.name }}
{% when None %}
-
{% endmatch %}
</td>
<td>
{{ dropdown::book_dropdown_button(book_with_user.book) }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endcall %}
{% endblock %}
+38 -31
View File
@@ -1,39 +1,46 @@
{% extends "base.html" %}
{% import "components/typography.html" as typography %}
{% import "components/cards.html" as cards %}
{% block main %}
{{ typography::heading("All users") }}
{{ typography::heading("All users") }}
<table class="table table-hover">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Nombre de livres</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
{% for user in users %}
<tr>
<th scope="row">{{ user.id }}</th>
<td>{{ user.name }}</td>
<td>10</td>
<td>
<form method="post" action="/users/{{ user.id }}">
<input value="Delete" type="submit" class="btn btn-danger btn-sm">
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% call cards::card() %}
<table class="table table-hover">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Owner book</th>
<th scope="col">Borrowed book</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
{% for (user, book_size, borrowed_book) in user_with_books_number %}
<tr>
<th scope="row">{{ user.id }}</th>
<td>{{ user.name }}</td>
<td>{{ book_size }}</td>
<td>{{ borrowed_book }}</td>
<td>
<form method="post" action="/users/{{ user.id }}">
<input value="Delete" type="submit" class="btn btn-danger btn-sm">
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endcall %}
<form action="/users" method="post">
<label class="form-label">Name</label>
<input type="text" name="name" class="form-control">
{% call cards::card() %}
<form action="/users" method="post">
<label class="form-label">Name</label>
<input type="text" name="name" class="form-control">
<input type="submit" value="Create user" class="btn btn-success mt-3">
</form>
<input type="submit" value="Create user" class="btn btn-success mt-3">
</form>
{% endcall %}
{% endblock %}
{% endblock %}