Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added banners/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions banners/admin.py
Original file line number Diff line number Diff line change
@@ -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")
58 changes: 58 additions & 0 deletions banners/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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"
),
),
],
)
]
Empty file added banners/migrations/__init__.py
Empty file.
18 changes: 18 additions & 0 deletions banners/models.py
Original file line number Diff line number Diff line change
@@ -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"
)
Empty file.
28 changes: 28 additions & 0 deletions banners/templatetags/banners.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions pydotorg/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
'codesamples',
'work_groups',
'nominations',
'banners',

'allauth',
'allauth.account',
Expand Down
7 changes: 7 additions & 0 deletions templates/banners/banner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<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;">
<span class="notification-bar__icon">
<i class="fa fa-chart-line" aria-hidden="true"></i>
</span>
<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>
</span>
</div>
3 changes: 3 additions & 0 deletions templates/downloads/index.html
Original file line number Diff line number Diff line change
@@ -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 %}
Expand Down Expand Up @@ -38,6 +39,8 @@ <h1 class="call-to-action">Download the latest version of Python</h1>
{% block content %}
<div class="row download-list-widget">

{% render_active_banner %}

<h2 class="widget-title">Looking for a specific release?</h2>
<p class="success-quote">Python releases by version number:</p>

Expand Down
3 changes: 3 additions & 0 deletions templates/psf/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand All @@ -26,6 +27,8 @@
{% block breadcrumbs %}
{% load sitetree %}

{% render_active_psf_banner %}

{% sitetree_breadcrumbs from "main" template "sitetree/breadcrumbs.html" %}
{% endblock breadcrumbs %}

Expand Down
3 changes: 3 additions & 0 deletions templates/psf/full-width.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand All @@ -26,6 +27,8 @@
{% block breadcrumbs %}
{% load sitetree %}

{% render_active_psf_banner %}

{% sitetree_breadcrumbs from "main" template "sitetree/breadcrumbs.html" %}
{% endblock breadcrumbs %}

Expand Down
3 changes: 2 additions & 1 deletion templates/psf/index.html
Original file line number Diff line number Diff line change
@@ -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 %}

Expand Down Expand Up @@ -30,6 +30,7 @@


{% block content %}
{% render_active_psf_banner %}

<div class="row">
<div class="psf-widget0">
Expand Down
3 changes: 3 additions & 0 deletions templates/python/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends "base.html" %}
{% load boxes %}
{% load banners %}

{% block body_attributes %}class="python home" id="homepage"{% endblock %}

Expand Down Expand Up @@ -36,6 +37,8 @@

{% block content %}

{% render_active_banner %}

<div class="row">

<div class="small-widget get-started-widget">
Expand Down