Jump to >

reviewboard.site.mixins

Mixins for LocalSite-related views and forms.

class CheckLocalSiteAccessViewMixin[source]

Generic view mixin to check if a user has access to the Local Site.

It’s important to note that this does not check for login access. This is just a convenience around using the @check_local_site_access decorator for generic views.

The local_site attribute will be set on the class for use in the view.

local_site

The Local Site being accessed, or None.

Type

reviewboard.site.models.LocalSite

dispatch(request, local_site=None, *args, **kwargs)[source]

Dispatch a HTTP request to the right handler.

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

  • local_site (reviewboard.site.models.LocalSite, optional) – The Local Site being accessed, if any.

  • *args (tuple) – Positional arguments to pass to the handler.

  • **kwargs (tuple) –

    Keyword arguments to pass to the handler.

    These will be arguments provided by the URL pattern.

Returns

The resulting HTTP response to send to the client.

Return type

django.http.HttpResponse

class LocalSiteAwareModelFormMixin(data=None, initial={}, request=None, *args, **kwargs)[source]

Mixin for model forms that associate with Local Sites.

This mixin allows model forms to be bound to a Local Site, which will then limit all relation fields to objects bound to the same site. This allows the construction of forms that could be modified by a Local Site administrator without risk of data outside the Local Site being used. The bound Local Site will always be forced, and the field will not appear on the form.

When not bound to a Local Site, relations across all Local Sites (and those not associated with a Local Site) are allowed, but if a Local Site is being assigned when posting to the form, all related objects will be validated against that Local Site.

cur_local_site

The Local Site that’s either been bound to the form or provided in posted data. This will be None if no Local Site is being used.

Type

reviewboard.site.models.LocalSite

limited_to_local_site

The Local Site bound to the form. This will be None if no Local Site is bound.

Type

reviewboard.site.models.LocalSite

request

The HTTP request provided to the form. This may be None if no request was provided.

Type

django.http.HttpRequest

local_site_field_name = 'local_site'[source]

The name of the Local Site field on the form.

form_needs_request = False[source]

Whether the form needs the ‘request’ argument.

full_clean()[source]

Perform a full clean the form.

This wraps the typical form cleaning process by first ensuring that all relation fields limit their choices to objects on the bound Local Site (if one is set), allowing validation to work naturally on each field. It then invokes the standard form cleaning logic, and then restores the choices.

Returns

The cleaned data from the form.

Return type

dict

Raises

django.core.exceptions.ValidationError – The form failed to validate.