Repository navigation
Link to new Python Insider feed #3204
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
Merged
+116
−4
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| """Point the Python Insider feed at https://blog.python.org/rss.xml. | ||
|
|
||
| Python Insider moved from Blogger to GitHub Pages. The legacy Blogger | ||
| feed path ``feeds/posts/default?alt=rss`` is still served as a | ||
| compatibility copy, but it has no file extension so GitHub Pages sends | ||
| it as ``application/octet-stream``, which makes Safari and other | ||
| browsers download it instead of opening a feed reader. The blog's | ||
| canonical feed is ``/rss.xml``, served as ``application/xml``. | ||
|
|
||
| ``update_blog_supernav`` looks up the Feed row by matching | ||
| ``settings.PYTHON_BLOG_FEED_URL`` exactly, so the stored Feed row has to | ||
| change together with the setting. The ``blogs-subscriptions`` sidebar | ||
| box links to the feed too, so rewrite both its raw and rendered content. | ||
| """ | ||
|
|
||
| from django.db import migrations | ||
| from django.db.models import Value | ||
| from django.db.models.functions import Replace | ||
|
|
||
| OLD_FEED_URL = "https://blog.python.org/feeds/posts/default?alt=rss" | ||
| NEW_FEED_URL = "https://blog.python.org/rss.xml" | ||
|
|
||
|
|
||
| def _replace_feed_url(apps, old, new): | ||
| Feed = apps.get_model("blogs", "Feed") | ||
| Feed.objects.filter(feed_url=old).update(feed_url=new) | ||
|
|
||
| Box = apps.get_model("boxes", "Box") | ||
| Box.objects.filter(label="blogs-subscriptions", content__contains=old).update( | ||
| content=Replace("content", Value(old), Value(new)), | ||
| _content_rendered=Replace("_content_rendered", Value(old), Value(new)), | ||
| ) | ||
|
|
||
|
|
||
| def forwards(apps, schema_editor): | ||
| _replace_feed_url(apps, OLD_FEED_URL, NEW_FEED_URL) | ||
|
|
||
|
|
||
| def backwards(apps, schema_editor): | ||
| _replace_feed_url(apps, NEW_FEED_URL, OLD_FEED_URL) | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("blogs", "0004_normalize_blogentry_urls"), | ||
| ("boxes", "0004_alter_box_creator_alter_box_last_modified_by"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RunPython(forwards, backwards), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| """Tests for blogs data migrations.""" | ||
|
|
||
| from django.db import connection | ||
| from django.db.migrations.executor import MigrationExecutor | ||
| from django.test import TransactionTestCase | ||
|
|
||
| OLD_FEED_URL = "https://blog.python.org/feeds/posts/default?alt=rss" | ||
| NEW_FEED_URL = "https://blog.python.org/rss.xml" | ||
| BEFORE = [ | ||
| ("blogs", "0004_normalize_blogentry_urls"), | ||
| ("boxes", "0004_alter_box_creator_alter_box_last_modified_by"), | ||
| ] | ||
| AFTER = [("blogs", "0005_blog_feed_url_rss_xml")] | ||
|
|
||
|
|
||
| class BlogFeedUrlRssXmlMigrationTests(TransactionTestCase): | ||
| """The 0005 migration repoints the Feed row and sidebar box at rss.xml.""" | ||
|
|
||
| def setUp(self): | ||
| self.executor = MigrationExecutor(connection) | ||
| self.executor.migrate(BEFORE) | ||
| apps = self.executor.loader.project_state(BEFORE).apps | ||
| self.Feed = apps.get_model("blogs", "Feed") | ||
| self.Box = apps.get_model("boxes", "Box") | ||
|
|
||
| def tearDown(self): | ||
| self.executor.loader.build_graph() | ||
| self.executor.migrate(self.executor.loader.graph.leaf_nodes()) | ||
|
|
||
| def _migrate(self, targets): | ||
| self.executor.loader.build_graph() | ||
| self.executor.migrate(targets) | ||
| return self.executor.loader.project_state(targets).apps | ||
|
|
||
| def test_forwards_rewrites_feed_and_box(self): | ||
| self.Feed.objects.create(name="Python Insider", website_url="https://blog.python.org", feed_url=OLD_FEED_URL) | ||
| self.Feed.objects.create(name="Other", website_url="https://example.org", feed_url="https://example.org/feed") | ||
| self.Box.objects.create( | ||
| label="blogs-subscriptions", | ||
| content=f'<a href="{OLD_FEED_URL}">RSS</a>', | ||
| content_markup_type="html", | ||
| ) | ||
|
|
||
| apps = self._migrate(AFTER) | ||
|
|
||
| Feed = apps.get_model("blogs", "Feed") | ||
| self.assertEqual(Feed.objects.get(name="Python Insider").feed_url, NEW_FEED_URL) | ||
| self.assertEqual(Feed.objects.get(name="Other").feed_url, "https://example.org/feed") | ||
| box = apps.get_model("boxes", "Box").objects.get(label="blogs-subscriptions") | ||
| self.assertEqual(box.content.raw, f'<a href="{NEW_FEED_URL}">RSS</a>') | ||
| self.assertIn(NEW_FEED_URL, box.content.rendered) | ||
| self.assertNotIn(OLD_FEED_URL, box.content.rendered) | ||
|
|
||
| def test_backwards_restores_old_url(self): | ||
| self.Feed.objects.create(name="Python Insider", website_url="https://blog.python.org", feed_url=OLD_FEED_URL) | ||
| self._migrate(AFTER) | ||
|
|
||
| apps = self._migrate(BEFORE) | ||
|
|
||
| Feed = apps.get_model("blogs", "Feed") | ||
| self.assertEqual(Feed.objects.get(name="Python Insider").feed_url, OLD_FEED_URL) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.