-
Notifications
You must be signed in to change notification settings - Fork 2
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
#155 Integrate Wagtail Routing #395
#155 Integrate Wagtail Routing #395
Conversation
Codecov Report
@@ Coverage Diff @@
## master #395 +/- ##
==========================================
+ Coverage 94.19% 94.24% +0.05%
==========================================
Files 192 192
Lines 6386 6378 -8
Branches 364 361 -3
==========================================
- Hits 6015 6011 -4
+ Misses 303 299 -4
Partials 68 68
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit out of the loop as to what is intended with this change so I just left general feedback and will leave it to @gsidebo to go over the wagtail-specifics since he's been involved more in that.
delete = options["revert"] | ||
site = Site.objects.get(is_default_site=True) | ||
if not site: | ||
print( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print( | |
self.stderr.write( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
print( | ||
"No site setup. Please configure a default site before running this command" | ||
) | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you have this exit with a non-zero exit code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
def get_top_level_wagtail_page(): | ||
""" | ||
The Wagtail CMS (at least in our usage) has one root page at depth 1, and one page at depth 2. All pages that we | ||
create in Wagtail are added as children to the page at depth 2. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this enforced? If this isn't the case in all environments then this migration will fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's technically possible for there to be multiple pages at depth 2, for example if in some environment we have the original "This is your Wagtail site!" page existing alongside the new Home Page. It wouldn't hurt to update this query to fetch all pages at depth 2. If there's just one, return that. If there's more than one, pick the Home Page.
The function name and docstring can also be updated.
-> get_top_level_wagtail_page
get_home_page
docstring: The Wagtail CMS (at least in our usage) has one uneditable root page at depth 1, and a home page as its child at depth 2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than going through pages at depth 1 or 2, I'm changing this to use the Site
model to fish out the configured home page ID. That gets rid of all assumptions.
Not going through the depth 1/2 route because you can in fact have multiple site records as well, so that's also a potential point of failure.
ecommerce/serializers.py
Outdated
@@ -22,6 +22,27 @@ | |||
from mitxpro.serializers import WriteableSerializerMethodField | |||
|
|||
|
|||
def _get_thumbnail_url(page): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't duplicate this method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed, was left over from some fixes earlier, isn't being used anyway. Oversight on my part.
cms/models.py
Outdated
if not self.program_page: | ||
return [] | ||
courses = self.program_page.program.courses.all() | ||
return CoursePage.objects.filter(course_id__in=courses) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure this function can be rewritten as:
return CoursePage.objects.filter(course__program=self.course.program) if self.course.program else []
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
def get_top_level_wagtail_page(): | ||
""" | ||
The Wagtail CMS (at least in our usage) has one root page at depth 1, and one page at depth 2. All pages that we | ||
create in Wagtail are added as children to the page at depth 2. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's technically possible for there to be multiple pages at depth 2, for example if in some environment we have the original "This is your Wagtail site!" page existing alongside the new Home Page. It wouldn't hurt to update this query to fetch all pages at depth 2. If there's just one, return that. If there's more than one, pick the Home Page.
The function name and docstring can also be updated.
-> get_top_level_wagtail_page
get_home_page
docstring: The Wagtail CMS (at least in our usage) has one uneditable root page at depth 1, and a home page as its child at depth 2
cms/models.py
Outdated
@@ -527,6 +566,7 @@ class Meta: | |||
|
|||
def get_context(self, request, *args, **kwargs): | |||
context = super(ProductPage, self).get_context(request) | |||
context.update(**get_js_settings_context(request)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function can be rewritten as:
return {
**super().get_context(request, *args, **kwargs),
**get_js_settings_context(request),
"title": self.title
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
d2371f7
to
0774ab7
Compare
cms/models.py
Outdated
@@ -607,7 +705,55 @@ def program_page(self): | |||
""" | |||
Gets the program page associated with this course, if it exists | |||
""" | |||
return self.course.program.page if self.course and self.course.program else None | |||
return self.course.program.page if self.course.program.page else None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be changed. As written, it will not work for courses with no program. Change to:
return self.course.program.page if self.course.program else None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Pre-Flight checklist
What are the relevant tickets?
Closes #155
What's this PR do?
courses/models_test
tocms/models_test
courses/templates
tocms/templates
serializers
andserializer_tests
to use the new setup (CoursePage/ProgramPage for source of most information)product_page
template for Wagtail to use in order to serve program and course pagesHow should this be manually tested?
Run the migrations, you should end up with a "Courses" page and "Programs" page under the home page, of the types
CourseIndexPage
andProgramIndexPage
respectively. All your courses and programs should have been moved to these index pages by the migration. In the CMS, go to anyCoursePage
orProgramPage
and click on thelive
link. The page should be rendered as expected, with the url pattern for both being/courses/<slug>/
and/programs/<slug>/
respectively.Screenshots (if appropriate)