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

ensure canonical urls are consistent (with no slash) #1605

Merged
merged 5 commits into from
Jan 10, 2025
Merged
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
17 changes: 17 additions & 0 deletions donations/migrations/0009_alter_thankyounote_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 5.1.1 on 2025-01-08 23:01

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("donations", "0008_thankyounote_source"),
]

operations = [
migrations.AlterModelOptions(
name="thankyounote",
options={"verbose_name": "Thank You Note", "verbose_name_plural": "Thank You Notes"},
),
]
13 changes: 13 additions & 0 deletions donations/migrations/0010_merge_20250110_1518.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Generated by Django 5.1.1 on 2025-01-10 21:18

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("donations", "0009_alter_thankyounote_options"),
("donations", "0009_thankyounote_salesforce_id"),
]

operations = []
9 changes: 9 additions & 0 deletions donations/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db import models
from django.core.exceptions import ValidationError

COLOR_SCHEME_CHOICES = (
('red', 'Red'),
Expand All @@ -25,6 +26,14 @@
salesforce_id = models.CharField(max_length=255, default="", blank=True, help_text="Not null if uploaded to Salesforce")


def __str__(self):
return f'{self.first_name} {self.last_name}'

Check warning on line 30 in donations/models.py

View check run for this annotation

Codecov / codecov/patch

donations/models.py#L30

Added line #L30 was not covered by tests

class Meta:
verbose_name = 'Thank You Note'
verbose_name_plural = 'Thank You Notes'


class DonationPopup(models.Model):
download_image = models.ImageField(null=True, blank=True)
download_ready = models.TextField(default="", blank=True)
Expand Down
2 changes: 1 addition & 1 deletion news/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@
return None

site_id, site_root_url, page_url_relative_to_site_root = url_parts
return (site_id, site_root_url, '/press/{}'.format(self.slug))
return site_id, site_root_url, '/press/{}'.format(self.slug)

Check warning on line 665 in news/models.py

View check run for this annotation

Codecov / codecov/patch

news/models.py#L665

Added line #L665 was not covered by tests

search_fields = Page.search_fields + [
index.SearchField('body'),
Expand Down
1 change: 1 addition & 0 deletions oxmenus/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from wagtail.admin.panels import FieldPanel
from wagtail.api import APIField


class MenuItemBlock(blocks.StructBlock):
label = blocks.CharBlock(max_length=255)
partial_url = blocks.CharBlock(max_length=255)
Expand Down
2 changes: 1 addition & 1 deletion oxmenus/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
from .serializers import OXMenusSerializer


class OXMenusViewSet(viewsets.ModelViewSet):
class OXMenusViewSet(viewsets.ReadOnlyModelViewSet):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am hoping this solves our occasional mystery menu items

queryset = Menus.objects.all()
serializer_class = OXMenusSerializer
17 changes: 17 additions & 0 deletions pages/migrations/0153_alter_homepage_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 5.1.1 on 2025-01-08 23:01

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("pages", "0152_alter_rootpage_body_alter_rootpage_layout"),
]

operations = [
migrations.AlterModelOptions(
name="homepage",
options={"verbose_name": "Home Page"},
),
]
33 changes: 8 additions & 25 deletions pages/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from wagtail.models import Orderable, Page
from wagtail.api import APIField
from wagtail.models import Site
from rest_framework.fields import Field

from api.models import FeatureFlag
from openstax.functions import build_image_url, build_document_url
Expand Down Expand Up @@ -224,7 +223,7 @@
# note that we ignore the slug and hardcode this url to / for the root page
site_id, site_root_url, page_url_relative_to_site_root = url_parts

return (site_id, site_root_url, '/')
return site_id, site_root_url, ''

Check warning on line 226 in pages/models.py

View check run for this annotation

Codecov / codecov/patch

pages/models.py#L226

Added line #L226 was not covered by tests

def serve_preview(self, request, mode_name):
site_id, site_root, relative_page_url = self.get_url_parts(request)
Expand All @@ -250,7 +249,7 @@
return None

site_id, site_root_url, page_url_relative_to_site_root = url_parts
return (site_id, site_root_url, '/{}'.format(self.slug))
return site_id, site_root_url, '/{}'.format(self.slug)

Check warning on line 252 in pages/models.py

View check run for this annotation

Codecov / codecov/patch

pages/models.py#L252

Added line #L252 was not covered by tests


#TODO: start removing these pages as we move to the above structure for all pages.
Expand Down Expand Up @@ -345,7 +344,6 @@
]

template = 'page.html'

parent_page_types = ['pages.HomePage']
max_count = 1

Expand Down Expand Up @@ -716,10 +714,7 @@
site_id, root_url, page_path = url_parts

# return '/' in place of the real page path
return (site_id, root_url, '/')

class Meta:
verbose_name = "homepage"
return site_id, root_url, '/'

Check warning on line 717 in pages/models.py

View check run for this annotation

Codecov / codecov/patch

pages/models.py#L717

Added line #L717 was not covered by tests


class K12MainPage(Page):
Expand Down Expand Up @@ -863,8 +858,6 @@
APIField('promote_image')
]

max_count = 1

class Meta:
verbose_name = "K12 Main Page"

Expand Down Expand Up @@ -902,15 +895,11 @@
FieldPanel('promote_image')
]

max_count = 1
template = 'page.html'
parent_page_types = ['pages.HomePage']
subpage_types = ['pages.K12Subject']

max_count = 1

class Meta:
verbose_name = "K12 Main Page"


class ContactUs(Page):
tagline = models.CharField(max_length=255)
Expand Down Expand Up @@ -982,7 +971,7 @@

# note that we ignore the parents, all general pages are /{slug}
site_id, site_root_url, page_url_relative_to_site_root = url_parts
return (site_id, site_root_url, '/{}'.format(self.slug))
return site_id, site_root_url, '/{}'.format(self.slug)

Check warning on line 974 in pages/models.py

View check run for this annotation

Codecov / codecov/patch

pages/models.py#L974

Added line #L974 was not covered by tests

promote_image = models.ForeignKey(
'wagtailimages.Image',
Expand Down Expand Up @@ -1557,7 +1546,6 @@
]

template = 'page.html'

parent_page_types = ['pages.HomePage']
max_count = 1

Expand Down Expand Up @@ -1610,7 +1598,6 @@
]

template = 'page.html'

parent_page_types = ['pages.HomePage']
max_count = 1

Expand Down Expand Up @@ -1852,7 +1839,6 @@
]

template = 'page.html'

parent_page_types = ['pages.HomePage']
max_count = 1

Expand Down Expand Up @@ -1892,7 +1878,6 @@
]

template = 'page.html'

parent_page_types = ['pages.HomePage']
max_count = 1

Expand Down Expand Up @@ -2821,7 +2806,7 @@

# note that we ignore the slug and hardcode this url to /subjects
site_id, site_root_url, page_url_relative_to_site_root = url_parts
return (site_id, site_root_url, '/subjects')
return site_id, site_root_url, '/subjects'

Check warning on line 2809 in pages/models.py

View check run for this annotation

Codecov / codecov/patch

pages/models.py#L2809

Added line #L2809 was not covered by tests

api_fields = [
APIField('heading'),
Expand Down Expand Up @@ -2943,7 +2928,7 @@

# note that we ignore the slug and hardcode this url to /subjects
site_id, site_root_url, page_url_relative_to_site_root = url_parts
return (site_id, site_root_url, '/subjects/{}'.format(self.slug[0:-6]))
return site_id, site_root_url, '/subjects/{}'.format(self.slug[0:-6])

Check warning on line 2931 in pages/models.py

View check run for this annotation

Codecov / codecov/patch

pages/models.py#L2931

Added line #L2931 was not covered by tests

@property
def selected_subject(self):
Expand Down Expand Up @@ -3098,7 +3083,6 @@
]

template = 'page.html'

parent_page_types = ['pages.HomePage']
max_count = 1

Expand Down Expand Up @@ -3264,7 +3248,7 @@
return None

site_id, site_root_url, page_url_relative_to_site_root = url_parts
return (site_id, site_root_url, '/k12/{}'.format(self.slug[4:]))
return site_id, site_root_url, '/k12/{}'.format(self.slug[4:])

Check warning on line 3251 in pages/models.py

View check run for this annotation

Codecov / codecov/patch

pages/models.py#L3251

Added line #L3251 was not covered by tests

api_fields = [
APIField('subheader'),
Expand Down Expand Up @@ -3379,7 +3363,6 @@
]

template = 'page.html'

parent_page_types = ['pages.HomePage']


Expand Down
17 changes: 17 additions & 0 deletions pages/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import datetime
import json
import unittest
from unittest.mock import patch

from django.test import TestCase, Client
from wagtail.test.utils import WagtailTestUtils, WagtailPageTestCase
Expand All @@ -9,6 +11,21 @@
from shared.test_utilities import assertPathDoesNotRedirectToTrailingSlash, mock_user_login
from http import cookies

class TestRootPage(unittest.TestCase):

@patch('pages.models.RootPage.get_url_parts')
def get_url_parts_returns_correct_values(self, mock_get_url_parts):
mock_get_url_parts.return_value = (1, 'http://openstax.org', 'some/path')
root_page = page_models.RootPage()
result = root_page.get_url_parts()
self.assertEqual(result, (1, 'http://openstax.org', ''))

@patch('pages.models.RootPage.get_url_parts')
def get_url_parts_returns_none_when_no_url_parts(self, mock_get_url_parts):
mock_get_url_parts.return_value = None
root_page = page_models.RootPage()
result = root_page.get_url_parts()
self.assertIsNone(result)

class HomePageTests(WagtailPageTestCase):

Expand Down
1 change: 1 addition & 0 deletions salesforce/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class ResourceDownloadAdmin(admin.ModelAdmin):
list_display = ('id', 'created', 'last_access', 'resource_name', 'book', 'book_format', 'account_uuid')
list_filter = ('created', 'book')


admin.site.register(SalesforceSettings, SalesforceSettingsAdmin)
admin.site.register(SalesforceForms, SalesforceFormsAdmin)
admin.site.register(School, SchoolAdmin)
Expand Down
Loading