Skip to main content

Export action for django admin

Project description

Django Admin Export Action

Version Build status License Coverage

Export action for Django's Admin

Quickstart

Install Django Admin Export Action::

pip install django-admin-export-action

Include it in INSTALLED_APPS::

INSTALLED_APPS = [
    # ...
    'admin_export_action',
]

Add to urlpatterns in urls.py:

path('export_action/', include("admin_export_action.urls", namespace="admin_export_action")),

Configuration

By default the export action will be added sitewide, which means for every app and every admin registered model.

You can disable this behaviour and decide to add manually the export action only for the models you desired:

# settings.py

ADMIN_EXPORT_ACTION = {
    'ENABLE_SITEWIDE': False
}

# model admin
from admin_export_action.admin import export_selected_objects

class MyModelAdmin(models.ModelAdmin):
    # ...
    actions = [export_selected_objects, ]

Convert any value to its xlsx representation can be a nightmare, and you may always find something weird you haven't considered. In order to let you fix every case, you can define an hook which is called when adding a value to a cell:

# settings.py

ADMIN_EXPORT_ACTION = {
    'VALUE_TO_XLSX_CELL': 'news.admin.my_convert_function'
}

# admin.py
def my_convert_function(value):
    if (value == 'convert'):
        return True, 'converted'
    elif (type(value) == list):
        return json.dumps(value)
    return False, None

If called, the hook is called first, it shoud return a tuple success, value. If success is True, then the returned value is used, otherwise the default conversions are performed.

The intermediate admin page used to select the fields to be exported needs the extra context each admin page has. But such context depends on your admin_site instance, for example if you use django-baton the admin site is different from the default one.
For this reason you can specify the path for your admin app:

# settings.py

ADMIN_EXPORT_ACTION = {
    'ADMIN_SITE_PATH': 'baton.autodiscover.admin'
}

This assures the site title and site header ar the ones you see in normal admin pages.

Usage

Go to an admin page where the export action is enabled, select objects, run the action.

In the next page:

  • select the fields you want to export
  • select the output format
  • select whether to get raw choices values or not
  • select whether to include table header (field verbose name) or not
  • click the "Export" button

Features

  • Generic or ready to use action to enable export data from Admin.
  • Automatic traversal of model relations.
  • Selection of fields to export.
  • Can export to XSLx, CSV, JSON and HTML.

Running Tests

Does the code actually work?

cd testapp/app
source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install -r requirements.txt
(myenv) $ python manage.py test

Security

This project assumes staff users are trusted. There may be ways for users to manipulate this project to get more data access than they should have.

Credits

This project is developed by Otto srl, and originally foked from fgmacedo/django-export-action

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_admin_export_action-0.3.2.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

django_admin_export_action-0.3.2-py3-none-any.whl (23.1 kB view details)

Uploaded Python 3

File details

Details for the file django_admin_export_action-0.3.2.tar.gz.

File metadata

File hashes

Hashes for django_admin_export_action-0.3.2.tar.gz
Algorithm Hash digest
SHA256 83364565e7d0447b65bf9e595b98cbe9098ff0144883f27c1112fc68c6bcc796
MD5 9c7810ebfe374dbf1ec55a66fbc43a3c
BLAKE2b-256 c9e574d7dd3d8e980178e9893e95cac88134cebec168cc78ef9a5bca88aa103b

See more details on using hashes here.

File details

Details for the file django_admin_export_action-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_admin_export_action-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6edf3c1592522ee46912ec95818f219408348564876e66a2915107d64b719efd
MD5 a4f0d9b2eb0a9e44417ec3de74689b39
BLAKE2b-256 22f2f9fe7e531f54234ec8cd9832644185913cfaf8aa53c0f385cb9ee63937a0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page