Code Monkey home page Code Monkey logo

django-admin-extra-buttons's People

Contributors

domdinicola avatar micahlyle avatar saxix avatar tvanesse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

django-admin-extra-buttons's Issues

Add the possibility to download a file from a button handler

Hello,

I have a case where I'd like a button to download a file by returning a FileResponse. However, the current code checks if something else than a HttpResponse is given and Redirects in that case :

if not isinstance(ret, HttpResponse):
return HttpResponseRedirectToReferrer(request)
return ret

I made a quick and dirty patch locally to test replacing line 52 with if not isinstance(ret, (FileResponse, HttpResponse)): and this did the trick for me.

I wondered if there was something else I wasn't aware of and if there was a reason not to give the opportunity to send back files from your excellent Django app. Otherwise, would you mind if I open a PR with this modification ?

Thanks for the excellent work,
Cheers

Sébastien

@button(enabled=False) is still clickable

Hello! Thanks for the useful library. I've tried it out and I've found a few issues. Let's start with the first one.

class MyModelModelAdmin(ExtraButtonsMixin, admin.ModelAdmin):
    @button(enabled=False)
    def send_newsletter_now(self, request):
        self.message_user(request, 'The newsletter emails were sent successfully.')

The button is greyed out, but is still clickable. It should be disabled.

Request: change text of @button

Hello and thank you for this necessary django library :)

I wish I could rename a button, here, the "Refresh" button, for example "Mettre à jour", etc.

Thank you :)

Feature request: confirm_action, but with configurable choices

The confirm action is useful when the user is presented with one option and some information about the action.

For some cases it could be useful to present the user with multiple options. A further extension to this could be to add some description on each option.

Some mockup:

**Do you want to mark order 123 from customer [email protected] as paid?**

<Button: Mark as paid without sending receipt>
Will only mark as paid. 


<Button: Mark as paid and send receipt>
Will send an email after marking the order as paid

API

    @button(
        label="Manage payment",
    )
    def mark_as_paid(self, request, pk):
        order: shop.models.Order = self.get_object(request, pk)

        @multi_action(label="Mark as paid without sending receipt", description="Will only mark as paid.") 
        def _action_charge_order(_request):
            order.charge()
            self.message_user(_request, message="Charged.")

        @multi_action(label="Mark as paid and send receipt", description="Will send an email after marking the order as paid.")
        def _action_charge_order_and_email(_request):
            order.charge_and_email()
            self.message_user(_request, message="Charged and emailed.")

        return confirm_action(
            self,
            request,
            actions=[_action_charge_order, _action_charge_order_and_email],
            message=f"Do you want to mark order {order.pk} from customer {order.custome} as paid",
        )

permission property hides the button permanently

I've tried permission property and it seems it hides the button no matter what value is provided from the permission function.

@register(MyModel)
class MyModelAdmin(ExtraButtonsMixin, admin.ModelAdmin):

    @button()
    def delete_all(self, request):
        pass

a simple button

@register(MyModel)
class MyModelAdmin(ExtraButtonsMixin, admin.ModelAdmin):

    @button(permission=lambda request, obj: False)
    def delete_all(self, request):
        pass

the button is hidden.

@register(MyModel)
class MyModelAdmin(ExtraButtonsMixin, admin.ModelAdmin):

    @button(permission=lambda request, obj: True)
    def delete_all(self, request):
        pass

the button is still hidden (why?)

Add example of error message to docs

a success message:
self.message_user(request, 'It was successful.')

an error message:
from django.contrib import messages
and
self.message_user(request, 'It failed.', messages.ERROR)

@button(disable_on_click=True) is not working

disable_on_click does not work for me at all.

class MyModelModelAdmin(ExtraButtonsMixin, admin.ModelAdmin):
    @button(disable_on_click=True)
    def send_newsletter_now(self, request):
        time.sleep(10)
        self.message_user(request, 'The newsletter emails were sent successfully.')

The button is still clickable after first click (while loading the page).

How do you use `@choice`? Can you provide a working example?

I guess the title is self-explanatory. There is no example for this decorator in the documentation.

I've tried something like

    @view(label="VIEW 1")
    def select_view_button(self, request, obj=None):
        # Implement any logic you need
        return HttpResponse("Selected view button clicked!")

    @view(label="VIEW 2")
    def select_view_button2(self, request, obj=None):
        # Implement any logic you need
        return HttpResponse("Selected view 2 button clicked!")

    @choice(
        label="Select View",
        choices=[select_view_button, select_view_button2],
        change_form=True,
        change_list=False,
    )
    def group_views(self, request, obj=None):
        # Implement any logic you need
        return HttpResponse("Selected view button clicked!")

But it keeps complaining that 'ChoiceButton' object has no attribute 'choices'.

My simple (but not perfect) solution for the broken buttons alignment

reference to the closed issue #12

I've created a custom mixin with override styles for object-tools block (extra buttons are rendering there)

class CustomExtraButtonsMixin(ExtraButtonsMixin):
    """
    Extra buttons mixin with buttons layout fix.
    """
    class Media:
        css = {
            'all': ('css/admin/extra-buttons/buttons-layout.css',)
        }

and buttons-layout.css:

.object-tools {
    font-size: 0.625rem;
    font-weight: bold;
    /* Disable default styles */
    padding-left: 0;
    float: none;
    position: unset;
    margin-top: 0;

    /* Custom styles to fix layout */
    display: flex;
    flex-wrap: wrap;
    padding-bottom: 16px;
    gap: 16px;
    justify-content: flex-start;
}

@media (max-width: 767px) {
    .object-tools li + li {
        margin-left: 0!important;
    }
}

Result:

Screenshot_20240119_000230

and responsive:

Screenshot_20240119_000421

Originally posted by @senabo in #12 (comment)

Button Alignment

When I add a new button, it is automatically adding horizontally, if the option for alignment of all buttons, it will be useful, like this;
image

question: ability to use outside of models?

Love this library, solved a problem I had in a few lines of code. Thanks for building it.

The docs say "add custom buttons to Django Admin pages and/or add views to any ModelAdmin" but all I can find in the examples is the mixin for adding things to a ModelAdmin. Is there a way to use the buttons somewhere not associated with a Model?

If not, feature request :)

Thanks again for sharing this useful code.

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.