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

Cleanup blogs app #1336

Merged
merged 11 commits into from Apr 19, 2019
Merged

Cleanup blogs app #1336

merged 11 commits into from Apr 19, 2019

Conversation

jaap3
Copy link
Contributor

@jaap3 jaap3 commented Sep 25, 2018

I might have gotten slightly carried away with cleaning this up, so feel free to reject this wholesale or ask me to create separate PRs for the things that are actually OK.

What I did:

  • Removed seemingly unused Contributor and Translation models (and related admin classes)
  • Used admin.register decorator to register the remaining admin classes
  • Add a "initial_data" factory for the Python Insider feed
  • Simplified the update_blogs management commands (It was almost possible to use update_or_create, but just not quite)
  • Made update_blog_supernav more robust (I'm not sure if that box is actually used though)
  • Strip tags in blog_supernav because I saw the "email this" etc. links inserted by feedburner in the summary field
  • Switch to https for the blog urls
  • Fix/tweak the test_feed_list test

blogs/management/commands/update_blogs.py Outdated Show resolved Hide resolved
'content': rendered_box,
'content_markup_type': 'html',
}
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change makes it not rely on a hardcoded primary key and it doesn't crash when the feed doesn't exist or there are no BlogEntries at all. Which will happen on a "fresh" installation.

However, I'm not sure if the 'supernav-python-blog' is actually used anymore. I don't see it on the live site. So maybe the entire supernav stuff can be removed?

Copy link
Member

Choose a reason for hiding this comment

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

'supernav-python-blog' is used in static/js/script.js.

Your rewrite is much better than the original code.

@@ -33,9 +29,6 @@ def test_get_latest_entries(self):
entries[0].pub_date.isoformat(),
'2013-03-04T15:00:00+00:00'
)
b = Box.objects.get(label='supernav-python-blog')
rendered_box = _render_blog_supernav(BlogEntry.objects.latest())
self.assertEqual(b.content.raw, rendered_box)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed this because it didn't test much and relied on a side effect of running the update_blogs and management command and the previously hardcoded primary key in the update_blog_supernav function. All while claiming to be a test for a template tag.

If updating the supernav is still required I can add proper tests.

Copy link
Member

Choose a reason for hiding this comment

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

I think having more tests wouldn't hurt :) But it can be done in a separate PR.

@@ -61,14 +54,14 @@ def test_feed_list(self):
summary='',
pub_date=now(),
url='path/to/foo',
feed=f1
feed=f2
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The second feed never got a blog entry, so this test was only testing that items from f1 were returned. It seems to me the intention was to test that entries of both feeds are returned.

@@ -2,6 +2,6 @@
<p class="date-posted"><small>{{ entry.pub_date|date:"l, F j, Y" }}</small></p>
<h4>{{ entry.title }}</h4>
<p class="excerpt">
<small>{{ entry.summary|truncatewords_html:50|safe }}<a class="readmore" href="{{ entry.url }}">Read more</a></small>
<small>{{ entry.summary|truncatewords_html:50|striptags|safe }}<a class="readmore" href="{{ entry.url }}">Read more</a></small>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was a serious potential for xss here, locally I could see the images FeedBurner inserts to share a blogpost.

blogs/management/commands/update_blogs.py Outdated Show resolved Hide resolved
blogs/models.py Show resolved Hide resolved
'content': rendered_box,
'content_markup_type': 'html',
}
)
Copy link
Member

Choose a reason for hiding this comment

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

'supernav-python-blog' is used in static/js/script.js.

Your rewrite is much better than the original code.

@@ -33,9 +29,6 @@ def test_get_latest_entries(self):
entries[0].pub_date.isoformat(),
'2013-03-04T15:00:00+00:00'
)
b = Box.objects.get(label='supernav-python-blog')
rendered_box = _render_blog_supernav(BlogEntry.objects.latest())
self.assertEqual(b.content.raw, rendered_box)
Copy link
Member

Choose a reason for hiding this comment

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

I think having more tests wouldn't hurt :) But it can be done in a separate PR.

blogs/parser.py Outdated Show resolved Hide resolved
blogs/management/commands/update_blogs.py Outdated Show resolved Hide resolved
blogs/factories.py Outdated Show resolved Hide resolved
jaap3 added 10 commits April 13, 2019 20:41
It's almost possible to just use update_or_create, but not quite
because of the `pub_date` check.
It now handles the cases when there is no Feed, the desired feed has an id other than 1 and when there are no blog entries at all.

Before this change this function would raise a
`BlogEntry.DoesNotExist` exception.
@berkerpeksag berkerpeksag merged commit f1747e7 into python:master Apr 19, 2019
@berkerpeksag
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants