django-itemlist


Namedjango-itemlist JSON
Version 0.3.4 PyPI version JSON
download
home_pagehttps://github.com/michel4j/django-itemlist
SummaryA customizable Django Admin ChangeList-like app for use outside of the admin.
upload_time2024-11-21 16:34:18
maintainerNone
docs_urlNone
authorMichel Fodje
requires_pythonNone
licenseMIT License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ========
ItemList
========

ItemList is a customizable Django Admin ChangeList-like app for use outside of the admin.
It can be used to create versatile paginated lists of objects which can be searched, filtered
and provide links to detail pages similarly to the admin ChangeLists.

Provides a generic class-based view `ItemListView`.

ItemListView
------------

*class itemlist.views.ItemListView*
    A page representing a list of objects, with a search box, list filters, sortable columns, pagination and optional
    links to detailed pages.

    *Ancestors (MRO)*
        This view inherits methods and attributes from the following Django  views:

        * django.views.generic.list.ListView
        * django.views.generic.list.MultipleObjectTemplateResponseMixin
        * django.views.generic.base.TemplateResponseMixin
        * django.views.generic.list.BaseListView
        * django.views.generic.list.MultipleObjectMixin
        * django.views.generic.base.View

    *Methods and attributes*
        list_columns
            A list of field names to display in columns. Supports double underscore lookups.  Non-field model
            attributes and methods can be used by specifying the attribute or method name as a string. In this
            case the value of the attribute or the result of the method will be displayed in the column. However,
            sorting and filtering will not work for these columns by default. To enable sorting through an associated
            field, set the `sort_field` attribute on the method. The title of the column can be customized by adding
            a 'short_description' attribute to the method.

        list_filters
            A list of field names or `django.contrib.admin.SimpleListFilter` instances for generating filters on the list.

        list_search
            A list of field names to include in search operations. Supports double underscore lookups.

        list_transforms
            A dictionary mapping field names to functions for transforming column values before display. Transform
            functions must take two arguments `transform(value, obj)`, where `obj` is the object corresponding
            to the list row.

        list_headers
            A dictionary mapping field names to header names for explicitly specifying the column header text.

        list_styles
            A dictionary mapping field names to css style classes to add to the HTML of the columns.

        list_title
            A string to use as the title of the list. If `None` (default), the model name is used.

        link_url
            A named url for creating links to detailed pages. If `None` (default), no links are created.

        link_kwarg
            The link kwarg parameter for `link_url`. Default is 'pk'

        link_attr
            By default links are created with the url in the href attribute of an anchor tag. The attribute can be
            changed by setting the link_attr parameter of the view. For example setting `link_attr` to `data-link` will
            create a tag that looks like `<a href="#!" data-link="http://...">...</a>`.  This is useful for loading
            content using JavaScript into modals or for ajax. This parameter replaces `link_data` boolean in previous
            versions.

        link_field
            Column name on which to create links. Must be one of the names included in list_columns. By default the
            first column will be used.

        get_list_columns()
            Return the field names to display in columns. By default, simply returns the value of `list_columns`.

        get_list_filters()
            Return the list_filters to display. By default, simply returns the value of `list_filters`.

        get_list_search()
            Return the list of field names to include in search operations. By default, simply returns the value
            of `list_search`.

        get_list_transforms()
            Return the dictionary of transforms to use for the columns. By default, simply returns the value of
            `list_transforms`.

        get_list_headers()
            Return the dictionary of column headings. By default, simply returns the value of `list_headers`.

        get_list_styles()
            Return the dictionary of column css styles. By default, simply returns the value of `list_styles`.

        get_list_title()
            Return the title of the list. By default, simply returns the value of `list_title`.

        get_link_url(obj)
            Return the detail url link for the current object/row. By default, uses the named url from `link_url`, the `kwarg` from
            `link_kwarg` and the value of the attribute.

        get_link_kwarg()
            Return the `kwarg` to use for the detail `link_url`. By default, simply returns the value of `link_kwarg`.

        get_link_field()
            Return the name of the column on which to create the detail links. By default, returns the first column.

        get_link_attr()
            Return the `attr` to use for the detail `link_url`. By default, simply returns the value of `link_attr`.


Example views.py:

.. code-block:: python

    from django.utils import timezone
    from itemlist import ItemListView

    from library.models import Topic

    class TopicList(ItemListView):
        template_name = 'myapp/topic_list.html'
        model = Topic
        list_filters = ['kind', 'parent']
        list_columns = ['id', 'name', 'acronym', 'kind', 'parent__name']
        list_search = ['name', 'kind__name']
        list_headers = {'parent__name': 'Mommy'}

        link_url = 'library:topic-detail'
        link_field = 'name'
        paginate_by = 20

        def get_context_data(self, **kwargs):
            context = super().get_context_data(**kwargs)
            context['now'] = timezone.now()
            return context

Example urls.py:

.. code-block:: python

    from django.urls import path

    from library.views import TopicList

    app_label = 'library'
    urlpatterns = [
        path('', TopicList.as_view(), name='topic-list'),
    ]

Examples for myapp/topic_list.html. The default template if none is specified is exactly the same as below:

.. code-block:: django

    {% extends "base.html" %}
    {% block content %}
        {% include "itemlist/embed_list.html" %}
    {% endblock %}


Another template example, equivalent to above. This allows you to reorder/omit components.

.. code-block:: django

    {% include "itemlist/filters.html" %}
    {% include "itemlist/list.html" %}
    {% include "itemlist/pagination.html" %}


Screenshots
-----------

.. image:: docs/example-list.png
  :width: 100%
  :alt: Screenshot with list example

.. image:: docs/example-another-filter-popup.png
  :width: 100%
  :alt: Screenshot with filter popup

.. image:: docs/example-search-sort.png
  :width: 100%
  :alt: Screenshot showing search and sort

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/michel4j/django-itemlist",
    "name": "django-itemlist",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Michel Fodje",
    "author_email": "michel4j@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/fb/56/3de6a50a7daacbd9d54ace6e7282db6a250aa9bb14014a667dd3a804439a/django-itemlist-0.3.4.tar.gz",
    "platform": null,
    "description": "========\nItemList\n========\n\nItemList is a customizable Django Admin ChangeList-like app for use outside of the admin.\nIt can be used to create versatile paginated lists of objects which can be searched, filtered\nand provide links to detail pages similarly to the admin ChangeLists.\n\nProvides a generic class-based view `ItemListView`.\n\nItemListView\n------------\n\n*class itemlist.views.ItemListView*\n    A page representing a list of objects, with a search box, list filters, sortable columns, pagination and optional\n    links to detailed pages.\n\n    *Ancestors (MRO)*\n        This view inherits methods and attributes from the following Django  views:\n\n        * django.views.generic.list.ListView\n        * django.views.generic.list.MultipleObjectTemplateResponseMixin\n        * django.views.generic.base.TemplateResponseMixin\n        * django.views.generic.list.BaseListView\n        * django.views.generic.list.MultipleObjectMixin\n        * django.views.generic.base.View\n\n    *Methods and attributes*\n        list_columns\n            A list of field names to display in columns. Supports double underscore lookups.  Non-field model\n            attributes and methods can be used by specifying the attribute or method name as a string. In this\n            case the value of the attribute or the result of the method will be displayed in the column. However,\n            sorting and filtering will not work for these columns by default. To enable sorting through an associated\n            field, set the `sort_field` attribute on the method. The title of the column can be customized by adding\n            a 'short_description' attribute to the method.\n\n        list_filters\n            A list of field names or `django.contrib.admin.SimpleListFilter` instances for generating filters on the list.\n\n        list_search\n            A list of field names to include in search operations. Supports double underscore lookups.\n\n        list_transforms\n            A dictionary mapping field names to functions for transforming column values before display. Transform\n            functions must take two arguments `transform(value, obj)`, where `obj` is the object corresponding\n            to the list row.\n\n        list_headers\n            A dictionary mapping field names to header names for explicitly specifying the column header text.\n\n        list_styles\n            A dictionary mapping field names to css style classes to add to the HTML of the columns.\n\n        list_title\n            A string to use as the title of the list. If `None` (default), the model name is used.\n\n        link_url\n            A named url for creating links to detailed pages. If `None` (default), no links are created.\n\n        link_kwarg\n            The link kwarg parameter for `link_url`. Default is 'pk'\n\n        link_attr\n            By default links are created with the url in the href attribute of an anchor tag. The attribute can be\n            changed by setting the link_attr parameter of the view. For example setting `link_attr` to `data-link` will\n            create a tag that looks like `<a href=\"#!\" data-link=\"http://...\">...</a>`.  This is useful for loading\n            content using JavaScript into modals or for ajax. This parameter replaces `link_data` boolean in previous\n            versions.\n\n        link_field\n            Column name on which to create links. Must be one of the names included in list_columns. By default the\n            first column will be used.\n\n        get_list_columns()\n            Return the field names to display in columns. By default, simply returns the value of `list_columns`.\n\n        get_list_filters()\n            Return the list_filters to display. By default, simply returns the value of `list_filters`.\n\n        get_list_search()\n            Return the list of field names to include in search operations. By default, simply returns the value\n            of `list_search`.\n\n        get_list_transforms()\n            Return the dictionary of transforms to use for the columns. By default, simply returns the value of\n            `list_transforms`.\n\n        get_list_headers()\n            Return the dictionary of column headings. By default, simply returns the value of `list_headers`.\n\n        get_list_styles()\n            Return the dictionary of column css styles. By default, simply returns the value of `list_styles`.\n\n        get_list_title()\n            Return the title of the list. By default, simply returns the value of `list_title`.\n\n        get_link_url(obj)\n            Return the detail url link for the current object/row. By default, uses the named url from `link_url`, the `kwarg` from\n            `link_kwarg` and the value of the attribute.\n\n        get_link_kwarg()\n            Return the `kwarg` to use for the detail `link_url`. By default, simply returns the value of `link_kwarg`.\n\n        get_link_field()\n            Return the name of the column on which to create the detail links. By default, returns the first column.\n\n        get_link_attr()\n            Return the `attr` to use for the detail `link_url`. By default, simply returns the value of `link_attr`.\n\n\nExample views.py:\n\n.. code-block:: python\n\n    from django.utils import timezone\n    from itemlist import ItemListView\n\n    from library.models import Topic\n\n    class TopicList(ItemListView):\n        template_name = 'myapp/topic_list.html'\n        model = Topic\n        list_filters = ['kind', 'parent']\n        list_columns = ['id', 'name', 'acronym', 'kind', 'parent__name']\n        list_search = ['name', 'kind__name']\n        list_headers = {'parent__name': 'Mommy'}\n\n        link_url = 'library:topic-detail'\n        link_field = 'name'\n        paginate_by = 20\n\n        def get_context_data(self, **kwargs):\n            context = super().get_context_data(**kwargs)\n            context['now'] = timezone.now()\n            return context\n\nExample urls.py:\n\n.. code-block:: python\n\n    from django.urls import path\n\n    from library.views import TopicList\n\n    app_label = 'library'\n    urlpatterns = [\n        path('', TopicList.as_view(), name='topic-list'),\n    ]\n\nExamples for myapp/topic_list.html. The default template if none is specified is exactly the same as below:\n\n.. code-block:: django\n\n    {% extends \"base.html\" %}\n    {% block content %}\n        {% include \"itemlist/embed_list.html\" %}\n    {% endblock %}\n\n\nAnother template example, equivalent to above. This allows you to reorder/omit components.\n\n.. code-block:: django\n\n    {% include \"itemlist/filters.html\" %}\n    {% include \"itemlist/list.html\" %}\n    {% include \"itemlist/pagination.html\" %}\n\n\nScreenshots\n-----------\n\n.. image:: docs/example-list.png\n  :width: 100%\n  :alt: Screenshot with list example\n\n.. image:: docs/example-another-filter-popup.png\n  :width: 100%\n  :alt: Screenshot with filter popup\n\n.. image:: docs/example-search-sort.png\n  :width: 100%\n  :alt: Screenshot showing search and sort\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "A customizable Django Admin ChangeList-like app for use outside of the admin.",
    "version": "0.3.4",
    "project_urls": {
        "Homepage": "https://github.com/michel4j/django-itemlist"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b65e2f6dd8b1472f9e606a01dedbde3860da1956c967a5d8cc4f045ead21528e",
                "md5": "964cd188eb4677950c06d16e34ccf8b1",
                "sha256": "654a99e6a7a27bc0813a0725c93938411e5f87289ed76d84dc45a71bbf57bd5a"
            },
            "downloads": -1,
            "filename": "django_itemlist-0.3.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "964cd188eb4677950c06d16e34ccf8b1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 14331,
            "upload_time": "2024-11-21T16:34:16",
            "upload_time_iso_8601": "2024-11-21T16:34:16.779107Z",
            "url": "https://files.pythonhosted.org/packages/b6/5e/2f6dd8b1472f9e606a01dedbde3860da1956c967a5d8cc4f045ead21528e/django_itemlist-0.3.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fb563de6a50a7daacbd9d54ace6e7282db6a250aa9bb14014a667dd3a804439a",
                "md5": "2389fb7e442e58542a879eabc84523b5",
                "sha256": "78b6764af4b19f768d2163dbae772945ae69809cda45eacb752f5c6d1180c4fe"
            },
            "downloads": -1,
            "filename": "django-itemlist-0.3.4.tar.gz",
            "has_sig": false,
            "md5_digest": "2389fb7e442e58542a879eabc84523b5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 494119,
            "upload_time": "2024-11-21T16:34:18",
            "upload_time_iso_8601": "2024-11-21T16:34:18.234600Z",
            "url": "https://files.pythonhosted.org/packages/fb/56/3de6a50a7daacbd9d54ace6e7282db6a250aa9bb14014a667dd3a804439a/django-itemlist-0.3.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-21 16:34:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "michel4j",
    "github_project": "django-itemlist",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "django-itemlist"
}
        
Elapsed time: 0.44568s