Skip to content

Commit

Permalink
Merge pull request #1399 from laws-africa/obl-microsites
Browse files Browse the repository at this point in the history
OBL Microsites
  • Loading branch information
longhotsummer authored Jul 24, 2023
2 parents 47a41ae + 0e244b9 commit 82d1a45
Show file tree
Hide file tree
Showing 30 changed files with 223 additions and 39 deletions.
Empty file added obl_microsites/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions obl_microsites/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class OpenByLawsMicrositesConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "obl_microsites"
4 changes: 4 additions & 0 deletions obl_microsites/context_processors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def obl_microsites(request):
if not hasattr(request, "microsite"):
return {}
return {"MICROSITE": request.microsite}
31 changes: 31 additions & 0 deletions obl_microsites/middleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from django.conf import settings
from django.http import Http404
from django.shortcuts import get_object_or_404

from peachjam.models import Locality


class LocalityMiddleware(object):
"""Middleware to determine the locality for the microsite, based on the domain of the request."""

def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):
host = request.get_host()

if host.startswith("127.0.0.1") or host.startswith("localhost"):
host = "bergrivier"
elif "." in host:
host = host.split(".", 1)[0]

microsite = settings.MICROSITES.get(host)
if not microsite:
raise Http404

if "locality" not in microsite:
microsite["locality"] = get_object_or_404(
Locality.objects, code=microsite["code"]
)
request.microsite = microsite
return self.get_response(request)
14 changes: 14 additions & 0 deletions obl_microsites/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from open_by_laws.settings import * # noqa

INSTALLED_APPS = ["obl_microsites"] + INSTALLED_APPS # noqa

ROOT_URLCONF = "obl_microsites.urls"

MIDDLEWARE = ["obl_microsites.middleware.LocalityMiddleware"] + MIDDLEWARE # noqa

TEMPLATES[0]["OPTIONS"]["context_processors"].append( # noqa
"obl_microsites.context_processors.obl_microsites"
)

# rely on open-by-laws to manage search indexing
ELASTICSEARCH_DSL_AUTOSYNC = False
1 change: 1 addition & 0 deletions obl_microsites/static/images/openup-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% extends "open_by_laws/municipal_by_laws_list.html" %}
{% block breadcrumbs %}{% endblock %}
28 changes: 28 additions & 0 deletions obl_microsites/templates/peachjam/_footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% extends 'peachjam/_footer.html' %}
{% load static %}
{% block newsletter-form %}{% endblock %}
{% block social-media %}{% endblock %}
{% block first-content-column %}
<h5>{{ MICROSITE.locality.name }} By-laws</h5>
<ul class="list-unstyled">
<li>
<a href="{% url 'home_page' %}">By-laws</a>
</li>
<li>
<a href="{{ MICROSITE.website }}">{{ MICROSITE.locality.name }} website</a>
</li>
</ul>
<img src="{% static 'images/municipalities/'|add:MICROSITE.code|add:"-logo.png" %}"
alt="{{ MICROSITE.locality.name }}"/>
{% endblock %}
{% block second-content-column %}{% endblock %}
{% block third-content-column %}
<p>
The by-laws are published through a partnership between {{ MICROSITE.locality.name }} Municipality and
<a href="https://openup.org.za">OpenUp</a>.
</p>
<img src="{% static 'images/openup-logo.svg' %}"
alt="OpenUp"
style="height: 40px"/>
{% endblock %}
{% block footer-logos %}{% endblock %}
29 changes: 29 additions & 0 deletions obl_microsites/templates/peachjam/_header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% extends 'peachjam/_header.html' %}
{% load static %}
{% block top-bar %}
<div class="p-2 bg-dark">
<div class="container d-flex justify-content-end">
<a href="{{ MICROSITE.locality.website }}"
target="_blank"
rel="noreferrer"
class="ms-3 text-white">
{{ MICROSITE.locality.name }} website →
</a>
</div>
</div>
{% endblock %}
{% block navbar-logo %}
<img src="{% static 'images/municipalities/'|add:MICROSITE.code|add:"-logo.png" %}"
alt="{{ MICROSITE.locality.name }} By-laws"
height="70"/>
{% endblock %}
{% block nav-items %}
<li class="nav-item">
<a class="nav-link"
href="{% url 'municipal_by_laws' code=MICROSITE.locality.code %}">{{ MICROSITE.locality.name }} By-laws</a>
</li>
{% endblock %}
{% block search-form %}
{{ block.super }}
<input type="hidden" name="locality" value="{{ MICROSITE.locality.name }}"/>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% extends 'peachjam/layouts/document_detail.html' %}
{% block breadcrumbs %}{% endblock %}
9 changes: 9 additions & 0 deletions obl_microsites/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.urls import include, path

from obl_microsites.views import RedirectHomeView

urlpatterns = [
# redirect the homepage view to the appropriate municipality listing view
path("", RedirectHomeView.as_view()),
path("", include("open_by_laws.urls")),
]
14 changes: 14 additions & 0 deletions obl_microsites/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.http import Http404
from django.urls import reverse
from django.views.generic import RedirectView


class RedirectHomeView(RedirectView):
def get_redirect_url(self, *args, **kwargs):
if not getattr(self.request, "microsite", None):
raise Http404()

return reverse(
"municipal_by_laws",
kwargs={"code": self.request.microsite["locality"].code},
)
39 changes: 39 additions & 0 deletions open_by_laws/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.utils.translation import gettext_lazy as _

from liiweb.settings import * # noqa

