Skip to content

Commit

Permalink
refactor templates
Browse files Browse the repository at this point in the history
  • Loading branch information
astynax committed Jun 7, 2021
1 parent c13f0a3 commit 94666b7
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 222 deletions.
6 changes: 3 additions & 3 deletions djaif/book/templates/admin/book_change_form.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "admin/change_form.html" %}
{% load i18n admin_urls %}
{% block after_related_objects %}
<a target="_blank" href="/book/{{ original.pk }}/map.svg">
<img src="/book/{{ original.pk }}/map.svg"/>
</a>
<a target="_blank" href="/book/{{ original.pk }}/map.svg">
<img src="/book/{{ original.pk }}/map.svg"/>
</a>
{% endblock %}
17 changes: 0 additions & 17 deletions djaif/book/templates/book.html

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
<body>
<ul>
{% for book in books %}
<li><a href="book/{{ book.id }}">
{{ book.title }}
{% if book.cover_art %}
<img src="{{ book.cover_art.url }}" />
{% endif %}
</a></li>
<li><a href="book/{{ book.id }}">
{{ book.title }}
{% if book.cover_art %}
<img src="{{ book.cover_art.url }}" />
{% endif %}
</a></li>
{% endfor %}
</ul>
</body>
Expand Down
15 changes: 15 additions & 0 deletions djaif/book/templates/default.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="/static/styles.css"
type="text/css" media="screen" />
<link rel="icon" href="/static/favicon.png"
type="image/png" sizes="64x64" />
</head>
<body>
{% block body %}
{% endblock %}
</body>
</html>
69 changes: 31 additions & 38 deletions djaif/book/templates/note.html
Original file line number Diff line number Diff line change
@@ -1,45 +1,38 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{{ page.book.title }}: {{ page.title }}</title>
</head>
<body>
<h3>
{{ page.title }}: Заметка
</h3>
{% extends "default.html" %}
{% block title %}{{ page.book.title }}: {{ page.title }}{% endblock %}
{% block body %}
<div class="single-column">
<h1><a href="{% url 'book' page.book.id %}">{{ page.book.title }} ({{ page.title }})</a>: Заметка</h1>
<form method="POST" style="display: grid;"
action="{% url 'update_note' page.book.id note.id %}">
{% csrf_token %}
<label for="memo-text">Текст</label>
<textarea id="memo-text" name="text">{{ note.text }}</textarea>

