-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1399 from laws-africa/obl-microsites
OBL Microsites
- Loading branch information
Showing
30 changed files
with
223 additions
and
39 deletions.
There are no files selected for viewing
Empty file.
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,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class OpenByLawsMicrositesConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "obl_microsites" |
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,4 @@ | ||
def obl_microsites(request): | ||
if not hasattr(request, "microsite"): | ||
return {} | ||
return {"MICROSITE": request.microsite} |
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,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) |
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,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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions
2
obl_microsites/templates/open_by_laws/municipal_by_laws_list.html
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,2 @@ | ||
{% extends "open_by_laws/municipal_by_laws_list.html" %} | ||
{% block breadcrumbs %}{% endblock %} |
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,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 %} |
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,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 %} |
2 changes: 2 additions & 0 deletions
2
obl_microsites/templates/peachjam/layouts/document_detail.html
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,2 @@ | ||
{% extends 'peachjam/layouts/document_detail.html' %} | ||
{% block breadcrumbs %}{% endblock %} |
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,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")), | ||
] |
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,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}, | ||
) |
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
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.
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,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> |
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
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