INSTALLED_APPS = ["open_by_laws.apps.OpenByLawsConfig"] + INSTALLED_APPS # noqa
Expand All @@ -12,3 +14,40 @@
TEMPLATES[0]["OPTIONS"]["context_processors"].append( # noqa
"open_by_laws.context_processors.open_by_laws"
)

LANGUAGES = [
("en", _("English")),
]

MICROSITES = {
"bergrivier": {
"name": "Bergrivier",
"code": "wc013",
"website": "https://www.bergmun.org.za/",
"url": "https://bergrivier.openbylaws.org.za",
},
"capeagulhas": {
"name": "Cape Agulhas",
"code": "wc033",
"website": "https://capeagulhas.gov.za/",
"url": "https://capeagulhas.openbylaws.org.za",
},
"cederberg": {
"name": "Cederberg",
"code": "wc012",
"website": "http://www.cederbergmun.gov.za/",
"url": "https://cederberg.openbylaws.org.za",
},
"mbizana": {
"name": "Mbizana",
"code": "ec443",
"website": "http://www.mbizana.gov.za/",
"url": "https://mbizana.openbylaws.org.za",
},
"matzikama": {
"name": "Matzikama",
"code": "wc011",
"website": "https://www.matzikamamunicipality.co.za/",
"url": "https://matzikama.openbylaws.org.za",
},
}
Binary file added open_by_laws/static/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions open_by_laws/templates/open_by_laws/_municipalities.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% load static %}
<div class="row">
{% for item in object_list %}
<div class="col-md-4">
<a class="placard {{ item.code }}"
href="{% if item.url %}{{ item.url }}{% else %}{% url 'municipal_by_laws' item.code %}{% endif %}"
style="background-image: url('{% static "/images/municipalities/"|add:item.code|add:"-placard.jpg" %}')">
<h3>{{ item.name }}</h3>
</a>
</div>
{% endfor %}
</div>
18 changes: 7 additions & 11 deletions open_by_laws/templates/open_by_laws/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,13 @@ <h5 class="text-sm-left">
</section>
<section class="municipalities py-5">
<div class="container">
<div class="row">
{% for municipality in municipalities %}
<div class="col-md-4">
<a class="placard {{ municipality.code }}"
href="{% url 'municipal_by_laws' municipality.code %}"
style="background-image: url('{% static "/images/municipalities/" %}{{ municipality.code }}-placard.jpg')">
<h3>{{ municipality.name }}</h3>
</a>
</div>
{% endfor %}
</div>
{% with object_list=municipalities %}
{% include "open_by_laws/_municipalities.html" %}
{% endwith %}
<h4>Official municipal partners</h4>
{% with object_list=microsites %}
{% include "open_by_laws/_municipalities.html" %}
{% endwith %}
</div>
</section>
</div>
Expand Down
22 changes: 6 additions & 16 deletions open_by_laws/templates/peachjam/_header.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
{% extends 'peachjam/_header.html' %}
{% load static i18n %}
{% block top-bar %}
<div class="p-2 bg-light">
<div class="container d-flex justify-content-end">
<a href="https://lawlibrary.org.za"
target="_blank"
rel="noreferrer"
class="ms-3">
<img src="{% static 'images/lawlibrary-logo.png' %}"
alt="lawlibrary"
height="40"/>
</a>
</div>
</div>
{% endblock %}
{% block top-bar %}{% endblock %}
{% block navbar-logo %}
<img src="{% static 'images/logo-lg.png' %}"
<img src="{% static 'images/logo.png' %}"
alt="Law Library"
height="70"
class="me-3"/>
<img src="{% static 'images/lawlibrary-logo.png' %}"
alt="Open By-laws"
width="65"
height="70"/>
{% endblock %}
{% block nav-items %}
Expand Down
7 changes: 6 additions & 1 deletion open_by_laws/views/home.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.conf import settings

from liiweb.views import HomePageView as LiiWebPageView
from peachjam.models import Locality

Expand All @@ -7,6 +9,9 @@ class HomePageView(LiiWebPageView):

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
codes = "cpt eth jhb wc033 wc011 ec443 wc013 wc012 wc015 wc041 wc023".split()

codes = "cpt eth jhb wc015 wc041 wc023".split()
context["municipalities"] = Locality.objects.filter(code__in=codes)
context["microsites"] = settings.MICROSITES.values()

return context
24 changes: 13 additions & 11 deletions peachjam/templates/peachjam/_header.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@
{% if request.path == '/' %}
{% else %}
<form method="get" action="{% url 'search:search' %}">
<div class="input-group">
<input type="text"
class="form-control"
placeholder="{% blocktrans %}Search {{ APP_NAME }}{% endblocktrans %}"
aria-label="{% blocktrans %}Search {{ APP_NAME }}{% endblocktrans %}"
aria-describedby="button-addon2"
name="q"/>
<button class="btn btn-dark" type="submit" id="button-addon2">
<i class="bi bi-search text-white"></i>
</button>
</div>
{% block search-form %}
<div class="input-group">
<input type="text"
class="form-control"
placeholder="{% blocktrans %}Search {{ APP_NAME }}{% endblocktrans %}"
aria-label="{% blocktrans %}Search {{ APP_NAME }}{% endblocktrans %}"
aria-describedby="button-addon2"
name="q"/>
<button class="btn btn-dark" type="submit" id="button-addon2">
<i class="bi bi-search text-white"></i>
</button>
</div>
{% endblock %}
</form>
{% endif %}
{% if user.is_authenticated %}
Expand Down

0 comments on commit 82d1a45

Please sign in to comment.