Skip to content

Conversation

ewdurbin
Copy link
Member

Allows management of banners displayed across python.org via Django admin.

Screen Shot 2019-04-11 at 10 24 09 AM

Screen Shot 2019-04-11 at 10 24 12 AM

Screen Shot 2019-04-11 at 10 24 25 AM


@register.simple_tag
def render_active_banner(psf_pages_only=True):
if not psf_pages_only:
Copy link
Member

Choose a reason for hiding this comment

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

If I understood this correctly, the following line would cover both if and else statements:

banner = Banner.objects.filter(active=True, psf_pages_only=psf_pages_only).first()

Copy link
Member Author

Choose a reason for hiding this comment

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

little trickier than that, since we accept either value for the PSF pages. so filtering on psf_pages_only makes general banners not show.

banners/admin.py Outdated
class BannerAdmin(admin.ModelAdmin):
list_display = ("title", "active", "psf_pages_only")

admin.site.register(Banner, BannerAdmin)
Copy link
Member

Choose a reason for hiding this comment

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

Style nit: We are trying to use the @admin.site.register() decorator version in new code.

from django.db import migrations, models


class Migration(migrations.Migration):
Copy link
Member

Choose a reason for hiding this comment

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

Do you plan to squash these two migrations when design of the Banner model is finished?

Copy link
Member Author

Choose a reason for hiding this comment

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

aye

{% block content %}
<div class="row download-list-widget">

{% render_active_banner False %}
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Passing psf_pages_only=False would increase readability here.

Copy link
Member Author

Choose a reason for hiding this comment

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

again, will be addressed with excellent suggestion from jaap3

{% block breadcrumbs %}
{% load sitetree %}

{% render_active_banner True %}
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Did Django complained without passing an argument? I don't have a computer to test at the moment, but we might just use {% render_active_banner %} here.

Copy link
Member Author

Choose a reason for hiding this comment

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

with suggestion from jaap3, this isn't necessary. I was just being explicit :)



@register.simple_tag
def render_active_banner(psf_pages_only=True):
Copy link
Contributor

Choose a reason for hiding this comment

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

What about having two template tags render_active_banner and render_active_psf_banner instead of adding a boolean argument? This would also make it clearer what is going on in the template.

Copy link
Member Author

Choose a reason for hiding this comment

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

great suggestion, thank you!

if not psf_pages_only:
banner = Banner.objects.filter(active=True, psf_pages_only=psf_pages_only).first()
else:
banner = Banner.objects.filter(active=True).first()
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to have a custom QuerySet/Manager that provides an active() method (i.e. Banner.objects.active().first())

'title': banner.title,
'link': banner.link,
}
return tmpl.render(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

@ewdurbin ewdurbin merged commit cdb0b8b into master Apr 18, 2019
@ewdurbin ewdurbin deleted the banners branch April 18, 2019 19:08
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.

3 participants