Creating custom views

This page describes how to provide a custom view from within your plugin. Before you start reading this page, please read and understand how URL handling works in pretalx.

Organiser panel views

If you want to add a custom view to the organiser area of an event, register an URL in your urls.py that lives in the /orga/ subpath:

 1from django.conf.urls import url
 2
 3from pretalx.event.models.event import SLUG_CHARS
 4
 5from . import views
 6
 7urlpatterns = [
 8    url(f'^orga/event/(?P<event>[{SLUG_CHARS}]+)/',
 9        views.admin_view, name='backend'),
10    url(f'^(?P<event>[{SLUG_CHARS}]+)/p/mypluginname/',
11        views.frontend_view, name='frontend'),
12    url(f'^p/mypluginname/',
13        views.global_view, name='global-frontend'),
14]

If you just created your urls.py file and you already had the dev-server running, you’ll now have to restart it for the new file to be recognized.

If your view is event-specific, you have to name one parameter in your URL event. By convention, all plugin URLs except for backend URLs start with a /p/ to avoid namespace collisions with event names and reserved URLs.

You can then write a regular view. Our middleware will automatically detect the /orga/ subpath and will ensure the following points if this is an URL with the event parameter:

  • The user has logged in

  • The request.event attribute contains the current event

  • The user has permission to view the current event

If you want to require specific permission types, we provide you with a decorator or a mixin for your views:

1from pretalx.common.mixins.views import PermissionRequired
2
3class AdminView(PermissionRequired, View):
4    permission_required = 'orga.view_submissions'
5
6    ...

There is also a signal that allows you to add the view to the event sidebar navigation like this:

 1from django.dispatch import receiver
 2from django.urls import resolve, reverse
 3from django.utils.translation import ugettext_lazy as _
 4from pretalx.orga.signals import nav_event
 5
 6
 7@receiver(nav_event, dispatch_uid='friends_tickets_nav')
 8def navbar_info(sender, request, **kwargs):
 9    url = resolve(request.path_info)
10    if not request.user.has_perm('orga.view_orga_area', request.event):
11        return []
12    return [{
13        'label': _('My plugin view'),
14        'icon': 'heart',
15        'url': reverse('plugins:myplugin:index', kwargs={
16            'event': request.event.slug,
17        }),
18        'active': url.namespace == 'plugins:myplugin' and url.url_name == 'view',
19    }]

Frontend views

Frontend views work pretty much like organiser area views. Take care that your URL starts with f'^(?P<event>[{SLUG_CHARS}]+)/p/mypluginname for event related urls or f'^p/mypluginname for global views. You can then write a regular view. It will be automatically ensured that:

  • The requested event exists

  • The requested event is visible (either by being public, or if an organiser looks at it)

  • The request involves the correct domain for the event

  • The request.event attribute contains the correct Event object

  • The organiser has enabled the plugin

  • The locale middleware has processed the request