Skip to content

Commit

Permalink
updates saved document template
Browse files Browse the repository at this point in the history
  • Loading branch information
actlikewill committed Aug 30, 2024
1 parent ee6c299 commit 786060d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 28 deletions.
11 changes: 7 additions & 4 deletions peachjam/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,18 @@ class Meta:
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["folder"].queryset = self.instance.user.folders.all()
self.fields["document"].required = False

def clean(self):
if self.cleaned_data.get("new_folder"):
cleaned_data = super().clean()
cleaned_data["document"] = self.instance.document
if cleaned_data.get("new_folder"):
folder, _ = Folder.objects.get_or_create(
name=self.cleaned_data["new_folder"],
name=cleaned_data["new_folder"],
user=self.instance.user,
)
self.cleaned_data["folder"] = folder
return self.cleaned_data
cleaned_data["folder"] = folder
return cleaned_data


class PeachjamSignupForm(SignupForm):
Expand Down
29 changes: 29 additions & 0 deletions peachjam/templates/peachjam/saved_document_create.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% load i18n %}
<div id="saveDocumentWrapper">
<button id="saveDocumentButton"
class="btn btn-outline-primary btn-shrink-sm ms-2"
type="button"
data-bs-toggle="modal"
data-bs-target="#saveDocumentModal"
aria-expanded="false"
hx-post="{% url 'saved_document_create' %}?doc_id={{ form.document.value }}"
hx-target="#saveDocumentWrapper">
{% trans 'Save document' %}
</button>
<div hx-swap-oob="true" id="saveDocumentModalDialog" class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<p class="h5 modal-title">{% trans 'Save document' %}</p>
<button type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Close"></button>
</div>
<div class="modal-body">
Saving...
{{ form.errors }}
</div>
<div class="modal-footer d-flex"></div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@
type="button"
data-bs-toggle="modal"
data-bs-target="#saveDocumentModal"
aria-expanded="false"
{% if not saved_document %} hx-post="{% url 'saved_document_create' %}" hx-target="#saveDocumentWrapper" hx-include="#save-document-form" {% endif %}>
{% if saved_document %}
<i class="bi bi-star-fill"></i>
{% if saved_document.folder %}
{% trans 'Saved to' %} {{ saved_document.folder }}
{% else %}
{% trans 'Saved' %}
{% endif %}
aria-expanded="false">
<i class="bi bi-star-fill"></i>
{% if saved_document.folder %}
{% trans 'Saved to' %} {{ saved_document.folder }}
{% else %}
{% trans 'Save document' %}
{% trans 'Saved' %}
{% endif %}
</button>
<div hx-swap-oob="true" id="saveDocumentModalDialog" class="modal-dialog">
Expand All @@ -29,7 +24,7 @@
</div>
<div class="modal-body">
<form id="save-document-form"
{% if saved_document %} hx-post="{% url 'saved_document_update' saved_document.id %}" {% else %} hx-post="{% url 'saved_document_create' %}" {% endif %}
hx-post="{% url 'saved_document_update' saved_document.id %}"
hx-target="#saveDocumentWrapper">
{{ form.document }}
<p class="h5">{{ saved_document.document }}</p>
Expand Down Expand Up @@ -66,18 +61,16 @@
</form>
</div>
<div class="modal-footer d-flex justify-content-between">
{% if saved_document %}
<button class="btn btn-danger"
type="button"
data-bs-dismiss="modal"
hx-target="#saveDocumentWrapper"
hx-include="#save-document-form"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'saved_document_delete' saved_document.id %}"
hx-confirm="Are you sure you want to unsave this document?">
{% trans 'Unsave' %}
</button>
{% endif %}
<button class="btn btn-danger"
type="button"
data-bs-dismiss="modal"
hx-target="#saveDocumentWrapper"
hx-include="#save-document-form"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'saved_document_delete' saved_document.id %}"
hx-confirm="Are you sure you want to unsave this document?">
{% trans 'Unsave' %}
</button>
<div>
<button type="button"
class="btn btn-outline-secondary btn-shrink-sm ms-2"
Expand Down
3 changes: 2 additions & 1 deletion peachjam/views/save_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def get(self, *args, **kwargs):


class BaseSavedDocumentFormView(AllowSavedDocumentMixin, LoginRequiredMixin):
template_name = "peachjam/saved_document.html"
template_name = "peachjam/saved_document_update.html"
form_class = SaveDocumentForm
context_object_name = "saved_document"
model = SavedDocument
Expand All @@ -124,6 +124,7 @@ def get_success_url(self):


class SavedDocumentCreateView(BaseSavedDocumentFormView, CreateView):
template_name = "peachjam/saved_document_create.html"
permission_required = "peachjam.add_saveddocument"

def get_form_kwargs(self):
Expand Down

0 comments on commit 786060d

Please sign in to comment.