djblets.avatars.services.file_upload¶
An avatar service for providing uploaded images.
- class FileUploadServiceForm(*args, **kwargs)[source]¶
Bases:
AvatarServiceConfigForm
The FileUploadService configuration form.
- js_view_class: Optional[str] = 'Djblets.Avatars.FileUploadSettingsFormView'[source]¶
The optional Backbone view used to render the form.
- template_name = 'avatars/services/file_upload_form.html'[source]¶
The template used to render the form.
- clean_file()[source]¶
Ensure the uploaded file is an image of an appropriate size.
- Returns:
The uploaded file, if it is valid.
- Return type:
django.core.files.UploadedFile
- Raises:
django.core.exceptions.ValidationError – Raised if the file is too large or the incorrect MIME type.
- save()[source]¶
Save the file and return the configuration.
- Returns:
The avatar service configuration.
- Return type:
- __annotations__ = {'css_bundle_names': 'List[str]', 'form_id': 'Optional[str]', 'form_title': 'Optional[StrOrPromise]', 'js_bundle_names': 'List[str]', 'js_model_class': 'Optional[str]', 'js_view_class': 'Optional[str]', 'save_label': 'Optional[StrOrPromise]'}¶
- declared_fields = {'avatar_upload': <django.forms.fields.FileField object>, 'form_target': <django.forms.fields.CharField object>}¶
- class FileUploadService(settings_manager_class)[source]¶
Bases:
AvatarService
An avatar service for uploaded images.
- avatar_service_id = 'file-upload'[source]¶
The avatar service’s ID.
This must be unique for every avatar service subclass.
- config_form_class[source]¶
alias of
FileUploadServiceForm
- property file_path_prefix[source]¶
The storage location for uploaded avatars.
This will be prepended to the path of all uploaded files. By default, it is controlled by the
UPLOADED_AVATARS_PATH
setting.
- get_unique_filename(filename)[source]¶
Create a unique filename.
The unique filename will be the original filename suffixed with a generated UUID.
- get_avatar_urls_uncached(user, size)[source]¶
Return the avatar URLs for the requested user.
- Parameters:
user (
django.contrib.auth.models.User
) – The user whose avatar URLs are to be fetched.size (
int
) – The size (in pixels) the avatar is to be rendered at.
- Returns
dict: A dictionary containing the URLs of the user’s avatars at normal- and high-DPI.
- cleanup(user)[source]¶
Clean up the uploaded file.
This will delete the uploaded file from the storage.
- Parameters:
user (
django.contrib.auth.models.User
) – The user.
- get_etag_data(user)[source]¶
Return the ETag data for the user’s avatar.
- Parameters:
user (
django.contrib.auth.models.User
) – The user.- Returns:
The uniquely identifying information for the user’s avatar.
- Return type:
- __annotations__ = {}¶