step 2 with basic crud implemented

This commit is contained in:
2026-04-19 12:36:55 +02:00
parent dae7a60eab
commit 57800f2123
16 changed files with 1113 additions and 110 deletions
+5 -3
View File
@@ -1,15 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ page_title or "Moving Helper" }}</title>
<title>{{ page_title or "搬家助手" }}</title>
<link rel="stylesheet" href="{{ url_for('static', path='/style.css') }}">
</head>
<body>
<main class="container">
<nav class="top-nav">
<a href="/boxes">箱子</a>
</nav>
{% block content %}{% endblock %}
</main>
</body>
</html>
-7
View File
@@ -1,7 +0,0 @@
{% extends "base.html" %}
{% block content %}
<h1>Boxes page</h1>
<p>This is the minimal starter page for the boxes module.</p>
{% endblock %}
+28
View File
@@ -0,0 +1,28 @@
{% extends "base.html" %}
{% block content %}
<div class="page-header">
<h1>{{ page_title }}</h1>
<a href="/boxes">返回箱子列表</a>
</div>
<form method="post" action="{{ form_action }}" class="stack">
<label>
名称
<input type="text" name="name" value="{{ box.name if box else '' }}" required>
</label>
<label>
房间
<input type="text" name="room" value="{{ box.room if box and box.room else '' }}">
</label>
<label>
状态
<input type="text" name="status" value="{{ box.status if box and box.status else '' }}">
</label>
<label>
备注
<textarea name="note" rows="4">{{ box.note if box and box.note else '' }}</textarea>
</label>
<button type="submit">{{ submit_label }}</button>
</form>
{% endblock %}
+34
View File
@@ -0,0 +1,34 @@
{% extends "base.html" %}
{% block content %}
<div class="page-header">
<div>
<h1>箱子</h1>
<p class="muted">这里管理顶层搬家容器,例如纸箱、行李箱或大收纳箱。</p>
</div>
<a class="button" href="/boxes/new">新建箱子</a>
</div>
{% if boxes %}
<div class="stack">
{% for box in boxes %}
<section class="card">
<h2><a href="/boxes/{{ box.id }}">{{ box.name }}</a></h2>
<p class="meta">物品数:{{ box.items|length }}</p>
{% if box.room %}<p>房间:{{ box.room }}</p>{% endif %}
{% if box.status %}<p>状态:{{ box.status }}</p>{% endif %}
{% if box.note %}<p>{{ box.note }}</p>{% endif %}
<div class="actions">
<a href="/boxes/{{ box.id }}">查看详情</a>
<a href="/boxes/{{ box.id }}/edit">编辑</a>
</div>
</section>
{% endfor %}
</div>
{% else %}
<section class="card">
<p>还没有箱子。</p>
<a href="/boxes/new">创建第一个箱子</a>
</section>
{% endif %}
{% endblock %}
+54
View File
@@ -0,0 +1,54 @@
{% extends "base.html" %}
{% block content %}
<div class="page-header">
<div>
<h1>{{ box.name }}</h1>
<p class="muted">查看这个箱子的基本信息,以及它下面的直接物品。</p>
</div>
<div class="actions">
<a href="/boxes">返回箱子列表</a>
<a class="button" href="/boxes/{{ box.id }}/items/new">添加物品</a>
</div>
</div>
<section class="card">
<p><strong>房间:</strong> {{ box.room or '-' }}</p>
<p><strong>状态:</strong> {{ box.status or '-' }}</p>
<p><strong>备注:</strong> {{ box.note or '-' }}</p>
<div class="actions">
<a href="/boxes/{{ box.id }}/edit">编辑箱子</a>
<form method="post" action="/boxes/{{ box.id }}/delete">
<button type="submit" class="link-button">删除箱子</button>
</form>
</div>
</section>
<section class="stack">
<h2>物品</h2>
{% if box.items %}
{% for item in box.items %}
<article class="card">
<h3><a href="/items/{{ item.id }}">{{ item.name }}</a></h3>
<p><strong>是否容器:</strong> {{ "是" if item.is_container else "否" }}</p>
{% if item.quantity is not none %}<p><strong>数量:</strong> {{ item.quantity }}</p>{% endif %}
{% if item.note %}<p><strong>备注:</strong> {{ item.note }}</p>{% endif %}
<div class="actions">
<a href="/items/{{ item.id }}">查看详情</a>
<a href="/items/{{ item.id }}/edit">编辑</a>
{% if item.is_container %}
<a href="/items/{{ item.id }}">查看内部内容</a>
{% endif %}
<form method="post" action="/items/{{ item.id }}/delete">
<button type="submit" class="link-button">删除</button>
</form>
</div>
</article>
{% endfor %}
{% else %}
<section class="card">
<p>这个箱子里还没有物品。</p>
</section>
{% endif %}
</section>
{% endblock %}
+31
View File
@@ -0,0 +1,31 @@
{% extends "base.html" %}
{% block content %}
<div class="page-header">
<div>
<h1>{{ page_title }}</h1>
<p class="muted">所属箱子:<a href="/boxes/{{ box.id }}">{{ box.name }}</a></p>
</div>
<a href="/boxes/{{ box.id }}">返回箱子</a>
</div>
<form method="post" action="{{ form_action }}" class="stack">
<label>
名称
<input type="text" name="name" value="{{ item.name if item else '' }}" required>
</label>
<label>
数量
<input type="number" name="quantity" min="0" value="{{ item.quantity if item and item.quantity is not none else '' }}">
</label>
<label class="checkbox-row">
<input type="checkbox" name="is_container" {% if item and item.is_container %}checked{% endif %}>
这个物品本身是一个小容器
</label>
<label>
备注
<textarea name="note" rows="4">{{ item.note if item and item.note else '' }}</textarea>
</label>
<button type="submit">{{ submit_label }}</button>
</form>
{% endblock %}
+57
View File
@@ -0,0 +1,57 @@
{% extends "base.html" %}
{% block content %}
<div class="page-header">
<div>
<h1>{{ item.name }}</h1>
<p class="muted">位于箱子 <a href="/boxes/{{ item.box.id }}">{{ item.box.name }}</a></p>
</div>
<div class="actions">
<a href="/boxes/{{ item.box.id }}">返回箱子</a>
<a href="/items/{{ item.id }}/edit">编辑物品</a>
</div>
</div>
<section class="card">
<p><strong>是否容器:</strong> {{ "是" if item.is_container else "否" }}</p>
<p><strong>数量:</strong> {{ item.quantity if item.quantity is not none else '-' }}</p>
<p><strong>备注:</strong> {{ item.note or '-' }}</p>
<div class="actions">
<form method="post" action="/items/{{ item.id }}/delete">
<button type="submit" class="link-button">删除物品</button>
</form>
</div>
</section>
{% if item.is_container %}
<section class="stack">
<div class="page-header">
<h2>子物品</h2>
<a class="button" href="/items/{{ item.id }}/subitems/new">添加子物品</a>
</div>
{% if item.subitems %}
{% for subitem in item.subitems %}
<article class="card">
<h3>{{ subitem.name }}</h3>
{% if subitem.quantity is not none %}<p><strong>数量:</strong> {{ subitem.quantity }}</p>{% endif %}
{% if subitem.note %}<p><strong>备注:</strong> {{ subitem.note }}</p>{% endif %}
<div class="actions">
<a href="/subitems/{{ subitem.id }}/edit">编辑</a>
<form method="post" action="/subitems/{{ subitem.id }}/delete">
<button type="submit" class="link-button">删除</button>
</form>
</div>
</article>
{% endfor %}
{% else %}
<section class="card">
<p>还没有子物品。</p>
</section>
{% endif %}
</section>
{% else %}
<section class="card">
<p>这个物品不是容器,因此不能包含子物品。</p>
</section>
{% endif %}
{% endblock %}
+27
View File
@@ -0,0 +1,27 @@
{% extends "base.html" %}
{% block content %}
<div class="page-header">
<div>
<h1>{{ page_title }}</h1>
<p class="muted">上级物品:<a href="/items/{{ item.id }}">{{ item.name }}</a></p>
</div>
<a href="/items/{{ item.id }}">返回物品</a>
</div>
<form method="post" action="{{ form_action }}" class="stack">
<label>
名称
<input type="text" name="name" value="{{ subitem.name if subitem else '' }}" required>
</label>
<label>
数量
<input type="number" name="quantity" min="0" value="{{ subitem.quantity if subitem and subitem.quantity is not none else '' }}">
</label>
<label>
备注
<textarea name="note" rows="4">{{ subitem.note if subitem and subitem.note else '' }}</textarea>
</label>
<button type="submit">{{ submit_label }}</button>
</form>
{% endblock %}