djblets.privacy.consent.forms¶
Forms, fields, and widgets for gathering and displaying consent.
- class ConsentRequirementWidget(consent_requirement=None, attrs=None)[source]¶
A widget for displaying and gathering consent information.
This presents the consent requirement in an easy-to-digest form, and makes it easy for users to choose to allow or block the thing requiring consent.
This is meant to be used with
ConsentRequirementField
.- render(name, value, attrs=None)[source]¶
Render the widget.
- Parameters
name (unicode) – The base name used for the
<input>
elements. Specific names will be composed from this.value (unicode) – The current value for the field.
attrs (dict, optional) – HTML attributes for the widget. This is used only to set an
id
attribute for the field.
- Returns
The rendered HTML for the widget.
- Return type
- class MultiConsentRequirementsWidget(consent_requirements, attrs=None)[source]¶
A widget for displaying and gathering multiple consent information.
This adds a
ConsentRequirementWidget
for each consent requirement provided to the widget.This is meant to be used with
MultiConsentRequirementsField
.- render(name, value, attrs=None)[source]¶
Render the widget.
- Parameters
name (unicode) – The base name used for the
<input>
elements. Specific names will be composed from this.value (list of unicode) – The current values for the fields.
attrs (dict, optional) – HTML attributes for the widget. This is used only to set a base
id
attribute for the fields.
- Returns
The rendered HTML for the widget.
- Return type
- value_from_datadict(data, files, name)[source]¶
Return the field values from the submitted form data.
- Parameters
- Returns
A list of values for all the fields, in the order of the list of consent requirements provided to the widget. Each item will be one of
ConsentRequirementField.ALLOW
,ConsentRequirementField.BLOCK
, orNone
.- Return type
list of unicode
- decompress(value)[source]¶
Decompress a list of values for the widget.
This is required by the parent class, and is responsible for taking the provided data and returning a list of values that can be used for the sub-widgets.
- Parameters
value (list) – The list of values (or
None
) to normalize and return.- Returns
The resulting list of values. This may be empty.
- Return type
list of unicode
- class ConsentRequirementField(consent_requirement, user=None, consent_source=None, extra_consent_data=None, **kwargs)[source]¶
A form field for displaying and gathering consent information.
This presents the consent requirement in an easy-to-digest form, and makes it easy for users to choose to allow or block the thing requiring consent.
The cleaned result from this field is a
ConsentData
instance, which can be recorded directly in the tracker.- widget[source]¶
alias of
djblets.privacy.consent.forms.ConsentRequirementWidget
- set_initial_from_user(user)[source]¶
Set the initial state of the field based on a user’s prior consent.
This is called automatically if passing a user to the constructor. Otherwise, it should be called manually when setting up a form.
- Parameters
user (django.contrib.auth.models.User) – The user viewing the form.
- prepare_value(value)[source]¶
Prepare a value for use in the field.
This will convert a
Consent
value to a value suitable for use in the field.- Parameters
value (djblets.privacy.consent.base.Consent) – The value to convert.
- Returns
A valid value for use in the field.
- Return type
unicode
- class MultiConsentRequirementsField(consent_requirements=None, user=None, consent_source=None, extra_consent_data=None, *args, **kwargs)[source]¶
A form field for displaying and gathering mulltiple consent information.
This provides a
ConsentRequirementField
for each consent requirement provided to the field (or all registered ones if an explicit list was not provided). It’s handy for forms that offer all consent choices to the user.The cleaned result from this field is a list of
ConsentData
instances, which can be recorded directly in the tracker.- set_initial_from_user(user)[source]¶
Set the initial state of the field based on a user’s prior consent.
This is called automatically if passing a user to the constructor. Otherwise, it should be called manually when setting up a form.
- Parameters
user (django.contrib.auth.models.User) – The user viewing the form.
- prepare_value(value)[source]¶
Prepare a value for use in the field.
This will convert a list of
Consent
values given in the order of the field’s list of requirements to values suitable for use in the field.- Parameters
value (list of list djblets.privacy.consent.base.Consent) – The list of values to convert.
- Returns
A list of values suitable for use in the field.
- Return type
list of unicode
- clean(value)[source]¶
Clean and return values from submitted form data.
- Parameters
value (list of unicode) – A list of values submitted by the client.
- Returns
The list of cleaned consent data values.
- Return type
list of djblets.privacy.consent.base.ConsentData
- compress(data_list)[source]¶
Compress cleaned values for the field.
This is required by the parent class, and is responsible for taking a list of cleaned values and returning something that can be validated and returned. This implementation returns the data as-is.
- Parameters
data_list (list of djblets.privacy.consent.base.ConsentData) – The list of cleaned data.
- Returns
The list of data.
- Return type
list of djblets.privacy.consent.base.ConsentData
- class ConsentFormMixin(*args, **kwargs)[source]¶
A mixin for forms that present registered consent requirements.
This can be mixed into a form to provide consent field initialization and saving.
- get_consent_user()[source]¶
Return the user deciding on consent.
This must be implemented by subclasses.
- Returns
The user deciding on consent.
- Return type
- get_consent_source()[source]¶
Return a source to record in the consent audit trail.
This must be implemented by subclasses.
- Returns
The source to record for each consent entry.
- Return type
unicode
- get_extra_consent_data()[source]¶
Return extra data to record in the consent audit trail.
By default, this just returns an empty dictionary.
- Returns
Extra data to record for each consent entry.
- Return type
- save_consent(user)[source]¶
Save the consent information recorded in the form.
- Parameters
user (django.contrib.auth.models.User) – The user who made the consent decisions.
- class ConsentConfigPageFormMixin(*args, **kwargs)[source]¶
A mixin for config forms that present registered consent requirements.
This can be mixed into a config form to provide consent field initialization and saving. It would be used instead of
ConsentFormMixin
.