Download Plugin Interface

Download plugins allow you to extend the functionality of downloading before the request is completed, for example, giving you the ability to define rules on who is allowed access to content outside of those rules provided by core Cantemo.

When a user clicks download next to a shape or calls the download URL, we take the shape and the item ID and together with the details for the user requesting the download (it is always an authenticated user), we will start checks on whether the user is allowed to proceed with the download or not.

IDownloadSecure

class portal.generic.plugin_interfaces.IDownloadSecure

Processes the user, shape and the item before allowing it to be sent to the user.

Requires:
  • process(self, allowed, slug, shape, user):

Args:
  • allowed - Boolean indication of whether the request was already allowed or not.

  • _slug - The slug, or ItemID for the currently requested download.

  • _shape - The shape, or file, for the current download request

  • user - User requesting the download.

Returns:
  • True - Allows download to carry on through the checks

  • False - Denies any access to the download (can be overridden by more plugins)

IDownloadNameChange

If you need to change the filename that gets sent to the user you can do this here. You will get an original url and the new URL, simply return the new file info when needed.

class portal.generic.plugin_interfaces.IDownloadNameChange

Processes the name that the file is going to be presented as.

def __call__(self, url, filename, internal_url, itemid, shape, user):

Args:
  • url - The url of the backend file being fetched - not always available

  • filename - The filename which will be presented to the user

  • internal_url - The internal url to redirect to - not always available

  • itemid - The itemid being fetched

  • shape - The shape id of the shape being fetched

  • user - The user who requested the file

Returns:
  • A dict with “filename” - the filename to download as

As an example - the following adds item ID and shape ID to all downloads, and uses lowercase for the rest of the filename:

class IDownloadNameChangePluginExample(Plugin):

implements(IDownloadNameChange)

def __call__(self, url, filename, internal_url, itemid, shape, user):
return {

‘filename’: ‘%s_%s_%s’ % (itemid, shape, filename.lower())

}

plugin = IDownloadNameChangePluginExample()