• Stars
    star
    141
  • Rank 259,971 (Top 6 %)
  • Language
    Python
  • License
    BSD 3-Clause "New...
  • Created over 13 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Django app enabling painless creation of additional admin object tools.

Django Object Tools

Django app enabling painless creation of additional admin object tools.

https://coveralls.io/repos/github/praekelt/django-object-tools/badge.svg?branch=develop

docs/images/example-tools.png

Requirements

  1. Python 2.7, 3.5-3.7
  2. Django 1.11, 2.0, 2.1

Installation

  1. Install or add django-object-tools to your python path.

  2. Add object_tools to your INSTALLED_APPS setting. django-object-tools overrides certain admin templates so you have to add it before django.contrib.admin.

  3. Hook up URLConf. Do this by pointing a given URL at the tools.urls method. In this example, we register the default Tools instance object_tools.tools at the URL /object-tools/:

    # urls.py
    from django.conf.urls.defaults import *
    from  django.conf.urls import url
    import object_tools
    
    urlpatterns = [
        path('object-tools/', object_tools.tools.urls)
    ]
  4. Obviously Django Admin itself needs to be installed, as described here.

  5. Remember to run migrate whenever you install new tools to setup permissions.

Usage

django-object-tools itself doesn't do much in terms of providing useful tools. Its purpose is to simplify creation and integration of custom tools delivered by other Django applications. To that end it takes care of the messy details like permissions and admin template integration so you can focus on the fun stuff.

As an example lets create a tool allowing you to delete all objects. Yes this is a bit convoluted but it's a good toy example for illustration purposes. Have a look at django-export and django-order for examples of real world tools leveraging django-object-tools.

Firstly create a Django app folder structure as per usual, with the root directory named delete, including a file called tools.py. It should look as follows:

delete/
    __init__.py
    tools.py

Edit tools.py to look like this:

from django.contrib.admin.actions import delete_selected
from django.contrib.admin.sites import site
import object_tools

class Delete(object_tools.ObjectTool):
    name = 'delete'
    label = 'Delete all'

    def view(self, request, extra_context=None):
        queryset = self.model.objects.all()
        modeladmin = site._registry.get(self.model)
        response = delete_selected(modeladmin, request, queryset)
        if response:
            return response
        else:
            return modeladmin.changelist_view(request)

object_tools.tools.register(Delete)

Let's go through that line by line:

  1. object_tools behaves similarly to Django's admin allowing you to explicitly register tools, see line 17. It also provides the ObjectTool base class.
  1. import delete_selected method provided by Django. This method will do all the heavy lifting.
  1. Create a tool class inheriting from object_tools.ObjectTool. All object tools have to inherit from object_tools.ObjectTool. ObjectTool provides various methods to simplify creation of tools. See object_tools.options.py for more details.
  2. Set tool name to delete. This has to be a unique name identifying the tool. This is used to uniquely identify the tool internally and for instance to setup permissions.
  3. Set label to Delete all. The label is displayed within admin and not the name, thus allowing you to specify a more verbose, user friendly label.
  1. Implement view method. This is the brains of your tool. The view method is called when the user executes your tool, so your tool logic would go here. This can be any view like code, as long as it returns an HttpResponse object. In this case we wrap Django's built-in delete_selected to provide the form, logic and template code to perform the actual delete.
  1. Register the tool with object_tools, thus enabling its display in admin.

To enable the tool add delete to your INSTALLED_APPS setting.

Now when you navigate to the change list view of any model you'll find the delete all object tool in the upper right hand corner.

docs/images/delete-example-final.png

Clicking on the Delete all tool fires off the view and proceeds with deleting objects as per usual.

Note: django-object-tools adds per tool permissions to the built-in set of default Django permissions. So in this example only superusers or users who have the the Can delete <model> permission will be able to see and use the tool. If you can't see or use a particular tool make sure the authenticated user has the required permissions to do so.

More Repositories

1

django-likes

Django app providing view interface to django-secretballot.
Python
77
star
2

django-preferences

Django app allowing users to set app specific preferences through the admin interface.
Python
56
star
3

django-photologue

Powerful image management for the Django web framework.
Python
53
star
4

swagger-django-generator

Convert Swagger specifications into Django or aiohttp code
Python
51
star
5

django-category

Django categorize content app.
Python
46
star
6

django-setuptest

Simple test suite enabling Django app testing via $ python setup.py test.
Python
43
star
7

django-export

Django app allowing for filtered exporting of model object data.
Python
40
star
8

django-analytics

JavaScript
33
star
9

python-sshtail

Python library tailing file(s) via SSH.
Python
31
star
10

django-googlesearch

Django Google custom search engine app.
Python
29
star
11

django-ultracache

Drop-in replacement for Django's template fragment caching. Provides automatic cache invalidation.
Python
27
star
12

django-simple-autocomplete

Django app adding painless autocomplete to admin.
Python
23
star
13

django-generate

Django slightly smarter than fixtures content generation app.
Python
20
star
14

django-multicore

A framework that makes it easy to parallelize Django code
Python
19
star
15

django-south-admin

Django app allowing for South management through Admin.
Python
19
star
16

django-sharing

Django row level object sharing app.
Python
16
star
17

react-web-chat

A react-based instant message interface.
JavaScript
14
star
18

django-admin-api

Expose Django's admin as a RESTful service
JavaScript
14
star
19

jmbo

Jmbo base app.
Python
13
star
20

django-order

Django app allowing users to manually order objects via admin.
Python
13
star
21

panya

Panya base app.
Python
12
star
22

django-cache-headers

Configurable middleware to add HTTP caching headers for URL's.
Python
11
star
23

python-ssmi

Python module for TruTeq's proprietary SSMI interface for USSD and SMS
Python
10
star
24

nginx-ua-instance-switcher

Buildout configuring Nginx for desktop/mobile instance switching as described on http://www.28lines.com/?p=11
Python
10
star
25

sentry-deploy

Simple sentry provision and deploy scripts.
Puppet
10
star
26

django-publisher

Django targeted publishing through view layouts and widgets app.
Python
10
star
27

django-atlas

Geolocation models, data and tools using GeoDjango
Python
10
star
28

django-richcomments

Django app extending the builtin comments framework for AJAX style commenting.
JavaScript
9
star
29

django-moderator

Django Bayesian inference based comment moderation app.
Python
9
star
30

feersum-nlu-api-wrappers

Swagger spec and generated Python language wrappers for the FeersumNLU HTTP Rest API for building intelligent chatbots.
Python
9
star
31

django-livechat

Live chat module that integrates with django
Python
8
star
32

multicore

A module that makes it easy to parallelize Python code
Python
8
star
33

device-proxy

Inspect an incoming HTTP request and add extra headers or cookies. Useful for mobile device User-Agent inspection.
Python
8
star
34

feersum-lid-shared-task

Jupyter Notebook
8
star
35

panya-chart

Panya chart app.
Python
7
star
36

panya-contact

Panya contact form app.
Python
7
star
37

sideloader

Turn special github repos into deb files and whack them into a repo.
Python
7
star
38

panya-banner

Panya banner app.
Python
6
star
39

django-section

Django app for determining site section by request.
Python
6
star
40

panya-social

Panya social app.
Python
6
star
41

panya-event

Panya event app.
Python
6
star
42

pureftp-completeuploadscript

PureFTP upload script creating a .complete file on complete file upload.
Shell
6
star
43

panya-show

Panya show app.
Python
6
star
44

panya-gallery

Panya gallery app.
JavaScript
6
star
45

panya-competition

Panya competition app.
Python
6
star
46

django-poll

Django poll app.
Python
5
star
47

django-responsive-image

Provides a template tag that implements picture, srcset and lazy loading. Supports django-photologue.
Python
5
star
48

django-pagemenu

Django app for page menus with items altering querysets or linking directly to other views.
Python
5
star
49

django-insight

Python
5
star
50

django-profile

Django user profile app.
Python
5
star
51

django-google-credentials

Python
5
star
52

panya-music

Panya music app.
Python
5
star
53

panya-post

Panya post app.
Python
5
star
54

django-scaler

Degrade gracefully by automatically replacing heavy pages with static pages while a server is taking strain.
Python
5
star
55

panya-calendar

Panya calendar app.
Python
4
star
56

kraken

A load testing interface for Tsung
JavaScript
4
star
57

django-orderedrelations

Django app allowing to sort relationships via admin inlines.
Python
4
star
58

switchboard-go

switchboard-go
JavaScript
4
star
59

djangorestframework-extras

Python
4
star
60

switchboard-api

switchboard-api
Python
4
star
61

sapphire

A js library for drawing dashboard widgets
JavaScript
4
star
62

django-userprofile

Django user profile app.
Python
4
star
63

django-football365

Fetch logs, fixtures, results and live scores via the Football 365 API.
Python
4
star
64

swagger-aor-generator

Convert Swagger specifications into a simple Admin on Rest client.
JavaScript
4
star
65

django-formfactory

Dynamic django form builder.
Python
4
star
66

setsquare

JavaScript
4
star
67

rwc-feersum-client

A feersum client for react-web-chat
JavaScript
4
star
68

ummeli

Python
4
star
69

jmbo-paste

Python Paste templates creating Jmbo Buildout environments.
Python
3
star
70

autoload

Simple HTTPerf loadtest runner with pretty output.
Python
3
star
71

vumi-ureport

A vumi jsbox application for the Ureport project
JavaScript
3
star
72

jmbo-friends

Friends and badges for Jmbo
Python
3
star
73

jmbo-twitter

Python
3
star
74

mote

Mote - the pattern library framework.
JavaScript
3
star
75

mobius-skeleton

Bootstrap a Mobius project
Python
3
star
76

django-dfp

DFP implementation for Django
HTML
3
star
77

jmbo-gallery

Jmbo gallery app.
Python
3
star
78

go-jsbox-location

Location finder for go-jsbox
JavaScript
2
star
79

jmbo-chart

Jmbo chart app.
Python
2
star
80

mote-lib-base

The base set of patterns for Mote
HTML
2
star
81

eslint-config

JavaScript
2
star
82

fed-toolbox

JavaScript
2
star
83

mobius

Python
2
star
84

jmbo-football

Football app fro Jmbo
Python
2
star
85

stylelint-config

JavaScript
2
star
86

panya-docs

Panya documentation
Python
2
star
87

jmbo-comments

Comments module as subtracted from YoungAfricaLive
Python
2
star
88

vumi-freeswitch-esl

A Freeswitch eventsocket transport for Vumi.
Python
2
star
89

jmbo-competition

Jmbo competition app.
Python
2
star
90

vxpolls

Vumi polls framework
Python
2
star
91

jmbo-polls

2
star
92

django-layers

Serve different templates and static files for eg. mobi and web. Layers can be stacked to enable resource re-use..
Python
2
star
93

jenkins-provision

Ngionx conf, puppet manifest etc.. for setting up Jenkins.
Shell
2
star
94

django-gizmo

Django app allowing for configurable targetting of template inclusion tags.
Python
2
star
95

panya-playlist

Panya playlist app.
Python
2
star
96

vumi-open-campaigns

open source campaigns developed with Vumi
2
star
97

vumi-twilio-api

Provides a REST API to vumi that emulates the twilio API.
Python
2
star
98

panya-tube

Panya tube(channel, show, clip) app.
Python
2
star
99

jmbo-calendar

Jmbo calendar app.
Python
2
star
100

jmbo-vlive

Jmbo library for the Vodafone Live platform
2
star