Skip to content

Commit

Permalink
Load banners on every page load
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarton committed Oct 15, 2024
1 parent 15370b1 commit 367e19b
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 1 deletion.
1 change: 1 addition & 0 deletions epilepsy12/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def download(self, request, queryset):

admin.site.register(OrganisationalAuditSubmission, OrganisationalAuditSubmissionAdmin)
admin.site.register(OrganisationalAuditSubmissionPeriod, OrganisationalAuditSubmissionPeriodAdmin)
admin.site.register(Banner)

admin.site.site_header = "Epilepsy12 admin"
admin.site.site_title = "Epilepsy12 admin"
Expand Down
1 change: 1 addition & 0 deletions epilepsy12/context_processors/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .banner import banner
13 changes: 13 additions & 0 deletions epilepsy12/context_processors/banner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import re
from ..models import Banner

def banner(request):
banners = Banner.objects.all()

for banner in banners:
url_matcher = re.compile(banner.url_matcher)

if url_matcher.match(request.path):
return { "banner": banner }

return {}
32 changes: 32 additions & 0 deletions epilepsy12/migrations/0038_banner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 5.1 on 2024-10-15 09:58

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
(
"epilepsy12",
"0037_alter_historicalorganisationalauditsubmission_s01wteconsultants_and_more",
),
]

operations = [
migrations.CreateModel(
name="Banner",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("url_matcher", models.CharField(max_length=255)),
("html", models.TextField()),
],
),
]
3 changes: 2 additions & 1 deletion epilepsy12/models_folder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@
from .entities.trust import Trust
from .entities.local_health_board import LocalHealthBoard

from .organisational_audit import OrganisationalAuditSubmissionPeriod, OrganisationalAuditSubmission
from .organisational_audit import OrganisationalAuditSubmissionPeriod, OrganisationalAuditSubmission
from .banner import Banner
8 changes: 8 additions & 0 deletions epilepsy12/models_folder/banner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.db import models

class Banner(models.Model):
url_matcher = models.CharField(max_length=255)
html = models.TextField()

def __str__(self):
return f"Banner for {self.url_matcher}"
1 change: 1 addition & 0 deletions rcpch-audit-engine/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
"django.contrib.messages.context_processors.messages",
"django_auto_logout.context_processors.auto_logout_client", # auto logout
"rcpch-audit-engine.build_info.get_build_info",
"epilepsy12.context_processors.banner"
]
},
},
Expand Down
15 changes: 15 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,25 @@

<body id="root">

<textarea style="display: none">
{% debug %}
</textarea>

{% block nav %}
{% include 'epilepsy12/nav.html' %}
{% endblock %}

{% if banner %}
<div class='ui container'>
<div class="rcpch_padding">
<div class="ui rcpch_info icon message">
<i class="info icon"></i>
{{banner.html}}
</div>
</div>
</div>
{% endif %}

{% if messages %}
<div class='ui container' id="message">
<div class="rcpch_padding">
Expand Down

0 comments on commit 367e19b

Please sign in to comment.