Repository navigation
Expand file tree
/
Copy pathcontext.py
More file actions
55 lines (47 loc) · 1.9 KB
/
Copy pathcontext.py
File metadata and controls
55 lines (47 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import json
from django.conf import settings
from django.contrib.staticfiles.storage import staticfiles_storage
def site_origin(request):
"""Public origin for canonical and social URLs.
CANONICAL_ORIGIN wins when it is set, so a preview host does not become
the indexed URL. Otherwise the request host is used.
"""
if settings.CANONICAL_ORIGIN:
return settings.CANONICAL_ORIGIN
return request.build_absolute_uri("/").rstrip("/")
def absolute_url(request, path):
if path.startswith(("http://", "https://")):
return path
if not path.startswith("/"):
path = "/" + path
return site_origin(request) + path
def conference(request):
"""Conference facts used by the shared header, footer, and home page."""
language = getattr(request, "LANGUAGE_CODE", "") or settings.LANGUAGE_CODE
image = staticfiles_storage.url("img/pythonmozambique-logo.png")
payload = {
"@context": "https://schema.org",
"@type": "WebSite",
"name": settings.CONFERENCE_NAME,
"url": site_origin(request) + "/",
}
website_ld = (
json.dumps(payload, ensure_ascii=False)
.replace("<", "\\u003c")
.replace(">", "\\u003e")
.replace("&", "\\u0026")
)
return {
"SOCIAL_LINKS": settings.SOCIAL_LINKS,
"CONFERENCE_NAME": settings.CONFERENCE_NAME,
"CONFERENCE_DATES": settings.CONFERENCE_DATES,
"CONFERENCE_VENUE": settings.CONFERENCE_VENUE,
"CONFERENCE_CITY": settings.CONFERENCE_CITY,
"CFP_DEADLINE": settings.CFP_DEADLINE,
"CONTACT_US_EMAILS": settings.CONTACT_US_EMAILS,
"META_DESCRIPTION": settings.META_DESCRIPTION,
"canonical_url": absolute_url(request, request.path or "/"),
"og_image_url": absolute_url(request, image),
"og_locale": "pt_PT" if language.startswith("pt") else "en_US",
"website_ld_json": website_ld,
}