mirror of
https://github.com/pretix/pretix.git
synced 2026-08-09 10:37:50 +00:00
Simplify the API for custom URLs
This commit is contained in:
@@ -12,7 +12,7 @@ Control panel views
|
||||
-------------------
|
||||
|
||||
If you want to add a custom view to the control area of an event, just register an URL in your
|
||||
``maindomain_urls.py`` that lives in the ``/control/`` subpath::
|
||||
``urls.py`` that lives in the ``/control/`` subpath::
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
@@ -66,26 +66,14 @@ Frontend views
|
||||
Including a custom view into the participant-facing frontend is a little bit different as there is
|
||||
no path prefix like ``control/``.
|
||||
|
||||
First, define your URL in your ``maindomain_urls.py``::
|
||||
First, define your URL in your ``urls.py``, but this time in the ``event_patterns`` section::
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^(?P<organizer>[^/]+)/(?P<event>[^/]+)/mypluginname/',
|
||||
views.frontend_view, name='frontend'),
|
||||
]
|
||||
|
||||
And for the case of custom domains in your ``subdomain_urls.py``::
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^(?P<event>[^/]+)/mypluginname/',
|
||||
views.frontend_view, name='frontend'),
|
||||
event_patterns = [
|
||||
url(r'^mypluginname/', views.frontend_view, name='frontend'),
|
||||
]
|
||||
|
||||
You can then implement a view as you would normally do, but you need to apply a decorator to your
|
||||
@@ -104,4 +92,4 @@ correctly ensure that:
|
||||
* The event is accessed via the domain it should be accessed
|
||||
* The ``request.event`` attribute contains the correct ``Event`` object
|
||||
* The ``request.organizer`` attribute contains the correct ``Organizer`` object
|
||||
* The locale is set correctly
|
||||
* The locale is set correctly
|
||||
|
||||
@@ -29,8 +29,8 @@ former our ``maindomain`` config and the latter our ``subdomain`` config. For pr
|
||||
modules we do some magic to avoid duplicate configuration, but for a fairly simple plugin with
|
||||
only a handful of routes, we recommend just configuring the two URL sets separately.
|
||||
|
||||
The file ``maindomain_urls.py`` inside your plugin package will be loaded and scanned for
|
||||
URL configuration automatically and should be provided by any plugin that provides any view.
|
||||
The file ``urls.py`` inside your plugin package will be loaded and scanned for URL configuration
|
||||
automatically and should be provided by any plugin that provides any view.
|
||||
|
||||
A very basic example that provides one view in the admin panel and one view in the frontend
|
||||
could look like this::
|
||||
@@ -42,23 +42,19 @@ could look like this::
|
||||
urlpatterns = [
|
||||
url(r'^control/event/(?P<organizer>[^/]+)/(?P<event>[^/]+)/mypluginname/',
|
||||
views.AdminView.as_view(), name='backend'),
|
||||
url(r'^(?P<organizer>[^/]+)/(?P<event>[^/]+)/mypluginname/',
|
||||
views.FrontendView.as_view(), name='frontend'),
|
||||
]
|
||||
|
||||
A matching configuration for custom domains will be expected in the ``subdomain_urls.py`` file
|
||||
of your package and would look like this::
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^(?P<event>[^/]+)/mypluginname/',
|
||||
views.FrontendView.as_view(), name='frontend'),
|
||||
event_patterns = [
|
||||
url(r'^mypluginname/', views.FrontendView.as_view(), name='frontend'),
|
||||
]
|
||||
|
||||
If you only provide URLs in the admin area, you do not need to provide a ``subdomain_urls`` module.
|
||||
.. note::
|
||||
As you can see, the view in the frontend is not included in the standard Django ``urlpatterns``
|
||||
setting but in a separate list with the name ``event_patterns``. This will automatically prepend
|
||||
the appropriate parameters to the regex (e.g. the event or the event and the organizer, depending
|
||||
on the called domain).
|
||||
|
||||
If you only provide URLs in the admin area, you do not need to provide a ``event_patterns`` attribute.
|
||||
|
||||
URL reversal
|
||||
------------
|
||||
|
||||
Reference in New Issue
Block a user