reviewboard.site.mixins¶
Mixins for LocalSite-related views and forms.
- class CheckLocalSiteAccessViewMixin[source]¶
Bases:
object
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
.
- 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:
- __annotations__ = {}¶
- class LocalSiteAwareModelFormMixin(data=None, initial={}, request=None, *args, **kwargs)[source]¶
Bases:
object
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.
- limited_to_local_site¶
The Local Site bound to the form. This will be
None
if no Local Site is bound.
- request¶
The HTTP request provided to the form. This may be
None
if no request was provided.- Type:
- __init__(data=None, initial={}, request=None, *args, **kwargs)[source]¶
Initialize the form.
- Parameters:
data (
dict
, optional) – Posted data for the form.initial (
dict
, optional) – Initial data for the form.request (
django.http.HttpRequest
, optional) – The HTTP request from the client. This is used for logging of access errors, and will be passed to the underlying form ifform_needs_request
isTrue
.*args (
tuple
) – Positional arguments to pass to the parent form.**kwargs (
dict
) – Keyword arguments to pass to the parent form.
- Keyword Arguments:
limit_to_local_site (
reviewboard.site.models.LocalSite
, optional) – A specific Local Site to bind the form to.request (
django.http.HttpRequest
, optional) – The HTTP request from the client.
- Raises:
ValueError – An object instance was provided to the form that isn’t compatible with the
LocalSite
provided inlimit_to_local_site
.
- 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:
- Raises:
django.core.exceptions.ValidationError – The form failed to validate.
- __annotations__ = {}¶