• Stars
    star
    133
  • Rank 272,600 (Top 6 %)
  • Language
    Python
  • License
    Other
  • Created over 2 years ago
  • Updated 4 months ago

Reviews

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

Repository Details

django-admin-extra-buttons

Pypi coverage Test Docs

my image

This is a full rewriting of the original django-admin-extra-url. It provides decorators to easily add custom buttons to Django Admin pages and/or add views to any ModelAdmin

It allows easy creation of wizards, actions and/or links to external resources as well as api only views.

Three decorators are available:

  • button() to mark a method as extra view and show related button
  • link() This is used for "external" link, where you don't need to invoke local views.
  • view() View only decorator, this adds a new url but do not render any button.
  • choice() Menu like button, can be used to group multiple @views().

Install

pip install django-admin-extra-buttons

After installation add it to INSTALLED_APPS

INSTALLED_APPS = (
   ...
   'admin_extra_buttons',
)

How to use it

from admin_extra_buttons.api import ExtraButtonsMixin, button, confirm_action, link, view
from admin_extra_buttons.utils import HttpResponseRedirectToReferrer
from django.http import HttpResponse, JsonResponse
from django.contrib import admin
from django.views.decorators.clickjacking import xframe_options_sameorigin
from django.views.decorators.csrf import csrf_exempt

class MyModelModelAdmin(ExtraButtonsMixin, admin.ModelAdmin):

    @button(permission='demo.add_demomodel1',
            change_form=True,
            html_attrs={'style': 'background-color:#88FF88;color:black'})
    def refresh(self, request):
        self.message_user(request, 'refresh called')
        # Optional: returns HttpResponse
        return HttpResponseRedirectToReferrer(request)
    
    @button(html_attrs={'style': 'background-color:#DC6C6C;color:black'})
    def confirm(self, request):
        def _action(request):
            pass

        return confirm_action(self, request, _action, "Confirm action",
                          "Successfully executed", )

    @link(href=None, 
          change_list=False, 
          html_attrs={'target': '_new', 'style': 'background-color:var(--button-bg)'})
    def search_on_google(self, button):
        original = button.context['original']
        button.label = f"Search '{original.name}' on Google"
        button.href = f"https://www.google.com/?q={original.name}"

    @view()
    def select2_autocomplete(self, request):
        return JsonResponse({})

    @view(http_basic_auth=True)
    def api4(self, request):
        return HttpResponse("Basic Authentication allowed")

    @view(decorators=[csrf_exempt, xframe_options_sameorigin])
    def preview(self, request):
        if request.method == "POST":
            return HttpResponse("POST")
        return HttpResponse("GET")
            

Project Links

More Repositories

1

django-adminactions

collection of useful django actions to use with ModelAdmin or AdminSite.
Python
680
star
2

django-concurrency

Optimistic lock implementation for Django. Prevents users from doing concurrent editing.
Python
414
star
3

django-iadmin

WARNING: This project is not maintained anymore.
JavaScript
42
star
4

django-adminfilters

Python
39
star
5

django-geo

django application to manage administrative geographical info (country, city, region ...)
Python
27
star
6

django-webcam

UNMAINTAINED: this project is not currently active. no plan to restart it soon
Python
25
star
7

django-admin-extra-urls

Single mixin class to easily add buttons on any Django ModelAdmin related page
Python
25
star
8

django-site-maintenance

django app to put web site in 'maintenance mode'
Python
21
star
9

drf-api-checker

DjangoRestFramework contract integrity checker
Python
20
star
10

django-strategy-field

Strategy Pattern with Django models
Python
15
star
11

django-workflows

fork of bitbucket project
Python
7
star
12

django-smart-admin

Python
5
star
13

django-uuid-pk

django uuidfield that can be used as primary key
Python
5
star
14

django-whatsnew

Simple application to manage "what's new" welcome screen based on package version.
Python
5
star
15

django-nojs

simple application to manage "javascript disabled" browser
5
star
16

django-buildhost

fabric scripts to create a totally OS independend Apache/python/Django stack
Python
5
star
17

django-extra-fields

additional django fields
Python
4
star
18

django-easy-reports

Python
4
star
19

django-regex

Fields and utilities to work with regular expression in Django
Python
3
star
20

stefanoapostolico.com

HTML
3
star
21

devpi-theme-16

devpi custom theme
CSS
3
star
22

pyppi

Python
3
star
23

lazo

small utility to interact with Rancher API
Python
2
star
24

pdfcli

simple command line tool to work with pdf
Python
2
star
25

django-sysinfo

Simple django app to expose system infos: libraries version, database server version...
Python
2
star
26

drf-querystringfilter

DjangoRestFramework Filter based on URL querystring arguments
Python
2
star
27

django-excel-data-sync

Python
1
star
28

django-anonymoususer-permissions

Small backend to grant permission to Anonymous users using django admin interface
Python
1
star
29

docker-flower

Smarty
1
star
30

django-project-settings

Store django settings into database
Python
1
star
31

drf-dynamic-serializer

Python
1
star
32

django-mb

Django app to send updates/creations/deletions to a message broker.
Python
1
star
33

django-ichangelist

Python
1
star
34

flower_oauth_azure

Azure OAUth Login Handler
Python
1
star
35

flex-registration

Python
1
star