-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d5fbb5
commit 44c5651
Showing
9 changed files
with
181 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
{% load static i18n %} | ||
<div class="modal-header"> | ||
<h5 id="SaveDocumentModalTitle" class="modal-title">{% trans 'Where do you want to save your document?' %}</h5> | ||
<button type="button" | ||
class="btn-close" | ||
data-bs-dismiss="modal" | ||
aria-label="Close"/> | ||
</div> | ||
<div class="modal-body"> | ||
<div id="SaveDocumentModal" data-vue-component="SaveDocumentModal"></div> | ||
<div class="modal-dialog" id="testing"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<p class="h5 modal-title">Add new collection</p> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<form id="collections-form" hx-post="{% url 'save_document' %}"> | ||
{% if new %} | ||
<h4>Document Saved</h4> | ||
{% else %} | ||
<h2 class="h4">Choose Collection</h2> | ||
{% endif %} | ||
<p class="h6">{{ saved_document }}</p> | ||
{{ save_document_form.document }} | ||
{{ save_document_form.user_profile }} | ||
<label class="form-label" | ||
for="{{ save_document_form.collection.id_for_label }}"> | ||
{{ save_document_form.collection.label }} | ||
</label> | ||
<select id="{{ save_document_form.collection.id_for_label }}" | ||
class="form-select" | ||
name="{{ save_document_form.collection.name }}"> | ||
{% for value, name in save_document_form.fields.collection.choices %} | ||
<option value="{{ value }}" | ||
{% if save_document_form.fields.collection.value == x %} selected{% endif %}> | ||
{{ name }} | ||
</option> | ||
{% endfor %} | ||
</select> | ||
<div class="d-inline-flex justify-content-between"> | ||
<div> | ||
<button type="button" | ||
class="btn btn-outline-secondary btn-shrink-sm ms-2" | ||
data-bs-toggle="modal" | ||
data-bs-target="#addCollection"> | ||
Add collection | ||
</button> | ||
</div> | ||
<button class="btn btn-primary" type="submit">Done</button> | ||
</div> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,57 @@ | ||
from typing import Any | ||
|
||
from django.contrib.auth import get_user_model | ||
from django.db.models.query import QuerySet | ||
from django.shortcuts import render | ||
from django.views.generic import ListView | ||
from django.http import HttpRequest | ||
from django.shortcuts import get_object_or_404 | ||
from django.views.generic import TemplateView | ||
|
||
from peachjam.models import Collection | ||
from peachjam.forms import CollectionForm, SaveDocumentForm | ||
from peachjam.models import SavedDocument, UserProfile | ||
|
||
User = get_user_model() | ||
|
||
|
||
class CollectionListView(ListView): | ||
model = Collection | ||
class CreateCollectionView(TemplateView): | ||
template_name = "peachjam/collections_list.html" | ||
context_object_name = "collections" | ||
navbar_link = "collections" | ||
paginate_by = 10 | ||
|
||
def get_queryset(self) -> QuerySet[Any]: | ||
# print(super().get_queryset().filter(user=User(self.request.user.id))) | ||
return super().get_queryset().filter(user=User(self.request.user.id)) | ||
def post(self, request: HttpRequest): | ||
post_data = request.POST | ||
user_profile = get_object_or_404(UserProfile, user=self.request.user) | ||
form = CollectionForm(post_data, user_profile=user_profile) | ||
context = self.get_context_data() | ||
if form.is_valid(): | ||
instance = form.save() | ||
return self.render_to_response( | ||
{ | ||
"saved_document": instance, | ||
"add_new_collection_form": form, | ||
**context, | ||
} | ||
) | ||
|
||
return self.render_to_response({"add_new_collection_form": form, **context}) | ||
|
||
|
||
class SaveDocumentView(TemplateView): | ||
template_name = "peachjam/save_document.html" | ||
|
||
def get_context_data(self, *args, **kwargs): | ||
context = super().get_context_data(*args, **kwargs) | ||
context = super().get_context_data(**kwargs) | ||
user_profile = get_object_or_404(UserProfile, user=self.request.user) | ||
collections = user_profile.collections.all() | ||
context["collections"] = collections | ||
return context | ||
|
||
def render_collections(self, request): | ||
return render(request, "peachjam/collections_list.html") | ||
def post(self, request: HttpRequest): | ||
post_data = request.POST | ||
instance = SavedDocument.objects.filter( | ||
document=post_data.get("document"), | ||
user_profile=post_data.get("user_profile"), | ||
).first() | ||
form = SaveDocumentForm(post_data, instance=instance) | ||
context = self.get_context_data() | ||
if form.is_valid(): | ||
instance = form.save() | ||
return self.render_to_response( | ||
{"saved_document": instance, "save_document_form": form, **context} | ||
) | ||
|
||
return self.render_to_response({"save_document_form": form, **context}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters