Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/saxix/django-admin-extra-buttons
https://github.com/saxix/django-admin-extra-buttons
django python
Last synced: 6 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/saxix/django-admin-extra-buttons
- Owner: saxix
- License: other
- Created: 2022-02-18T10:16:19.000Z (almost 3 years ago)
- Default Branch: develop
- Last Pushed: 2024-10-30T19:58:26.000Z (about 1 month ago)
- Last Synced: 2024-12-01T06:03:41.904Z (13 days ago)
- Topics: django, python
- Language: Python
- Homepage: https://saxix.github.io/django-admin-extra-buttons/
- Size: 855 KB
- Stars: 139
- Watchers: 5
- Forks: 10
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES
- Contributing: docs/contributing.md
- License: LICENSE
Awesome Lists containing this project
- stars - saxix/django-admin-extra-buttons - (Python)
- stars - saxix/django-admin-extra-buttons - (Python)
README
django-admin-extra-buttons
==========================[![Pypi](https://badge.fury.io/py/django-admin-extra-buttons.svg)](https://badge.fury.io/py/django-admin-extra-buttons)
[![coverage](https://codecov.io/github/saxix/django-admin-extra-buttons/coverage.svg?branch=develop)](https://codecov.io/github/saxix/django-admin-extra-buttons?branch=develop)
[![Test](https://github.com/saxix/django-admin-extra-buttons/actions/workflows/test.yml/badge.svg)](https://github.com/saxix/django-admin-extra-buttons/actions/workflows/test.yml)
[![Docs](https://github.com/saxix/django-admin-extra-buttons/actions/workflows/docs.yml/badge.svg)](https://github.com/saxix/django-admin-extra-buttons/actions/workflows/docs.yml)![my image](https://raw.githubusercontent.com/saxix/django-admin-extra-buttons/develop/docs/images/screenshot.png)
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 ModelAdminIt allows easy creation of wizards, actions and/or links to external resources
as well as api only views.Four 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().How to use it
-------------```python
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_exemptclass MyModelModelAdmin(ExtraButtonsMixin, admin.ModelAdmin):
@button(permission='demo.add_demomodel1',
visible=lambda self: self.context["request"].user.is_superuser,
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):
passreturn 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
- Code: https://github.com/saxix/django-admin-extra-buttons
- Documentation: https://saxix.github.io/django-admin-extra-buttons/
- Issue Tracker: https://github.com/saxix/django-admin-extra-buttons/issues
- Download Package: https://pypi.org/project/django-admin-extra-buttons/