<label for="memo-page">Привязка</label>
<select id="memo-page" name="page">
{% if note.page %}
<option value="keep"
{% if note.page.id != page.id %}
selected
{% endif %}>
Оставить привязанной к [{{ note.page.title }}]
</option>
{% endif %}
{% if not note.page or note.page.id != page.id %}
<option value="change">
Привязать к [{{ page.title }}]
</option>
{% endif %}
<option value="remove"
{% if not note.page %}
selected
{% endif %}>
{% if note.page %}Отвязать{% endif %}
</option>
</select>
<label for="memo-pinned">Закреплена</label>
<input id="memo-pinned" name="pinned" type="checkbox"
{% if note.pinned %}checked{% endif %}>
<label for="memo-page">Привязка
<select id="memo-page" name="page">
{% if note.page %}
<option value="keep"
{% if note.page.id != page.id %}
selected
{% endif %}
>Оставить привязанной к [{{ note.page.title }}]</option>
{% endif %}
{% if not note.page or note.page.id != page.id %}
<option value="change">Привязать к [{{ page.title }}]</option>
{% endif %}
<option value="remove"
{% if not note.page %}
selected
{% endif %}
>{% if note.page %}Отвязать{% endif %}</option>
</select>
</label>
<label for="memo-pinned">
Закреплена
<input id="memo-pinned" name="pinned" type="checkbox"
{% if note.pinned %}checked{% endif %}>
</label>
<button type="submit">Обновить</button>
</form>
</body>
</html>
</div>
{% endblock %}
137 changes: 67 additions & 70 deletions djaif/book/templates/page.html
Original file line number Diff line number Diff line change
@@ -1,100 +1,97 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{{ page.book.title }}: {{ page.title }}</title>
<link rel="stylesheet" href="/static/page.css" type="text/css" media="screen" />
<link rel="icon" sizes="64x64" href="/static/favicon.png" type="image/png" />
</head>
<body>
<div class="main">
<div class="content">
{% extends "default.html" %}
{% block title %}{{ page.book.title }}: {{ page.title }}{% endblock %}
{% block body %}
<div class="page">
<div class="page-split">
<div class="page-content">
<h1>
{{ page.title }}
</h1>
{{ page.body }}
{% if page_items %}
<h3>Вы видите</h3>
<ul>
{% for item in page_items %}
<li>
<a href="{% url 'take' page.book.id item.id %}">
{{ item.name }}
</a>
</li>
{% endfor %}
</ul>
<h3>Вы видите</h3>
<ul>
{% for item in page_items %}
<li>
<a href="{% url 'take' page.book.id item.id %}">
{{ item.name }}
</a>
</li>
{% endfor %}
</ul>
{% endif %}
{% if dropped_items %}
<h3>Брошено вами ранее</h3>
<ul>
{% for dropped_item in dropped_items %}
<li>
{{ dropped_item.item.name }}
<a href="{% url 'take_back' page.book.id dropped_item.id %}">
[Подобрать]
</a>
</li>
{% endfor %}
</ul>
<h3>Брошено вами ранее</h3>
<ul>
{% for dropped_item in dropped_items %}
<li>
{{ dropped_item.item.name }}
<a href="{% url 'take_back' page.book.id dropped_item.id %}">
[Подобрать]
</a>
</li>
{% endfor %}
</ul>
{% endif %}
<h3>Куда податься?</h3>
<ul>
{% for link, passable in links %}
<li>
{% if passable %}
<a href="{% url 'go_to' page.book.id link.id %}">
{{ link.name }}
</a>
{% else %}
{{ link.name }}
{% endif %}
</li>
<li>
{% if passable %}
<a href="{% url 'go_to' page.book.id link.id %}">
{{ link.name }}
</a>
{% else %}
{{ link.name }}
{% endif %}
</li>
{% endfor %}
</ul>
{% if progress.items.all %}
<h3>Инвентарь</h3>
<ul>
{% for item in progress.items.all %}
<li>
{{ item.name }}
<a href="{% url 'drop' page.book.id item.id %}">
[Выбросить]
</a>
</li>
{% endfor %}
</ul>
<h3>Инвентарь</h3>
<ul>
{% for item in progress.items.all %}
<li>
{{ item.name }}
<a href="{% url 'drop' page.book.id item.id %}">
[Выбросить]
</a>
</li>
{% endfor %}
</ul>
{% endif %}
<hr />
<a href="{% url 'saves' page.book.id %}">Сохранения</a>
</div>
<div class="sidebar">
<div class="page-sidebar">
<h3>Заметки</h3>
<form method="POST" class="new-note"
action="{% url 'add_note' page.book.id %}">
{% csrf_token %}
<label for="memo-text">Новая</label>
<textarea id="memo-text" name="text"></textarea>
<label for="memo-pin">Для этого места</label>
<input id="memo-pin" name="pin" type="checkbox">
<label for="memo-pin">
Для этого места
<input id="memo-pin" name="pin" type="checkbox">
</label>
<button type="submit">Добавить</button>
</form>
{% for name, noteset in notesets %}
<ul class="noteset noteset-{{ name }}">
{% for note_id, note_text, note_page_title in noteset %}
<li>
<a href="{% url 'delete_note' page.book.id note_id %}">🚮</a>
<a href="{% url 'toggle_note' page.book.id note_id %}">📌</a>
<a href="{% url 'update_note' page.book.id note_id %}">🖉</a>
<pre>{{ note_text }}</pre>
{% if note_page_title and name == 'other' %}
({{ note_page_title }})
{% endif %}
</li>
{% endfor %}
</ul>
<ul class="noteset noteset-{{ name }}">
{% for note_id, note_text, note_page_title in noteset %}
<li>
<a href="{% url 'delete_note' page.book.id note_id %}">🚮</a>
<a href="{% url 'toggle_note' page.book.id note_id %}">📌</a>
<a href="{% url 'update_note' page.book.id note_id %}">🖉</a>
<pre>{{ note_text }}</pre>
{% if note_page_title and name == 'other' %}
({{ note_page_title }})
{% endif %}
</li>
{% endfor %}
</ul>
{% endfor %}
</div>
</div>
</body>
</html>
</div>
{% endblock %}
38 changes: 14 additions & 24 deletions djaif/book/templates/saves.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{{ book.title }}: Сохранения</title>
</head>
<body>
<h1>
{{ book.title }}
</h1>
<h2>
{{ page.title }}
</h2>
<a href="{% url 'book' book.id %}">[Продолжить игру]</a>
<br/>
<a href="{% url 'save_new' book.id %}">[Новое сохранение]</a>
{% extends "default.html" %}
{% block title %}{{ book.title }}: Сохранения{% endblock %}
{% block body %}
<div class="single-column">
<h1><a href="{% url 'book' page.book.id %}">{{ page.book.title }} ({{ page.title }})</a>: Сохранения</h1>
<a href="{% url 'save_new' page.book.id %}">[Новое сохранение]</a>
<ul>
{% for save in saves %}
<li>
<a href="{% url 'delete_save' book.id save.id %}">[Удалить]</a>
<a href="{% url 'load_from' book.id save.id %}">[Загрузить]</a>
<a href="{% url 'save_to' book.id save.id %}">[Заменить]</a>
[{{ save.updated_at|date:"Y.m.d H:i:s" }}] {{ save.book_page.title }}
</li>
<li>
<a href="{% url 'delete_save' page.book.id save.id %}">[Удалить]</a>
<a href="{% url 'load_from' page.book.id save.id %}">[Загрузить]</a>
<a href="{% url 'save_to' page.book.id save.id %}">[Заменить]</a>
[{{ save.updated_at|date:"Y.m.d H:i:s" }}] {{ save.book_page.title }}
</li>
{% endfor %}
</ul>
</body>
</html>
</div>
{% endblock %}
10 changes: 3 additions & 7 deletions djaif/book/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def inner(request, book_id, **kwargs):
def view_books(request):
return render(
request,
'book_index.html',
'books.html',
context={'books': models.Book.objects.all()},
)

Expand Down Expand Up @@ -85,7 +85,6 @@ def view_book(request, book_id):
'page': progress.book_page,
'progress': progress,
'links': links,
'notesets': notesets,
'page_items': progress.book_page.items.exclude(
id__in=progress.items.only('id'),
).exclude(
Expand All @@ -96,6 +95,7 @@ def view_book(request, book_id):
'dropped_items': progress.droppeditem_set.filter(
book_page=progress.book_page,
).all(),
'notesets': notesets,
},
)

Expand Down Expand Up @@ -164,7 +164,6 @@ def view_saves(request, progress, book_id):
request,
'saves.html',
context={
'book': progress.book,
'page': progress.book_page,
'saves': saves,
},
Expand Down Expand Up @@ -195,10 +194,7 @@ def view_book_map(request, book_id):

@on_progress
def add_note(request, progress, book_id):
if 'pin' in request.POST:
page = progress.book_page
else:
page = None
page = progress.book_page if 'pin' in request.POST else None
models.Note.objects.create(
progress=progress,
text=request.POST['text'],
Expand Down
Loading

0 comments on commit 94666b7

Please sign in to comment.