From 6c373d94d50af046245014f75ed81ecf947868ff Mon Sep 17 00:00:00 2001 From: Muralidhar Reddy Challa Date: Sat, 12 Oct 2024 11:44:19 +0530 Subject: [PATCH 1/2] Refactor action links for easier template customization - Replace Python template tags with a for loop in HTML - Change action structure from tuple to dictionary - Remove HTML generation in Python code - Allow direct rendering of action properties in template --- src/neapolitan/templates/neapolitan/partial/list.html | 6 ++++-- src/neapolitan/templatetags/neapolitan.py | 5 ++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/neapolitan/templates/neapolitan/partial/list.html b/src/neapolitan/templates/neapolitan/partial/list.html index a046c06..be4a954 100644 --- a/src/neapolitan/templates/neapolitan/partial/list.html +++ b/src/neapolitan/templates/neapolitan/partial/list.html @@ -27,8 +27,10 @@ {% endif %} ">{{ field }} {% endfor %} - - {{ object.actions }} + + {% for action in object.actions %} + {{ action.Name }} + {% endfor %} {% endfor %} diff --git a/src/neapolitan/templatetags/neapolitan.py b/src/neapolitan/templatetags/neapolitan.py index ee1e7fa..f7c4819 100644 --- a/src/neapolitan/templatetags/neapolitan.py +++ b/src/neapolitan/templatetags/neapolitan.py @@ -8,15 +8,14 @@ def action_links(view, object): actions = [ - (url, name) + {"Name": name, "URL": url} for url, name in [ (Role.DETAIL.maybe_reverse(view, object), "View"), (Role.UPDATE.maybe_reverse(view, object), "Edit"), (Role.DELETE.maybe_reverse(view, object), "Delete"), ] if url is not None ] - links = [f"{anchor_text}" for url, anchor_text in actions] - return mark_safe(" | ".join(links)) + return actions @register.inclusion_tag("neapolitan/partial/detail.html") From 26a30dec1361f88c73f0b3f975d32caedf2d6863 Mon Sep 17 00:00:00 2001 From: Muralidhar Reddy Challa Date: Sat, 12 Oct 2024 12:52:34 +0530 Subject: [PATCH 2/2] Implement pagination functionality - Add new template tag 'pagination' - Ensures compatibility with Django's page_obj structure - Create corresponding partial template 'pagination.html' - Implement inclusion tag for easy integration of pagination controls --- .../templates/neapolitan/object_list.html | 26 ++++++++-------- .../neapolitan/partial/pagination.html | 31 +++++++++++++++++++ src/neapolitan/templatetags/neapolitan.py | 16 ++++++++++ 3 files changed, 60 insertions(+), 13 deletions(-) create mode 100644 src/neapolitan/templates/neapolitan/partial/pagination.html diff --git a/src/neapolitan/templates/neapolitan/object_list.html b/src/neapolitan/templates/neapolitan/object_list.html index 4090e32..c248c3a 100644 --- a/src/neapolitan/templates/neapolitan/object_list.html +++ b/src/neapolitan/templates/neapolitan/object_list.html @@ -1,24 +1,24 @@ -{% extends "base.html" %} +{% extends 'base.html' %} {% load neapolitan %} {% block content %} - -
+

{{ object_verbose_name_plural|capfirst }}

{% if create_view_url %} - + {% endif %} -
+
-{% if object_list %} + {% if object_list %} {% object_list object_list view %} -{% else %} + {% if is_paginated %} + {% pagination page_obj %} + {% endif %} + {% else %}

There are no {{ object_verbose_name_plural }}. Create one now?

-{% endif %} - -
+ {% endif %} +
{% endblock %} diff --git a/src/neapolitan/templates/neapolitan/partial/pagination.html b/src/neapolitan/templates/neapolitan/partial/pagination.html new file mode 100644 index 0000000..96a2194 --- /dev/null +++ b/src/neapolitan/templates/neapolitan/partial/pagination.html @@ -0,0 +1,31 @@ + \ No newline at end of file diff --git a/src/neapolitan/templatetags/neapolitan.py b/src/neapolitan/templatetags/neapolitan.py index f7c4819..5f441fd 100644 --- a/src/neapolitan/templatetags/neapolitan.py +++ b/src/neapolitan/templatetags/neapolitan.py @@ -68,3 +68,19 @@ def object_list(objects, view): "headers": headers, "object_list": object_list, } + + +@register.inclusion_tag("neapolitan/partial/pagination.html") +def pagination(page_obj): + """ + Renders pagination controls for the given page object. + + Inclusion tag usage:: + + {% pagination page_obj %} + + Template: ``neapolitan/partial/pagination.html`` - Will render the pagination controls. + """ + return { + "page_obj": page_obj, + } \ No newline at end of file