SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit d8420c9f authored by George Katsikas's avatar George Katsikas :goat:
Browse files

add notes list view

parent db084ad3
No related branches found
No related tags found
No related merge requests found
{{ note.title }}
{% load scipost_extras %}
<div class="row"
hx-get="{% url "pins:_hx_notes_list" object|content_type_id object.id %}"
hx-trigger="notes-updated from:body target:form delay:2s, {% if notes is None %}load{% endif %}"
hx-swap="outerHTML">
<div class="col-12">
<h3>Notes</h3>
<div>
<button class="btn btn-light btn-sm"
hx-get="{% url "pins:_hx_note_create_form" object|content_type_id object.id %}"
hx-target="closest div">Add note</button>
</div>
<ul>
{% for note in notes %}
<li>{% include "pins/_hx_note_item.html" %}</li>
{% endfor %}
</ul>
</div>
</div>
......@@ -3,14 +3,26 @@ __license__ = "AGPL v3"
app_name = "pins"
from django.urls import path
from django.urls import include, path
from . import views
urlpatterns = [
path(
"_hx_create/<int:regarding_content_type>/<int:regarding_object_id>",
views._hx_note_create_form,
name="hx_note_create_form",
"<int:regarding_content_type>/<int:regarding_object_id>",
include(
[
path(
"_hx_create",
views._hx_note_create_form,
name="_hx_note_create_form",
),
path(
"_hx_list",
views._hx_notes_list,
name="_hx_notes_list",
),
]
),
),
]
......@@ -6,6 +6,7 @@ from django.template.response import TemplateResponse
from scipost.permissions import HTMXResponse
from .models import Note
from .forms import NoteForm
......@@ -28,3 +29,21 @@ def _hx_note_create_form(request, regarding_content_type, regarding_object_id):
context = {"form": form}
return TemplateResponse(request, "pins/_hx_note_create_form.html", context)
def _hx_notes_list(request, regarding_content_type, regarding_object_id):
regarding_content_type = ContentType.objects.get_for_id(regarding_content_type)
object = regarding_content_type.get_object_for_this_type(id=regarding_object_id)
notes = Note.objects.filter(
regarding_content_type=regarding_content_type,
regarding_object_id=regarding_object_id,
)
# TODO: Filter to the notes that the user has permission to see
# ...
context = {
"object": object,
"notes": notes,
}
return TemplateResponse(request, "pins/_hx_notes_list.html", context)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment