Skip to content

Commit

Permalink
feat(pages): admin link to page
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoeejoee committed Nov 12, 2023
1 parent 7fd6896 commit 1d2dad5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
12 changes: 11 additions & 1 deletion fiesta/apps/pages/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from django.contrib import admin
from django.utils.html import format_html
from mptt.admin import DraggableMPTTAdmin

from ..plugins.admin import BaseChildConfigurationAdmin
Expand All @@ -20,12 +21,21 @@ class PagesAdmin(DraggableMPTTAdmin):
list_display = (
"tree_actions",
"indented_title",
"external_url",
"default",
"slug_path",
"order",
"section",
# ...more fields if you feel like it...
)
list_display_links = ("indented_title",)
list_filter = ["section"]
expand_tree_by_default = True

@admin.display(
description="Page link",
)
def external_url(self, obj: Page):
return format_html(
"<a href='{url}'>{url}</a>",
url=obj.get_absolute_url(),
)
6 changes: 5 additions & 1 deletion fiesta/apps/pages/models/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ def __str__(self):
return f"{self.title}"

def get_absolute_url(self) -> str:
return self.section.section_base_url(None) + reverse("pages:single-page", kwargs=dict(slug=self.slug_path))
return self.section.section_base_url(None) + (
reverse("pages:default-page")
if self.default
else reverse("pages:single-page", kwargs=dict(slug=self.slug_path))
)

def save(self, *args, **kwargs):
super().save(*args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion fiesta/apps/pages/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
urlpatterns = [
# TODO: use custom converter https://docs.djangoproject.com/en/4.1/topics/http/urls/#registering-custom-path-converters
path("<path:slug>", SinglePageView.as_view(), name="single-page"),
path("", DefaultPageView.as_view()),
path("", DefaultPageView.as_view(), name="default-page"),
]

0 comments on commit 1d2dad5

Please sign in to comment.