generated from freelawproject/new-project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #643 from freelawproject/641-EOY-banner
feat(header): add customizable banner to header
- Loading branch information
Showing
7 changed files
with
150 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{% comment %} | ||
This template renders a banner that fills the horizontal space available and | ||
conditionally displays a title, a text, and a button, based on the following params: | ||
|
||
Parameters: | ||
title: The title for the banner, displayed in bold text (optional) | ||
text: The text for the banner, displayed in regular text (optional) | ||
button_text: Text of the button (Optional: No button is displayed if not provided) | ||
button_link: The URL that the button points to (Optional: No button is displayed if not provided) | ||
|
||
The banner elements (title, text, button) are displayed in a row in large screens, and as a column | ||
in small and medium screens. | ||
|
||
It's advisable to wrap this template with a div tag and use the parent element to handle | ||
the sizing and the responsive behavior. Here's an example: | ||
|
||
<div class="flex w-44 md:w-48 lg:w-52"> | ||
{% include 'includes/banner.html' with button_text="Donate Today" button_link="https://donate.free.law/forms/supportflp" title="Today is GivingTuesday!" %} | ||
</div> | ||
{% endcomment %} | ||
|
||
<div class="flex w-full justify-center items-center py-2 px-4 sm:px-6 md:px-10"> | ||
<div class="flex lg:flex-row flex-col justify-center items-center py-3 text-center"> | ||
{% if title %} | ||
<strong class="pr-0 lg:pr-6">{{ title }}</strong> | ||
{% endif %} | ||
{% if text %} | ||
<span class="text-sm pr-2 mb-2 lg:mb-0 text-start"> | ||
{{ text }} | ||
</span> | ||
{% endif %} | ||
{% if button_text and button_link %} | ||
<div class="w-28 text-sm font-medium mr-1 outline rounded-md outline-1 hover:text-gray-300"> | ||
{% include './action-button.html' with link=button_link text=button_text size='sm' color='' %} | ||
</div> | ||
{% endif %} | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from django.contrib import admin | ||
|
||
from bc.core.models import BannerConfig | ||
|
||
|
||
@admin.register(BannerConfig) | ||
class BannerConfigAdmin(admin.ModelAdmin): | ||
list_display = ("__str__", "is_active", "title", "text") | ||
list_filter = ("is_active",) | ||
search_fields = ( | ||
"title", | ||
"text", | ||
"button_text", | ||
"button_link", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Generated by Django 5.1.1 on 2024-12-10 15:31 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
initial = True | ||
|
||
dependencies = [] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="BannerConfig", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"is_active", | ||
models.BooleanField( | ||
default=False, | ||
help_text="If another config is currently active, enabling this one will deactivate the first one.", | ||
), | ||
), | ||
( | ||
"title", | ||
models.CharField(blank=True, max_length=255, null=True), | ||
), | ||
("text", models.TextField(blank=True, null=True)), | ||
( | ||
"button_text", | ||
models.CharField(blank=True, max_length=40, null=True), | ||
), | ||
("button_link", models.URLField(blank=True, null=True)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django.conf import settings | ||
|
||
from bc.core.models import BannerConfig | ||
|
||
|
||
def banner_settings(request): | ||
active_banner = BannerConfig.objects.filter(is_active=True).first() | ||
return { | ||
"HEADER_BANNER_ENABLED": bool(active_banner), | ||
"HEADER_BANNER_TITLE": (active_banner.title if active_banner else ""), | ||
"HEADER_BANNER_TEXT": (active_banner.text if active_banner else ""), | ||
"HEADER_BANNER_BUTTON_TEXT": ( | ||
active_banner.button_text if active_banner else "" | ||
), | ||
"HEADER_BANNER_BUTTON_LINK": ( | ||
active_banner.button_link if active_banner else "" | ||
), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters