Album

Models

An album component you may use in a gallery.

Album items are ordered from their order field value. Items with a zero value for their order will be ordered in an almost arbitrary order (mostly depending from item object id).

Album form have a special field mass_upload, it expects a valid ZIP archive file to create items. Archive file is limited to the value from setting BLOCKS_MASSUPLOAD_FILESIZE_LIMIT.

The archive file may contains one or many image files with enabled format from django-smart-media setting SMARTIMAGE_ALLOWED_IMAGE_EXTENSIONS. Each image will create a new Album item where the name will be filled with the full relative image file path. Images in archive can be structured in multiple subdirectory. Created Album item from an archive don’t have any order.

class cmsplugin_blocks.models.album.Album(*args, **kwargs)[source]

Album container for items.

title

A required title string.

template

Template choice from available plugin templates in setting BLOCKS_ALBUM_TEMPLATES. Default to the first choice item.

size_features

Optional related size features.

color_features

Optional related color features.

extra_features

Optional related extra features.

copy_relations(oldinstance)[source]

Copy all relations when plugin object is copied as another object.

See:

https://docs.django-cms.org/en/latest/how_to/09-custom_plugins.html#relations-between-plugins

class cmsplugin_blocks.models.album.AlbumItem(*args, **kwargs)[source]

Album item to include in container.

title

Optional title string.

order

Number for order position in item list.

image

Required image file.

image_alt

An optional text string for alternative image text.

Factories

Forms

class cmsplugin_blocks.forms.album.AlbumForm(*args, **kwargs)[source]

Form to manage an Album with possible ZIP file to store items.

Be aware that this form does not finally save collected image items, they are stored to attribute _awaiting_items on Album instance. Then in the common workflow, the CMS plugin using this form will get this attribute and perform final save. If you use this form without the CMS plugin edit workflow, you will need to reproduce it.

clean_mass_upload()[source]

Validate uploaded ZIP archive file and temporary store it to “uploaded_zip” form object attribute if valid.

save(*args, **kwargs)[source]

Save this form’s self.instance object if commit=True. Otherwise, add a save_m2m() method to the form which can be called after the instance is saved manually at a later time. Return the model instance.

property media

Return all media required to render the widgets on this form.

class cmsplugin_blocks.forms.album.AlbumItemForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)[source]
property media

Return all media required to render the widgets on this form.

Plugins

class cmsplugin_blocks.plugins.album.AlbumPlugin(model=None, admin_site=None)[source]

Album interface is able to add/edit/remove items within inline forms.

Also used template is dynamically retrieved from “template” value.

module = 'Blocks'

Modules collect plugins of similar type

name = 'Album'

Name of the plugin needs to be set in child classes

model

alias of Album

form

alias of AlbumForm

render_template = 'cmsplugin_blocks/album/default.html'

The path to the template used to render the template. If render_plugin is True either this or get_render_template must be defined. See also: render_plugin , get_render_template().

cache = True

Is this plugin cacheable? If your plugin displays content based on the user or request or other dynamic properties set this to False.

If present and set to False, the plugin will prevent the caching of the resulting page.

Important

Setting this to False will effectively disable the CMS page cache and all upstream caches for pages where the plugin appears. This may be useful in certain cases but for general cache management, consider using the much more capable get_cache_expiration().

Warning

If you disable a plugin cache be sure to restart the server and clear the cache afterwards.

get_fieldsets(request, obj=None)[source]

Define plugin form fieldsets depending features are enabled or not (when there is no defined feature choices).

render(context, instance, placeholder)[source]

This method returns the context to be used to render the template specified in render_template.

Parameters:
  • context (dict) – The context with which the page is rendered.

  • instance (cms.models.pluginmodel.CMSPlugin instance) – The instance of your plugin that is rendered.

  • placeholder (str) – The name of the placeholder that is rendered.

Return type:

dict or django.template.Context

This method must return a dictionary or an instance of django.template.Context, which will be used as context to render the plugin template.

By default, this method will add instance and placeholder to the context, which means for simple plugins, there is no need to overwrite this method.

If you overwrite this method it’s recommended to always populate the context with default values by calling the render method of the super class:

def render(self, context, instance, placeholder):
    context = super().render(context, instance, placeholder)
    ...
    return context
save_model(request, obj, form, change)[source]

Override original method, and add some attributes to obj This has to be made, because if the object is newly created, it must know where it lives.