-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathpassthru.py
More file actions
72 lines (50 loc) · 1.9 KB
/
Copy pathpassthru.py
File metadata and controls
72 lines (50 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""
Passthru page apps (``feincms3.root.passthru``)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The idea of this module is to allow tagging pages to allow programmatically
determing the URL of pages which are often linked to, e.g. privacy policy or
imprint pages.
Create an application type:
.. code-block:: python
TYPES = [
...
ApplicationType(
key="imprint",
title=_("imprint"),
urlconf="feincms3.root.passthru",
template_name="pages/standard.html",
regions=[Region(key="main", title=_("Main"))],
),
]
Reverse the URL of the page (if it exists):
.. code-block:: python
# Raise NoReverseMatch on failure
reverse_passthru("imprint")
# Fallback
reverse_passthru("imprint", fallback="/en/imprint/")
# Outside the request-response cycle
reverse_passthru("imprint", urlconf=apps_urlconf())
Templates have :func:`~feincms3.templatetags.feincms3.reverse_passthru`; since
the page may not exist, the variable assignment form is generally what you
want:
.. code-block:: html+django
{% load feincms3 %}
{% reverse_passthru 'imprint' as imprint_url %}
{% if imprint_url %}<a href="{{ imprint_url }}">Imprint</a>{% endif %}
"""
from functools import partial
from django.urls import path
from django.utils.functional import lazy
from feincms3.applications import reverse_app
from feincms3.root.middleware import UseRootMiddlewareResponse
app_name = "passthru"
urlpatterns = [path("", lambda request: UseRootMiddlewareResponse(), name="passthru")]
ignore_app_name_mismatch = True
def reverse_passthru(namespace, **kwargs):
"""
Reverse a passthru app URL
Raises ``NoReverseMatch`` if page could not be found.
"""
return reverse_app(namespace, "passthru", **kwargs)
def reverse_passthru_lazy(namespace, **kwargs):
return lazy(partial(reverse_passthru, namespace, **kwargs), str)()