diff --git a/banners/__init__.py b/banners/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/banners/admin.py b/banners/admin.py new file mode 100644 index 000000000..cfb0e1073 --- /dev/null +++ b/banners/admin.py @@ -0,0 +1,8 @@ +from django.contrib import admin + +from banners.models import Banner + + +@admin.register(Banner) +class BannerAdmin(admin.ModelAdmin): + list_display = ("title", "active", "psf_pages_only") diff --git a/banners/migrations/0001_initial.py b/banners/migrations/0001_initial.py new file mode 100644 index 000000000..a50adb59f --- /dev/null +++ b/banners/migrations/0001_initial.py @@ -0,0 +1,58 @@ +# Generated by Django 2.0.9 on 2019-04-18 18:43 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [] + + operations = [ + migrations.CreateModel( + name="Banner", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "title", + models.CharField( + help_text="Text to display in the banner's button", + max_length=1024, + ), + ), + ( + "message", + models.CharField( + help_text="Message to display in the banner", max_length=2048 + ), + ), + ( + "link", + models.CharField( + help_text="Link the button will go to", max_length=1024 + ), + ), + ( + "active", + models.BooleanField( + default=False, help_text="Make the banner active on the site" + ), + ), + ( + "psf_pages_only", + models.BooleanField( + default=True, help_text="Display the banner on /psf pages only" + ), + ), + ], + ) + ] diff --git a/banners/migrations/__init__.py b/banners/migrations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/banners/models.py b/banners/models.py new file mode 100644 index 000000000..87797573a --- /dev/null +++ b/banners/models.py @@ -0,0 +1,18 @@ +from django.db import models + + +class Banner(models.Model): + + title = models.CharField( + max_length=1024, help_text="Text to display in the banner's button" + ) + message = models.CharField( + max_length=2048, help_text="Message to display in the banner" + ) + link = models.CharField(max_length=1024, help_text="Link the button will go to") + active = models.BooleanField( + null=False, default=False, help_text="Make the banner active on the site" + ) + psf_pages_only = models.BooleanField( + null=False, default=True, help_text="Display the banner on /psf pages only" + ) diff --git a/banners/templatetags/__init__.py b/banners/templatetags/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/banners/templatetags/banners.py b/banners/templatetags/banners.py new file mode 100644 index 000000000..24c62b5e8 --- /dev/null +++ b/banners/templatetags/banners.py @@ -0,0 +1,28 @@ +from django import template +from django.template.loader import render_to_string + +from banners.models import Banner + +register = template.Library() + + +def _render_banner(banner=None): + if banner is not None: + return render_to_string( + "banners/banner.html", + {"message": banner.message, "title": banner.title, "link": banner.link}, + ) + + return "" + + +@register.simple_tag +def render_active_banner(): + banner = Banner.objects.filter(active=True, psf_pages_only=False).first() + return _render_banner(banner=banner) + + +@register.simple_tag +def render_active_psf_banner(): + banner = Banner.objects.filter(active=True).first() + return _render_banner(banner=banner) diff --git a/pydotorg/settings/base.py b/pydotorg/settings/base.py index 6d0bb2d1e..7311c20c4 100644 --- a/pydotorg/settings/base.py +++ b/pydotorg/settings/base.py @@ -167,6 +167,7 @@ 'codesamples', 'work_groups', 'nominations', + 'banners', 'allauth', 'allauth.account', diff --git a/templates/banners/banner.html b/templates/banners/banner.html new file mode 100644 index 000000000..ecc425dc6 --- /dev/null +++ b/templates/banners/banner.html @@ -0,0 +1,7 @@ +
+ + + + {{ message }}   {{ title }} + +
diff --git a/templates/downloads/index.html b/templates/downloads/index.html index 8afc91ded..ed3ef0b6d 100644 --- a/templates/downloads/index.html +++ b/templates/downloads/index.html @@ -1,5 +1,6 @@ {% extends "base.html" %} {% load boxes %} +{% load banners %} {% block page_title %}Download Python | {{ SITE_INFO.site_name }}{% endblock %} {% block og_title %}Download Python{% endblock %} @@ -38,6 +39,8 @@

Download the latest version of Python

{% block content %}
+ {% render_active_banner %} +

Looking for a specific release?

Python releases by version number:

diff --git a/templates/psf/default.html b/templates/psf/default.html index 67ab7d2e4..9ae2fd540 100644 --- a/templates/psf/default.html +++ b/templates/psf/default.html @@ -2,6 +2,7 @@ {% extends "base.html" %} {% load boxes %} +{% load banners %} {# TODO: Try to deduplicate this and templates/pages/default.html. #} {% block page_title %}{{ page.title }} | Python Software Foundation{% endblock %} @@ -26,6 +27,8 @@ {% block breadcrumbs %} {% load sitetree %} + {% render_active_psf_banner %} + {% sitetree_breadcrumbs from "main" template "sitetree/breadcrumbs.html" %} {% endblock breadcrumbs %} diff --git a/templates/psf/full-width.html b/templates/psf/full-width.html index b220b96d3..8a4a6ce01 100644 --- a/templates/psf/full-width.html +++ b/templates/psf/full-width.html @@ -2,6 +2,7 @@ {% extends "base.html" %} {% load boxes %} +{% load banners %} {# TODO: Try to deduplicate this and templates/pages/default.html. #} {% block page_title %}{{ page.title }} | Python Software Foundation{% endblock %} @@ -26,6 +27,8 @@ {% block breadcrumbs %} {% load sitetree %} + {% render_active_psf_banner %} + {% sitetree_breadcrumbs from "main" template "sitetree/breadcrumbs.html" %} {% endblock breadcrumbs %} diff --git a/templates/psf/index.html b/templates/psf/index.html index 6feafa93d..080e14f4d 100644 --- a/templates/psf/index.html +++ b/templates/psf/index.html @@ -1,7 +1,7 @@ {# ===== PSF LANDING PAGE ===== #} {% extends "base.html" %} -{% load boxes sponsors blogs %} +{% load boxes sponsors blogs banners %} {% block page_title %}Python Software Foundation{% endblock %} @@ -30,6 +30,7 @@ {% block content %} + {% render_active_psf_banner %}
diff --git a/templates/python/index.html b/templates/python/index.html index f8f349b68..ac8b191df 100644 --- a/templates/python/index.html +++ b/templates/python/index.html @@ -1,5 +1,6 @@ {% extends "base.html" %} {% load boxes %} +{% load banners %} {% block body_attributes %}class="python home" id="homepage"{% endblock %} @@ -36,6 +37,8 @@ {% block content %} + {% render_active_banner %} +