Skip to content

Commit

Permalink
added csrf token
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandravaphilips committed Aug 13, 2024
1 parent 6499f5b commit 803f958
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 85 deletions.
172 changes: 87 additions & 85 deletions peachjam/templates/peachjam/_folders_list.html
Original file line number Diff line number Diff line change
@@ -1,90 +1,92 @@
{% load i18n %}
<div class="d-flex justify-content-between align-items-center">
<h1 class="mb-4">{% trans 'Saved documents' %}</h1>
<button class="btn btn-primary"
hx-target="#folders-list"
hx-prompt="Give your folder a name:"
hx-post="{% url 'saved_document_list' %}">
{% trans 'New Folder' %}
</button>
</div>
{% if folders or ungrouped_saved_documents %}
{% for folder in folders %}
<div class="card mb-5">
<h3 class="card-header">{{ folder }}</h3>
<div class="card-body">
<div>
{% if folder.saved_documents.all %}
<table class="doc-table">
{% for saved_doc in folder.saved_documents.all %}
<tr>
<td class="cell-title">
<a href="{{ saved_doc.document.get_absolute_url }}">{{ saved_doc.document.title }}</a>
{% include 'peachjam/_labels.html' with labels=saved_doc.document.labels.all %}
</td>
<td class="cell-date" style="white-space: nowrap;">
{{ saved_doc.document.date }}
<a class="ms-3"
type="button"
hx-delete="{% url 'saved_document_list' %}?saved_doc_id={{ saved_doc.id }}"
hx-target="#folders-list"
hx-confirm="Are you sure you want to remove this document?">
<i class="bi bi-trash"></i>
</a>
</td>
</tr>
{% endfor %}
</table>
{% else %}
<p>{% trans 'No saved documents.' %}</p>
{% endif %}
<div hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'>
<div class="d-flex justify-content-between align-items-center">
<h1 class="mb-4">{% trans 'Saved documents' %}</h1>
<button class="btn btn-primary"
hx-target="#folders-list"
hx-prompt="Give your folder a name:"
hx-post="{% url 'saved_document_list' %}">
{% trans 'New Folder' %}
</button>
</div>
{% if folders or ungrouped_saved_documents %}
{% for folder in folders %}
<div class="card mb-5">
<h3 class="card-header">{{ folder }}</h3>
<div class="card-body">
<div>
{% if folder.saved_documents.all %}
<table class="doc-table">
{% for saved_doc in folder.saved_documents.all %}
<tr>
<td class="cell-title">
<a href="{{ saved_doc.document.get_absolute_url }}">{{ saved_doc.document.title }}</a>
{% include 'peachjam/_labels.html' with labels=saved_doc.document.labels.all %}
</td>
<td class="cell-date" style="white-space: nowrap;">
{{ saved_doc.document.date }}
<a class="ms-3"
type="button"
hx-delete="{% url 'saved_document_list' %}?saved_doc_id={{ saved_doc.id }}"
hx-target="#folders-list"
hx-confirm="Are you sure you want to remove this document?">
<i class="bi bi-trash"></i>
</a>
</td>
</tr>
{% endfor %}
</table>
{% else %}
<p>{% trans 'No saved documents.' %}</p>
{% endif %}
</div>
</div>
<div class="card-footer text-end">
<button class="btn btn-outline-danger me-2"
type="button"
hx-delete="{% url 'saved_document_list' %}?folder_id={{ folder.id }}"
hx-target="#folders-list"
hx-confirm="Are you sure you want to delete this folder? All saved documents in this folder will also be deleted.">
{% trans 'Delete' %}
</button>
<button class="btn btn-secondary"
type="button"
hx-put="{% url 'saved_document_list' %}?folder_id={{ folder.id }}"
hx-target="#folders-list"
hx-prompt="Edit folder name">
{% trans 'Rename' %}
</button>
</div>
</div>
<div class="card-footer text-end">
<button class="btn btn-outline-danger me-2"
type="button"
hx-delete="{% url 'saved_document_list' %}?folder_id={{ folder.id }}"
hx-target="#folders-list"
hx-confirm="Are you sure you want to delete this folder? All saved documents in this folder will also be deleted.">
{% trans 'Delete' %}
</button>
<button class="btn btn-secondary"
type="button"
hx-put="{% url 'saved_document_list' %}?folder_id={{ folder.id }}"
hx-target="#folders-list"
hx-prompt="Edit folder name">
{% trans 'Rename' %}
</button>
</div>
</div>
{% endfor %}
{% if ungrouped_saved_documents %}
<div class="card">
<h3 class="card-header">{% trans 'Ungrouped documents' %}</h3>
<div class="card-body">
<table class="doc-table">
{% for saved_doc in ungrouped_saved_documents %}
<tr>
<td class="cell-title">
<a href="{{ saved_doc.document.get_absolute_url }}">{{ saved_doc.document.title }}</a>
{% include 'peachjam/_labels.html' with labels=saved_doc.document.labels.all %}
</td>
<td class="cell-date" style="white-space: nowrap;">
{{ saved_doc.document.date }}
<a class="ms-3"
type="button"
hx-delete="{% url 'saved_document_list' %}?saved_doc_id={{ saved_doc.id }}"
hx-target="#folders-list"
hx-confirm="Are you sure you want to remove this document?">
<i class="bi bi-trash"></i>
</a>
</td>
</tr>
{% endfor %}
</table>
{% endfor %}
{% if ungrouped_saved_documents %}
<div class="card">
<h3 class="card-header">{% trans 'Ungrouped documents' %}</h3>
<div class="card-body">
<table class="doc-table">
{% for saved_doc in ungrouped_saved_documents %}
<tr>
<td class="cell-title">
<a href="{{ saved_doc.document.get_absolute_url }}">{{ saved_doc.document.title }}</a>
{% include 'peachjam/_labels.html' with labels=saved_doc.document.labels.all %}
</td>
<td class="cell-date" style="white-space: nowrap;">
{{ saved_doc.document.date }}
<a class="ms-3"
type="button"
hx-delete="{% url 'saved_document_list' %}?saved_doc_id={{ saved_doc.id }}"
hx-target="#folders-list"
hx-confirm="Are you sure you want to remove this document?">
<i class="bi bi-trash"></i>
</a>
</td>
</tr>
{% endfor %}
</table>
</div>
</div>
</div>
{% endif %}
{% else %}
<p>You have no saved documents.</p>
{% endif %}
{% else %}
<p>You have no saved documents.</p>
{% endif %}
</div>
1 change: 1 addition & 0 deletions peachjam/templates/peachjam/save_document.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
data-bs-dismiss="modal"
hx-target="#saveDocument"
hx-include="#save_document-form"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-delete="{% url 'save_document' %}?id={{ saved_document.id }}"
hx-confirm="Are you sure you want to unsave this document?">
{% trans 'Unsave' %}
Expand Down

0 comments on commit 803f958

Please sign in to comment.