authentication_service.utils module¶
-
authentication_service.utils.
check_limit
(limit)[source]¶ Ensures the limit is within bounds or sets the default limit if no limit was specified. :param limit: Amount of objects to return. :return: Either the minimum, maximum or the default limit.
-
authentication_service.utils.
strip_empty_optional_fields
(object_dict)[source]¶ We do not need to add fields that contain None to the response, so we strip those fields out of the response. To do this, we iterate over the fields in the input dictionary and check that the value isn’t, what we consider, empty. If a field has a value, add that field and value to the output dictionary. :param object_dict: Input dictionary containing possible empty fields. :return: Output dictionary containing only fields that have values.
-
authentication_service.utils.
to_dict_with_custom_fields
(instance, custom_fields)[source]¶ Convert an object to a dictionary with only some of the fields that exist on the object. Some fields also require some manual handling. :param instance: Object to be converted. :param custom_fields: List of fields to include in dict. :return: Dictionary with custom fields.
-
authentication_service.utils.
update_form_fields
(form, required=None, hidden=None, validators=None, fields_data=None)[source]¶ Update form fields and widgets.
form – Instance of a form. required – list of fields to toggle required for. hidden – list of fields to hide. validators – a dictionary
- {
- “<fieldname>”: [<list of validators>]
}
- fields_data – a dictionary
- {
- “<fieldname>”: {
- “attributes”: {
- <attribute>: <value>
},
}
}
Helper method for setting field and widget attributes, can be used for any form instance. Sets attributes on both fields and widgets.