Skip to content

Commit

Permalink
merge with master
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandravaphilips committed Aug 13, 2024
1 parent 9cb6a12 commit 6499f5b
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 135 deletions.
29 changes: 4 additions & 25 deletions peachjam/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,7 @@ def send_email(self):
class SaveDocumentForm(forms.ModelForm):
folder = forms.ModelChoiceField(queryset=Folder.objects, required=False)
new_folder = forms.CharField(max_length=255, required=False)
user_profile = forms.ModelChoiceField(
queryset=UserProfile.objects, widget=forms.HiddenInput()
)
user_profile = forms.ModelChoiceField(queryset=UserProfile.objects, required=False)
document = forms.ModelChoiceField(
queryset=CoreDocument.objects, widget=forms.HiddenInput()
)
Expand All @@ -317,14 +315,15 @@ class Meta:

def __init__(self, *args, document=None, user_profile=None, **kwargs):
super().__init__(*args, **kwargs)
if document is not None and user_profile is not None:
self.user_profile = user_profile
if document is not None:
self.document = document
self.user_profile = user_profile
self.fields["document"].initial = self.document
self.fields["user_profile"].initial = self.user_profile
self.fields["folder"].queryset = user_profile.folders.all()

def clean(self):
self.cleaned_data["user_profile"] = self.user_profile
if self.cleaned_data.get("new_folder"):
folder, _ = Folder.objects.get_or_create(
name=self.cleaned_data["new_folder"],
Expand All @@ -337,26 +336,6 @@ def save(self, commit=True):
return super().save()


class FolderForm(forms.ModelForm):
name = forms.CharField(max_length=255, required=True)
user_profile = forms.ModelChoiceField(
queryset=UserProfile.objects, widget=forms.HiddenInput()
)

class Meta:
model = Folder
fields = "__all__"

def __init__(self, *args, user_profile=None, **kwargs):
super().__init__(*args, **kwargs)
if user_profile is not None:
self.user_profile = user_profile
self.fields["user_profile"].initial = self.user_profile

def save(self, commit=True):
return super().save()


class PeachjamSignupForm(SignupForm):
captcha = ReCaptchaField(widget=ReCaptchaV2Invisible)

Expand Down
2 changes: 1 addition & 1 deletion peachjam/js/components/DocumentProblemModal.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="modal-dialog">
<div id="documentDetailModal" class="modal-content">
<div class="modal-content">
<div class="modal-header">
<h5 id="documentProblemModalTitle" class="modal-title">
{{ $t('Is there something wrong with this document?') }}
Expand Down
2 changes: 1 addition & 1 deletion peachjam/models/save_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ def __str__(self):
message = f"{self.document.title} has been saved"
if self.folder:
message += f" to the '{self.folder.name}' folder"
return _("Document has been saved")
return message
18 changes: 9 additions & 9 deletions peachjam/templates/peachjam/_document_detail_toolbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
hx-target="#saveDocument"
hx-include="#save_document-form">
{% if saved.folder %}
<i class="bi bi-star-fill"></i> Saved to {{ saved.folder }}
<i class="bi bi-star-fill"></i> {% trans 'Saved to' %} {{ saved.folder }}
{% elif saved %}
<i class="bi bi-star-fill"></i> Saved
<i class="bi bi-star-fill"></i> {% trans 'Saved' %}
{% else %}
Save document
{% trans 'Save document' %}
{% endif %}
</button>
<div id="saveDocument" class="modal fade" tabindex="-1" aria-hidden="true">
Expand All @@ -37,28 +37,28 @@
data-bs-toggle="modal"
type="button"
data-bs-target="#loginprompt">
Save document
{% trans 'Save document' %}
</button>
<div id="loginprompt" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Login</h5>
<h5 class="modal-title">{% trans 'Login' %}</h5>
<button type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Close"></button>
</div>
<div class="modal-body">
<p>
<strong>You are not logged in.</strong>
<strong>{% trans 'You are not logged in' %}.</strong>
</p>
<p>To save a document you need to be logged in.</p>
<p>{% trans 'To save a document you need to be logged in' %}.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{% trans 'Close' %}</button>
<a href="{% url 'account_login' %}?next={{ document.get_absolute_url }}"
class="btn btn-primary">Login</a>
class="btn btn-primary">{% trans 'Login' %}</a>
</div>
</div>
</div>
Expand Down
152 changes: 78 additions & 74 deletions peachjam/templates/peachjam/_folders_list.html
Original file line number Diff line number Diff line change
@@ -1,86 +1,90 @@
{% load i18n %}
<div class="d-flex justify-content-between align-items-center">
<h1 class="mb-4">Saved documents</h1>
<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' %}">
New Folder
{% trans 'New Folder' %}
</button>
</div>
{% 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 %}
{% 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.">
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">
Rename
</button>
</div>
</div>
{% endfor %}
{% if ungrouped_saved_documents %}
<div class="card">
<h3 class="card-header">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 %}
4 changes: 1 addition & 3 deletions peachjam/templates/peachjam/_header.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@
<a class="dropdown-item" href="{% url 'admin:index' %}">{% trans 'Admin' %}</a>
{% endif %}
<a class="dropdown-item" href="{% url 'account_logout' %}">{% trans 'Logout' %}</a>
<a class="dropdown-item"
href="{% url 'saved_document_list' %}"
target="_blank">{% trans 'Saved documents' %}</a>
<a class="dropdown-item" href="{% url 'saved_document_list' %}">{% trans 'Saved documents' %}</a>
</li>
</ul>
</li>
Expand Down
3 changes: 1 addition & 2 deletions peachjam/templates/peachjam/layouts/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@
{% block head-css %}{% endblock %}
{% block head-js %}{% endblock %}
</head>
<body hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
class="{% block body-class %}{% endblock %}">
<body class="{% block body-class %}{% endblock %}">
{% block header %}{% endblock %}
{% block body-content %}{% endblock %}
{% block footer %}{% endblock %}
Expand Down
31 changes: 18 additions & 13 deletions peachjam/templates/peachjam/save_document.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<div class="modal-dialog" id="testing">
{% load i18n %}
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<p class="h5 modal-title">Save document</p>
<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">
{% if updated %}<div class="alert alert-success">{{ saved_document }}</div>{% endif %}
{% if updated %}<div class="alert alert-success">Document has been saved</div>{% endif %}
<form id="save_document-form"
hx-post="{% url 'save_document' %}"
hx-target="#saveDocument">
{% csrf_token %}
<p class="h5">{{ document }}</p>
{{ save_document_form.document }}
{{ save_document_form.user_profile }}
<label class="form-label" for="{{ save_document_form.folder.id_for_label }}">
{{ save_document_form.folder.label }}
</label>
Expand All @@ -34,19 +35,19 @@
data-bs-target="#addFolder"
aria-expanded="false"
aria-controls="addFolder">
New folder...
{% trans 'New folder' %}...
</button>
<div class="collapse" id="addFolder">
<label class="form-label"
for="{{ save_document_form.new_folder.id_for_label }}">New folder name</label>
for="{{ save_document_form.new_folder.id_for_label }}">{% trans 'New folder name' %}</label>
<input class="form-control"
id="{{ save_document_form.new_folder.id_for_label }}"
name="{{ save_document_form.new_folder.name }}"
type="text"/>
</div>
<p class="mt-3">
<a class="icon-link icon-link-hover link-underline link-underline-opacity-0"
href="{% url 'saved_document_list' %}">View saved documents</a>
href="{% url 'saved_document_list' %}">{% trans 'View saved documents' %}</a>
</p>
</form>
</div>
Expand All @@ -58,16 +59,20 @@
hx-include="#save_document-form"
hx-delete="{% url 'save_document' %}?id={{ saved_document.id }}"
hx-confirm="Are you sure you want to unsave this document?">
Unsave
{% trans 'Unsave' %}
</button>
<div>
<button type="button"
class="btn btn-outline-secondary btn-shrink-sm ms-2"
data-bs-dismiss="modal">Close</button>
data-bs-dismiss="modal">
{% trans 'Close' %}
</button>
<button class="btn btn-primary ms-1"
type="submit"
form="save_document-form"
data-bs-dismiss="modal">Save</button>
data-bs-dismiss="modal">
{% trans 'Save' %}
</button>
</div>
</div>
</div>
Expand All @@ -83,10 +88,10 @@
hx-include="#save_document-form"
hx-swap-oob="true">
{% if deleted %}
Save document
{% trans 'Save document' %}
{% elif saved_document.folder %}
<i class="bi bi-star-fill"></i> Saved to {{ saved_document.folder }}
<i class="bi bi-star-fill"></i> {% trans 'Saved to' %} {{ saved_document.folder }}
{% else %}
<i class="bi bi-star-fill"></i> Saved
<i class="bi bi-star-fill"></i> {% trans 'Saved' %}
{% endif %}
</button>
Loading

0 comments on commit 6499f5b

Please sign in to comment.