Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add section page #260

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions apps/core/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from wagtail.core.models import Locale, Page, Site

from apps.core.models import ContentPage, HomePage
from apps.core.models.content import SectionPage

fake = Faker()

Expand Down Expand Up @@ -75,3 +76,8 @@ def first_published_at(self):
@factory.lazy_attribute
def parent(self):
return HomePageFactory()


class SectionPageFactory(ContentPageFactory):
class Meta:
model = SectionPage
4 changes: 2 additions & 2 deletions apps/core/management/commands/buildfixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from wagtail.images import get_image_model
from wagtail.models import Collection, Locale, Page

from apps.core.factories import ContentPageFactory, HomePageFactory
from apps.core.factories import ContentPageFactory, HomePageFactory, SectionPageFactory

fake = Faker()

Expand Down Expand Up @@ -94,7 +94,7 @@ def create_content_pages(self):
],
],
]:
page = ContentPageFactory(
page = SectionPageFactory(
parent=self.home,
title=title,
slug=slugify(title),
Expand Down
34 changes: 34 additions & 0 deletions apps/core/migrations/0010_sectionpage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 4.1.2 on 2022-11-09 15:19

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


class Migration(migrations.Migration):

dependencies = [
("core", "0009_default_homepage_introduction"),
]

operations = [
migrations.CreateModel(
name="SectionPage",
fields=[
(
"contentpage_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="core.contentpage",
),
),
],
options={
"abstract": False,
},
bases=("core.contentpage",),
),
]
10 changes: 8 additions & 2 deletions apps/core/models/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_context(self, request, *args, **kwargs):
)
return context

def serve(self, request):
def serve(self, request, *args, **kwargs):
if request.method == "POST":
data = json.loads(request.body)
if "pk" in data:
Expand All @@ -69,8 +69,14 @@ def serve(self, request):

return HttpResponse(json.dumps(data))
else:
return super().serve(request)
return super().serve(request, *args, **kwargs)

def save_revision(self, *args, **kwargs):
self.table_of_contents = create_table_of_contents(self.body)
return super().save_revision(*args, **kwargs)


class SectionPage(ContentPage):
parent_page_types = ["core.HomePage"]

# Distinct section page features here.
2 changes: 1 addition & 1 deletion apps/core/models/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class HomePage(Page):
subpage_types = ["core.ContentPage"]
subpage_types = ["core.SectionPage", "core.ContentPage"]
max_count = 1
introduction = models.TextField(blank=True)

Expand Down
1 change: 1 addition & 0 deletions apps/core/templates/core/section_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends "core/content_page.html" %}
3 changes: 2 additions & 1 deletion apps/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ class Meta:
fields = ["id", "title", "search_description", "full_url", "parent_section"]

def get_parent_section(self, page):
# We might update this to search for the first SectionPage
ancestors = page.get_ancestors()
if len(ancestors) >= 3:
return ancestors[2].title
else:
return _("Home")
return _("Home") # Shouldn't this be None? OR a dash?


@api_view(["GET"])
Expand Down