Skip to content

Commit 8209374

Browse files
committed
update the partner middleware and pages
1 parent 5985704 commit 8209374

File tree

5 files changed

+59
-24
lines changed

5 files changed

+59
-24
lines changed

backend/donations/views/site.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ def _partner_response(self, context: Dict, partner: Partner):
7272
context.update(
7373
{
7474
"company_name": partner.name,
75-
"custom_header": partner.has_custom_header,
76-
"custom_note": partner.has_custom_note,
75+
"has_custom_header": partner.has_custom_header,
76+
"has_custom_note": partner.has_custom_note,
7777
"ngos": partner_ngos,
7878
}
7979
)

backend/partners/middleware.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def extract_subdomain(host: str, apex: str) -> str:
2626
# Drop the port number (if present)
2727
host = host.split(":", maxsplit=1)[0]
2828

29-
# Drop the www. prefix (if present)
29+
# Drop the `www.` prefix (if present)
3030
if host[:4] == "www.":
3131
host = host[4:]
3232

@@ -40,21 +40,17 @@ def extract_subdomain(host: str, apex: str) -> str:
4040

4141
return subdomain
4242

43-
def __init__(self, get_response):
44-
self.get_response = get_response
45-
46-
def __call__(self, request):
47-
if request.path == "/health/":
48-
logger.debug("Healthcheck: Skipping PartnerDomainMiddleware")
49-
return self.get_response(request)
43+
def _get_partner_from_subdomain(self, request):
44+
if settings.FORCE_PARTNER:
45+
return Partner.active.first()
5046

51-
logger.debug("Request host %s", request.get_host())
5247
try:
5348
subdomain = PartnerDomainMiddleware.extract_subdomain(request.get_host(), settings.APEX_DOMAIN)
5449
except InvalidSubdomain:
5550
raise Http404(f"Invalid APEX_DOMAIN: {settings.APEX_DOMAIN}")
5651

5752
logger.debug("Subdomain %s", subdomain or "None")
53+
5854
if not subdomain:
5955
partner = None
6056
else:
@@ -63,6 +59,19 @@ def __call__(self, request):
6359
except Partner.DoesNotExist:
6460
partner = None
6561

62+
return partner
63+
64+
def __init__(self, get_response):
65+
self.get_response = get_response
66+
67+
def __call__(self, request):
68+
if request.path == "/health/":
69+
logger.debug("Healthcheck: Skipping PartnerDomainMiddleware")
70+
return self.get_response(request)
71+
72+
logger.debug("Request host %s", request.get_host())
73+
partner = self._get_partner_from_subdomain(request)
74+
6675
request.partner = partner
6776
logger.debug("Request partner %s", request.partner or "None")
6877

backend/redirectioneaza/settings/app_configs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from django.utils.translation import gettext_lazy as _
88
from localflavor.ro.ro_counties import COUNTIES_CHOICES
99

10+
from .base import DEBUG
1011
from .environment import env
1112

1213
# Global parameters
@@ -131,3 +132,7 @@
131132
if len(ENCRYPT_KEY) != 32 or ENCRYPT_KEY == "%INVALID%":
132133
raise Exception("ENCRYPT_KEY must be exactly 32 characters long")
133134
FERNET_OBJECT = Fernet(urlsafe_b64encode(ENCRYPT_KEY.encode("utf-8")))
135+
136+
FORCE_PARTNER = False
137+
if DEBUG:
138+
FORCE_PARTNER = env.bool("FORCE_PARTNER", False)

backend/redirectioneaza/settings/environment.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
TIMEDELTA_DONATIONS_LIMIT_DOWNLOAD_DAYS=(int, 31),
2222
IS_CONTAINERIZED=(bool, False),
2323
RECAPTCHA_ENABLED=(bool, True),
24+
FORCE_PARTNER=(bool, False),
2425
# proxy headers
2526
USE_PROXY_FORWARDED_HOST=(bool, False),
2627
PROXY_SSL_HEADER=(str, "HTTP_CLOUDFRONT_FORWARDED_PROTO"),

backend/templates/v2/public/components/home/hero.html

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,32 @@
77

88
<h1 class="block mt-1 text-4xl font-extrabold tracking-tight sm:text-5xl xl:text-6xl">
99

10-
<span class="block text-gray-900">
11-
{% if custom_subdomain %}
12-
{% trans "Redirect 3.5% of your tax to one of the NGOs" %}
10+
{% if custom_subdomain %}
11+
{% if has_custom_note %}
12+
{% trans "Redirect 3.5% of your income tax" as heading_main %}
13+
{% trans "to a cause of your choice" as heading_secondary %}
1314
{% else %}
14-
{% trans "You decide what happens" %}
15+
{% trans "Redirect 3.5% of your tax to one of the NGOs" as heading_main %}
16+
{% blocktrans trimmed asvar heading_secondary %}
17+
supported by {{ company_name }}
18+
{% endblocktrans %}
1519
{% endif %}
16-
</span>
20+
{% else %}
21+
{% trans "You decide what happens" as heading_main %}
22+
{% trans "with 3.5% of the income tax" as heading_secondary %}
23+
{% endif %}
1724

18-
<span class="block text-amber-300">
19-
{% if custom_subdomain %}
20-
{% trans "supported by" %}
21-
{{ company_name }}
22-
{% else %}
23-
{% trans "with 3.5% of the income tax" %}
24-
{% endif %}
25-
</span>
25+
{% if heading_main %}
26+
<div class="block text-gray-900">
27+
{{ heading_main }}
28+
</div>
29+
{% endif %}
30+
31+
{% if heading_secondary %}
32+
<div class="block text-amber-300">
33+
{{ heading_secondary }}
34+
</div>
35+
{% endif %}
2636

2737
</h1>
2838

@@ -36,6 +46,16 @@ <h1 class="block mt-1 text-4xl font-extrabold tracking-tight sm:text-5xl xl:text
3646
<strong>{{ limit.day }} {{ month_limit }}</strong>.
3747
</p>
3848

49+
{% if has_custom_note %}
50+
<p class="mt-3 text-base text-gray-500 sm:mt-5">
51+
{% blocktrans trimmed %}
52+
If your favorite NGO is not on this page,
53+
check the full list of organizations on
54+
<a class="underline text-cyan-700" href="https://redirectioneaza.ro">redirectioneaza.ro</a>.
55+
{% endblocktrans %}
56+
</p>
57+
{% endif %}
58+
3959
{% if not custom_subdomain %}
4060
{% include "public/components/home/hero-search.html" %}
4161

0 commit comments

Comments
 (0)