Skip to content

Commit

Permalink
remove unused snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahframe committed Jul 7, 2024
1 parent f773118 commit 6ca6414
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 88 deletions.
2 changes: 1 addition & 1 deletion cdhweb/blog/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

def make_blog_link_page(homepage):
"""Create a test blog link page underneath the homepage."""
link = BlogLinkPageArchived(title="updates", link_url="updates")
link = BlogLinkPageArchived(title="updates")
homepage.add_child(instance=link)
homepage.save()
return link
Expand Down
8 changes: 0 additions & 8 deletions cdhweb/events/tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,3 @@ def test_event_location(self, client, workshop):
"""event archive page should list non-virtal event address on cards"""
response = client.get(reverse("events:upcoming"))
assertContains(response, workshop.location.address)

def test_page_intro(self, client, events_link_page):
"""event archive page should display an intro snippet if set"""
# create a snippet for the upcoming events page
PageIntro.objects.create(page=events_link_page, paragraph="<i>test content</i>")
# visit and check that it renders
response = client.get(reverse("events:upcoming"))
assertContains(response, "<i>test content</i>")
17 changes: 0 additions & 17 deletions cdhweb/pages/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
from cdhweb.pages.forms import SiteSearchForm
from cdhweb.pages.models import PageIntro


def page_intro(request):
"""Template context processor: if there is a PageIntro snippet
for this page, add it to the context for display."""
# wagtail stores link url without leading and trailing slashes,
# but requests to django view urls include them; strip them off to match

# NOTE: page intro modification time is NOT taken into account
# when generating Last-Modified headers and returning 304 Not Modified
page_intro = PageIntro.objects.filter(
page__link_url=request.path.strip("/")
).first()
if page_intro:
return {"page_intro": page_intro}
return {}


def site_search(request):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 5.0.5 on 2024-07-07 23:49

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("cdhpages", "0055_alter_contentpage_attachments_and_more"),
]

operations = [
migrations.RemoveField(
model_name="linkpage",
name="extra_classes",
),
migrations.RemoveField(
model_name="linkpage",
name="link_page",
),
migrations.RemoveField(
model_name="linkpage",
name="link_url",
),
migrations.RemoveField(
model_name="linkpage",
name="url_append",
),
]
16 changes: 16 additions & 0 deletions cdhweb/pages/migrations/0057_delete_pageintro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 5.0.5 on 2024-07-07 23:56

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('cdhpages', '0056_remove_linkpage_extra_classes_and_more'),
]

operations = [
migrations.DeleteModel(
name='PageIntro',
),
]
33 changes: 6 additions & 27 deletions cdhweb/pages/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
from wagtail.snippets.blocks import SnippetChooserBlock
from wagtail.snippets.models import register_snippet
from wagtailcodeblock.blocks import CodeBlock
from wagtailmenus.models import AbstractLinkPage
from wagtailmenus.panels import linkpage_tab

from cdhweb.pages import snippets # needed for import order

Expand Down Expand Up @@ -237,19 +235,18 @@ def get_plaintext_description(self):
return striptags(self.get_description())


class LinkPage(AbstractLinkPage):
class LinkPage(Page):
"""Link page for controlling appearance in menus of non-Page content."""

# NOTE these pages can have slugs, but the slug isn't editable in the admin
# by default. We override the editing interface to introduce a "promote"
# panel as with other Page models containing the form field for the slug.
# see: https://github.com/rkhleics/wagtailmenus/blob/master/wagtailmenus/panels.py#L79-L93
edit_handler = TabbedInterface(
[
linkpage_tab,
ObjectList((MultiFieldPanel((FieldPanel("slug"),)),), heading="Promote"),
]
)
# edit_handler = TabbedInterface(
# [
# ObjectList((MultiFieldPanel((FieldPanel("slug"),)),), heading="Promote"),
# ]
# )
search_fields = Page.search_fields

is_creatable = False
Expand Down Expand Up @@ -436,24 +433,6 @@ def get_context(self, request):
return context


@register_snippet
class PageIntro(models.Model):
"""Snippet for optional page intro text on for pages generated from
django views not managed by wagtail"""

page = models.OneToOneField(LinkPage, on_delete=models.CASCADE)
#: intro text
paragraph = RichTextField(features=PARAGRAPH_FEATURES)

panels = [
FieldPanel("page"),
FieldPanel("paragraph"),
]

def __str__(self):
return self.page.title


class DisplayUrlMixin(models.Model):
"""Mixin that provides a single required URL field and a display method."""

Expand Down
16 changes: 0 additions & 16 deletions cdhweb/pages/tests/test_context_processors.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
import pytest
from wagtail.models import Page

from cdhweb.pages.context_processors import page_intro
from cdhweb.pages.models import LinkPage, PageIntro


@pytest.mark.django_db
def test_page_intro(rf):
root = Page.objects.get(title="Root")
link_page = LinkPage(title="Students", link_url="people/students")
root.add_child(instance=link_page)
intro = PageIntro.objects.create(
page=link_page, paragraph="<p>We have great students</p>"
)

# should find a page intro for students
assert page_intro(rf.get("/people/students/")) == {"page_intro": intro}
# but not not for staff
assert page_intro(rf.get("/people/staff/")) == {}
2 changes: 1 addition & 1 deletion cdhweb/people/tests/test_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_child_pages(self):
class TestPageIntro:
def test_str(self):
root = Page.objects.get(title="Root")
link_page = LinkPage(title="Students", link_url="people/students")
link_page = LinkPage(title="Students")
root.add_child(instance=link_page)
intro = PageIntro.objects.create(
page=link_page, paragraph="<p>We have great students</p>"
Expand Down
16 changes: 0 additions & 16 deletions cdhweb/projects/tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,6 @@ def test_page_titles(self, client, projects):
response = client.get(reverse("projects:working-groups"))
assertNotContains(response, "<h2>Past Projects</h2>")

def test_page_intro(self, client, projects_landing_page):
"""project list pages should display an intro snippet if set"""
# create link page for project list
sponsored_projects = LinkPage(
title="Sponsored Projects", link_url="projects/sponsored"
)
projects_landing_page.add_child(instance=sponsored_projects)
# create a snippet for the sponsored projects page
PageIntro.objects.create(
page=sponsored_projects, paragraph="<i>test content</i>"
)

# visit and check that it renders
response = client.get(reverse("projects:sponsored"))
assertContains(response, "<i>test content</i>")

def test_project_card(self, client, projects):
"""project list pages should display cards for each project"""
# one project card for each staff/postdoc project
Expand Down
2 changes: 0 additions & 2 deletions cdhweb/settings/components/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@
# "wagtailmenus.context_processors.wagtailmenus",
"cdhweb.context_extras",
"cdhweb.context_processors.template_settings",
"cdhweb.pages.context_processors.page_intro",
"cdhweb.pages.context_processors.site_search",
"cdhweb.context_processors.show_test_warning",
],
Expand Down Expand Up @@ -188,7 +187,6 @@
"wagtail.admin",
"wagtail_modeladmin",
"wagtail",
"wagtailmenus",
"wagtailautocomplete",
"modelcluster",
"taggit",
Expand Down

0 comments on commit 6ca6414

Please sign in to comment.