Request Plugins

Request plugins extend the functionality before the request is completed.

IPreProcessRequest

class portal.generic.plugin_interfaces.IPreProcessRequest

IPreProcessRequest plugins, receive request information before Portal has had a chance to service the request. It is recommended that only one plugin is registered at a time, otherwise its a case of first in first out.

Requires:
  • process method that can take at least a request object.

Returns:
  • either returns HTTP object or None, or doesn’t return anything.

A simple example that would match a url string and return a redirect to another known page (this uses the reverse functionality but could easily be a string):

from django import http

from portal.pluginbase.core import implements, Plugin
from portal.generic.plugin_interfaces import IPreProcessRequest

class DisableViewPlugin(Plugin):
    implements(IPreProcessRequest)
    def process(self, request, *args, **kwargs):
        host = request.get_host()
        _path = request.path
        if _path == '/groups/add/':
            from django.urls import reverse
            return http.HttpResponsePermanentRedirect(reverse(
                                                           'my_group_add'))

disableplugin = DisableViewPlugin()

This can be dropped into a file in to the plugin folder.

IProcessView

class portal.generic.plugin_interfaces.IProcessView

IProcessView contains the view object that is just about to be returned, before it is instantiated..

Requires:
  • process method that can take request, view_func, view_args, view_kwargs

Returns:
  • either returns HTTP object or None, or doesn’t return anything.