Jump to >


class FakeHTTPRequest(user, local_site_name=None)[source]

A fake HttpRequest implementation.

The WebAPI serialization methods use HttpRequest.build_absolute_uri to generate all the links, but none of the various signals that generate webhook events have the request plumbed through. Since we don’t actually need a valid request, this impersonates it enough to get valid results from build_absolute_uri.


The protocol scheme used to access the web server.

This is needed by the underlying class to build absolute URLs. It returns the scheme from the current site configuration.

New in version 4.0.3.




Return the hostname for the server.

This is needed by the underlying class to build absolute URLs. It returns the hostname from the configured site information.


The hostname.

Return type


class CustomPayloadParser(*args, **kwargs)[source]

A custom template parser that blocks certain tags.

This extends Django’s Parser class for template parsing, and removes some built-in tags, in order to prevent mailicious use.

invalid_block_tag(token, command, parse_until=None)[source]

Raise an error when an invalid block tag is found.

Normally Django produces a suitable error, but in modern versions of Django, the error is _too_ helpful, reminding the user to register or load the tag. This isn’t useful for WebHooks, so we override to use the older, simpler message used in Django 1.6.

  • token (django.template.base.Token) – The token representing the block tag.

  • command (unicode) – The name of the block tag that was found.

  • parse_until (list of django.template.base.Token, optional) – The list of tokens that were expected to be parsed instead of this token.

render_custom_content(body, context_data={})[source]

Render custom content for the payload using Django templating.

This will take the custom payload content template provided by the user and render it using a stripped down version of Django’s templating system.

In order to keep the payload safe, we use a limited Context along with a custom Parser that blocks certain template tags. This gives us tags like {% for %} and {% if %}, but blacklists tags like {% load %} and {% include %}.

  • body (unicode) – The template content to render.

  • context_data (dict, optional) – Context data for the template.


The rendered template.

Return type



django.template.TemplateSyntaxError – There was a syntax error in the template.

normalize_webhook_payload(payload, request, use_string_keys=False)[source]

Normalize a payload for a WebHook, returning a safe, primitive version.

This will take a payload containing various data types and model references and turn it into a payload built out of specific, whitelisted types (strings, bools, ints, dicts, lists, and datetimes). This payload is safe to include in custom templates without worrying about access to dangerous functions, and is easy to serialize.

  • payload (dict) – The payload to normalize.

  • request (django.http.HttpRequest) – The HTTP request from the client.

  • use_string_keys (bool, optional) – Whether to normalize all keys to strings.


The normalized payload.

Return type



TypeError – An unsupported data type was found in the payload. This is an issue with the caller.

dispatch_webhook_event(request, webhook_targets, event, payload)[source]

Dispatch the given event and payload to the given WebHook targets.

  • request (django.http.HttpRequest) – The HTTP request from the client.

  • webhook_targets (list of reviewboard.notifications.models.WebHookTarget) – The list of WebHook targets containing endpoint URLs to dispatch to.

  • event (unicode) – The name of the event being dispatched.

  • payload (dict) – The payload data to encode for the WebHook payload.


ValueError – There was an error with the payload format. Details are in the log and the exception message.