GithubHelp home page GithubHelp logo

benjaminrigaud / django-admincommand Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sbussetti/django-admincommand

0.0 2.0 0.0 133 KB

Launch django management commands from the admin

Python 93.55% HTML 6.45%

django-admincommand's Introduction

Django-AdminCommand

Django-AdminCommand is a Django application that makes it possible to run Django management commands from the admin.

Dependencies

  • django-async
  • django-sneak

Settings

You need to activate the Django admin in the settings and urls.py depending on your needs the configuration may vary, refer to the Django documentation related to the admin application.

Don't forget to add the application where you defined management commands in the list of installed applications. This might be already done but it might not be the case if you use an application to gather all the management commands that must be admin commands.

Make magic happens

Create a Django Management Command:

# ./music/management/commands/lyrics.py


class Command(BaseCommand):
    help = "Compute lyrics based an bitorological fluctuations"

    def handle(self, *args, **options):
        # algorithm that generated lyrics based on a title and a dictionary

Then you will have to create a configuration class for the command:

# ./music/admincommands.py

from admincommands.models import AdminCommand


class Lyrics(AdminCommand):

     class form(forms.Form):
         title = forms.CharField()

     def get_command_arguments(self, forms_data):
         return [forms_data['title']], {}

And all is well, the new admin command will be available under the «Admin Command» area of the administration of the default admin site.

If you use custom admin site, don't forget to register admincommand.models.AdminCommand to the admin site object.

Asynchronous tasks

If you want to execute commands asynchronously you have to specify it in the AdminCommand configuration class with the asynchronous property set to True:

# ./music/admincommands.py

from admincommands.models import AdminCommand


class Fugue(AdminCommand):

     asynchronous = True

     class form(forms.Form):
         title = forms.CharField()

     def get_command_arguments(self, forms_data):
         return [forms_data['title']], {}

You also need to run periodically flush_queue from django-async application for that matter don't forget to install the application.

Permissions

You MUST add to every user or groups that should have access to the list of commands «Can change admincommand» permission. Every admin command gets it's own permission «Can Run AnAdminCommand», so you can add it to proper users or group. Users will only see and be able to execute admin commands for which they have the permission.

django-admincommand's People

Contributors

amirouche avatar diox avatar sbussetti avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.