Skip to content

Commit

Permalink
Merge pull request #30 from stuartmaxwell/page-parents
Browse files Browse the repository at this point in the history
Page parents
  • Loading branch information
stuartmaxwell authored Oct 10, 2024
2 parents 2eb8e01 + 2ec8b6c commit 53da8c1
Show file tree
Hide file tree
Showing 18 changed files with 1,157 additions and 123 deletions.
72 changes: 71 additions & 1 deletion docs/templatetags.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ Outputs the same comma-separated list of categories, but wrapped in a `span` tag

## blog_pages

Get all blog pages as a list, wrapped in HTML that can be configured with optional arguments.
Get all blog pages as a single-level list, wrapped in HTML that can be configured with optional arguments.

### Arguments

Expand Down Expand Up @@ -339,6 +339,76 @@ Outputs the same comma-separated list of pages, but wrapped in a `span` tag.
</span>
```

## blog_pages_list

Get all published blog pages and output as a nested list to support parent pages.

### Arguments

- `ul_outer_class` (optional): The CSS class(es) for the outer unordered list.
- `li_class` (optional): The CSS class(es) for the list item tags
- `a_class` (optional): The CSS class(es) for the anchor tags.
- `ul_child_class` (optional): The CSS class(es) for the nested unordered lists.

The output from this tag is HTML which has been marked as safe.

### Examples

Just the tag, with no arguments.

```django
{% blog_pages %}
```

This will output the following HTML:

```html
<ul>
<li>
<a href="/about">About me</a>
<ul>
<li>
<a href="/about/hobbies">Hobbies</a>
</li>
<li>
<a href="/about/resume">My Resume</a>
</li>
</ul>
</li>
<li>
<a href="/contact">Contact me</a>
</li>
</ul>
```

Or arguments can be used to build a Bootstrap-like navbar menu.

```django
{% blog_pages ul_outer_class="navbar-nav" li_class="nav-item" a_class="nav-link" ul_child_class="dropdown-menu" %}
```

This will output the following HTML:

```html
<ul class="navbar-nav">
<li class="nav-item">
<a href="/about" title="View the About me page" class="nav-link">About me</a>
<ul>
<li class="nav-item">
<a href="/about/hobbies" title="View the Hobbies page" class="nav-link">Hobbies</a>
</li>
<li class="nav-item">
<a href="/about/resume" title="View the My Resume page" class="nav-link">My Resume</a>
</li>
</ul>
</li>
<li class="nav-item">
<a href="/contact" title="View the Contact me page" class="nav-link">Contact me</a>
</li>
</ul>
```


## have_posts

Get a list of posts from the current context. This always returns a list, even if the context only contains a single post or page.
Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
@nox.parametrize("django_ver", ["~=4.2.0", "~=5.0.0", "~=5.1.0"])
def test(session: nox.Session, django_ver: str) -> None:
"""Run the test suite."""
session.install(".", "--all-extras", "-r", "pyproject.toml")
session.install("-e", ".", "--extra", "test", "-r", "pyproject.toml")
session.install(f"django{django_ver}")
session.run("pytest")
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "djpress"
version = "0.9.2"
version = "0.9.3"
description = "A blog application for Django sites, inspired by classic WordPress."
readme = "README.md"
requires-python = ">=3.10"
Expand Down
20 changes: 18 additions & 2 deletions src/djpress/admin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
"""djpress admin configuration."""

from typing import ClassVar

from django.contrib import admin

# Register the models here.
from djpress.models import Category, Post

admin.site.register(Category)
admin.site.register(Post)

@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
"""Category admin configuration."""

list_display: ClassVar["str"] = ["title", "slug"]


@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
"""Post admin configuration."""

list_display: ClassVar["str"] = ["post_type", "title", "slug", "date", "author"]
list_display_links: ClassVar["str"] = ["title", "slug"]
ordering: ClassVar["str"] = ["post_type", "-date"] # Displays pages first, then sorted by date.
list_filter: ClassVar["str"] = ["post_type", "date", "author"]
24 changes: 24 additions & 0 deletions src/djpress/migrations/0005_post_parent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 5.1.2 on 2024-10-09 06:22

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("djpress", "0004_rename_name_category_title_category_menu_order"),
]

operations = [
migrations.AddField(
model_name="post",
name="parent",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="children",
to="djpress.post",
),
),
]
25 changes: 25 additions & 0 deletions src/djpress/migrations/0006_alter_post_parent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 5.1.2 on 2024-10-09 06:36

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("djpress", "0005_post_parent"),
]

operations = [
migrations.AlterField(
model_name="post",
name="parent",
field=models.ForeignKey(
blank=True,
limit_choices_to={"post_type": "page"},
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="children",
to="djpress.post",
),
),
]
Loading

0 comments on commit 53da8c1

Please sign in to comment.