Table plugin

Plugin for Django CMS QE providing table listing. It allows to specify table, columns, paging and all other attributes including CSS classes to easily add any view to database without needs to create new plugin.

Usage

Add plugin from section Generic called Table.

At configuration screen pick which table you want to use. Then specify which columns to show, in which order and how many items per page to show.

TODO: Later there will be provided options to pre-filter and possibility to filter on client side by user.

API

Django CMS

class cms_qe_table.cms_plugins.TablePlugin(model=None, admin_site=None)[source]

CMS plugin allowing to add dynamically configured listing of any model.

form

alias of cms_qe_table.forms.TablePluginForm

model

alias of cms_qe_table.models.TablePluginModel

class cms_qe_table.models.TablePluginModel(*args, **kwargs)[source]

Configuration model for plugin Table for Django CMS QE. Possibility to specify table, columns, order, filtering etc. etc.

Parameters:
  • id (AutoField) –
  • path (CharField) –
  • depth (PositiveIntegerField) –
  • numchild (PositiveIntegerField) –
  • placeholder_id (ForeignKey to Placeholder) –
  • parent_id (ForeignKey to CMSPlugin) –
  • position (PositiveSmallIntegerField) –
  • language (CharField) –
  • plugin_type (CharField) –
  • creation_date (DateTimeField) –
  • changed_date (DateTimeField) –
  • cmsplugin_ptr_id (OneToOneField to CMSPlugin) –
  • table (CharField) –
  • columns (JSONField) –
  • filter (JSONField) –
  • paging_show (BooleanField) –
  • paging_per_page (IntegerField) –
exception DoesNotExist
exception MultipleObjectsReturned
columns_exist

Returns if all columns exists. When programmer rename column without change in this configuration, it will not be available anymore.

get_filter_params() → tuple[source]

Returns tuple with args and kwargs for queryset filter.

get_header() → list[source]

Returns header for table with verbose_name of fields if exists. In other cases at least uses name of that field.

get_items(page: Union[str, int, None] = None) → django.core.paginator.Page[source]

Returns items for table without header. It’s simply list (items) of lists (columns), not whole objects. Header is not included, for that use TablePluginModel.get_header.

model

Returns model for configured table.

table_exists

Returns if table exists. When programmer move model or rename table without change in this configuration, it will not be available anymore.

class cms_qe_table.forms.TablePluginForm(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]

Configuration form for plugin Table for Django CMS QE.

Views

cms_qe_table.views.get_table_choices(request: django.http.request.HttpRequest) → django.http.response.JsonResponse[source]

After choosing table, form has to show available columns. It’s done by JavaScript to call this view to get that data. URL expect one GET parameter called table. It’s because it’s easier to dynamicly change in JavaScript.

Output format is same as from cms_qe_table.utils.get_table_choices.

cms_qe_table.templatetags.cms_qe_table_filters.cms_qe_table_value(value: str) → str[source]

Django template filter to customize displaying of values by their type. If value is of type bool, then is used template cms_qe/table/table_value_bool.html. Every boilerplate or concrete app can customize this. When no template exists for given value type standard value represenation is used.

Utils

cms_qe_table.utils.get_filter_params(model, filter_data: dict) → tuple[source]

Returns tuple with args and kwargs for queryset filter.

cms_qe_table.utils.get_model_by_table(table: str) → django.db.models.base.ModelBase[source]

Returns Django model by table name.

cms_qe_table.utils.get_models_choices() → tuple[source]

Returns sorted and grouped choices of all models per app.

Example output:

(
    'app1',
    (
        ('choice1 key', 'choice1 name'),
        ...
    ),
), (
    'app2',
    (
        ('choice2 key', 'choice2 name'),
        ...
    ),
), (
    ...
)
cms_qe_table.utils.get_table_choices(table: str) → dict[source]

Returns choices for table depending on exact table name.

{
    "columns": [
        ["name", "label", "type"],
        ...
    ]
}

Exceptions

exception cms_qe_table.exceptions.TableDoesNotExists(table_name: str)[source]

Exception when plugin is configured with table which does not exists anymore. For example developer changed name or application providing that table is not used anymore.