Updates edit/create shelf forms

This commit is contained in:
Mouse Reeve 2021-09-28 16:37:24 -07:00
parent dba0aaff2c
commit 24553e0e35
4 changed files with 29 additions and 33 deletions

View file

@ -7,21 +7,7 @@
{% block form %} {% block form %}
<form name="create-shelf" action="{% url 'shelf-create' %}" method="post"> <form name="create-shelf" action="{% url 'shelf-create' %}" method="post">
{% csrf_token %} {% include "shelf/form.html" with editable=shelf.editable form=create_form %}
<input type="hidden" name="user" value="{{ request.user.id }}">
<div class="field">
<label class="label" for="id_name_create">{% trans "Name:" %}</label>
<input type="text" name="name" maxlength="100" class="input" required="true" id="id_name_create">
</div>
<div class="field has-addons">
<div class="control">
{% include 'snippets/privacy_select.html' %}
</div>
<div class="control">
<button class="button is-primary" type="submit">{% trans "Create Shelf" %}</button>
</div>
</div>
</form> </form>
{% endblock %} {% endblock %}

View file

@ -7,24 +7,7 @@
{% block form %} {% block form %}
<form name="edit-shelf" action="{{ shelf.local_path }}" method="post"> <form name="edit-shelf" action="{{ shelf.local_path }}" method="post">
{% csrf_token %} {% include "shelf/form.html" with editable=shelf.editable form=edit_form privacy=shelf.privacy %}
<input type="hidden" name="user" value="{{ request.user.id }}">
<div class="columns is-mobile">
{% if shelf.editable %}
<div class="column">
<label class="label" for="id_name">{% trans "Name:" %}</label>
<input type="text" name="name" maxlength="100" class="input" required="true" value="{{ shelf.name }}" id="id_name">
</div>
{% else %}
<input type="hidden" name="name" required="true" value="{{ shelf.name }}">
{% endif %}
<div class="column">
<label class="label" for="privacy_{{ shelf.id }}">{% trans "Shelf privacy:" %}</label>
{% include 'snippets/privacy_select.html' with current=shelf.privacy uuid=shelf.id no_label=True %}
</div>
</div>
<button class="button is-primary" type="submit">{% trans "Update shelf" %}</button>
</form> </form>
{% endblock %} {% endblock %}

View file

@ -0,0 +1,25 @@
{% load i18n %}
{% csrf_token %}
<input type="hidden" name="user" value="{{ request.user.id }}">
{% if editable %}
<div class="field">
<label class="label" for="id_name">{% trans "Name:" %}</label>
{{ form.name }}
</div>
{% else %}
<input type="hidden" name="name" required="true" value="{{ shelf.name }}">
{% endif %}
<div class="field">
<label class="label" for="id_description">{% trans "Description:" %}</label>
{{ form.description }}
</div>
<div class="field has-addons">
<div class="control">
{% include 'snippets/privacy_select.html' with current=privacy %}
</div>
<div class="control">
<button class="button is-primary" type="submit">{% trans "Save" %}</button>
</div>
</div>

View file

@ -85,6 +85,8 @@ class Shelf(View):
"shelves": shelves, "shelves": shelves,
"shelf": shelf, "shelf": shelf,
"books": page, "books": page,
"edit_form": forms.ShelfForm(instance=shelf),
"create_form": forms.ShelfForm(),
"page_range": paginated.get_elided_page_range( "page_range": paginated.get_elided_page_range(
page.number, on_each_side=2, on_ends=1 page.number, on_each_side=2, on_ends=1
), ),