-
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.
- Loading branch information
1 parent
bd6fd7d
commit a0ba1eb
Showing
10 changed files
with
81 additions
and
0 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): | ||
return { | ||
"LOCALITY": request.obl_locality, | ||
} |
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,27 @@ | ||
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"): | ||
# TODO: falls back to CPT for debugging | ||
code = "cpt" | ||
else: | ||
if "." in host: | ||
host = host.split(".", 1)[0] | ||
code = {"bergrivier": "wc013"}.get(host, None) | ||
if not code: | ||
raise Http404 | ||
|
||
request.obl_locality = get_object_or_404(Locality.objects, code=code) | ||
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,11 @@ | ||
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" | ||
) |
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,7 @@ | ||
{% extends 'peachjam/_header.html' %} | ||
{% block nav-items %} | ||
<li class="nav-item"> | ||
<a class="nav-link" | ||
href="{% url 'municipal_by_laws' code=LOCALITY.code %}">{{ LOCALITY.name }} By-laws</a> | ||
</li> | ||
{% 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,13 @@ | ||
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, "obl_locality", None): | ||
raise Http404() | ||
|
||
return reverse( | ||
"municipal_by_laws", kwargs={"code": self.request.obl_locality.code} | ||
) |