Skip to content

Commit cdb0b8b

Browse files
authored
implement naive self-service banners for python.org (#1413)
* implement naive self-service banners for python.org * make better help_texts for banners django admin * address feedback from review, thank you @berkerpeksag and @jaap3! * blackify banners app
1 parent cf5c53c commit cdb0b8b

File tree

14 files changed

+134
-1
lines changed

14 files changed

+134
-1
lines changed

banners/__init__.py

Whitespace-only changes.

banners/admin.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django.contrib import admin
2+
3+
from banners.models import Banner
4+
5+
6+
@admin.register(Banner)
7+
class BannerAdmin(admin.ModelAdmin):
8+
list_display = ("title", "active", "psf_pages_only")

banners/migrations/0001_initial.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Generated by Django 2.0.9 on 2019-04-18 18:43
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
initial = True
9+
10+
dependencies = []
11+
12+
operations = [
13+
migrations.CreateModel(
14+
name="Banner",
15+
fields=[
16+
(
17+
"id",
18+
models.AutoField(
19+
auto_created=True,
20+
primary_key=True,
21+
serialize=False,
22+
verbose_name="ID",
23+
),
24+
),
25+
(
26+
"title",
27+
models.CharField(
28+
help_text="Text to display in the banner's button",
29+
max_length=1024,
30+
),
31+
),
32+
(
33+
"message",
34+
models.CharField(
35+
help_text="Message to display in the banner", max_length=2048
36+
),
37+
),
38+
(
39+
"link",
40+
models.CharField(
41+
help_text="Link the button will go to", max_length=1024
42+
),
43+
),
44+
(
45+
"active",
46+
models.BooleanField(
47+
default=False, help_text="Make the banner active on the site"
48+
),
49+
),
50+
(
51+
"psf_pages_only",
52+
models.BooleanField(
53+
default=True, help_text="Display the banner on /psf pages only"
54+
),
55+
),
56+
],
57+
)
58+
]

banners/migrations/__init__.py

Whitespace-only changes.

banners/models.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from django.db import models
2+
3+
4+
class Banner(models.Model):
5+
6+
title = models.CharField(
7+
max_length=1024, help_text="Text to display in the banner's button"
8+
)
9+
message = models.CharField(
10+
max_length=2048, help_text="Message to display in the banner"
11+
)
12+
link = models.CharField(max_length=1024, help_text="Link the button will go to")
13+
active = models.BooleanField(
14+
null=False, default=False, help_text="Make the banner active on the site"
15+
)
16+
psf_pages_only = models.BooleanField(
17+
null=False, default=True, help_text="Display the banner on /psf pages only"
18+
)

banners/templatetags/__init__.py

Whitespace-only changes.

banners/templatetags/banners.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from django import template
2+
from django.template.loader import render_to_string
3+
4+
from banners.models import Banner
5+
6+
register = template.Library()
7+
8+
9+
def _render_banner(banner=None):
10+
if banner is not None:
11+
return render_to_string(
12+
"banners/banner.html",
13+
{"message": banner.message, "title": banner.title, "link": banner.link},
14+
)
15+
16+
return ""
17+
18+
19+
@register.simple_tag
20+
def render_active_banner():
21+
banner = Banner.objects.filter(active=True, psf_pages_only=False).first()
22+
return _render_banner(banner=banner)
23+
24+
25+
@register.simple_tag
26+
def render_active_psf_banner():
27+
banner = Banner.objects.filter(active=True).first()
28+
return _render_banner(banner=banner)

pydotorg/settings/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@
167167
'codesamples',
168168
'work_groups',
169169
'nominations',
170+
'banners',
170171

171172
'allauth',
172173
'allauth.account',

templates/banners/banner.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div class="notification-bar notification-bar--survey" style="background-color: #ffdf76; color: #664e04; border-color: #004d7a; text-align: center; background-color: #004d7a; color: #fff; padding: 10px; margin: .5em; position: relative; width: 95%; background-color: #ffdf76; color: #664e04; border-color: #004d7a; border-radius: 1em;">
2+
<span class="notification-bar__icon">
3+
<i class="fa fa-chart-line" aria-hidden="true"></i>
4+
</span>
5+
<span class="notification-bar__message">{{ message }} &nbsp;&nbsp;<a class="button button--dark button--small button--primary" style="color: #606060; border-color: #006dad; background-color: #006dad;" href="{{ link }}" target="_blank" rel="noopener">{{ title }}</a>
6+
</span>
7+
</div>

templates/downloads/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{% extends "base.html" %}
22
{% load boxes %}
3+
{% load banners %}
34

45
{% block page_title %}Download Python | {{ SITE_INFO.site_name }}{% endblock %}
56
{% block og_title %}Download Python{% endblock %}
@@ -38,6 +39,8 @@ <h1 class="call-to-action">Download the latest version of Python</h1>
3839
{% block content %}
3940
<div class="row download-list-widget">
4041

42+
{% render_active_banner %}
43+
4144
<h2 class="widget-title">Looking for a specific release?</h2>
4245
<p class="success-quote">Python releases by version number:</p>
4346

0 commit comments

Comments
 (0)