django-etc icon indicating copy to clipboard operation
django-etc copied to clipboard

Submit input value not in request.POST

Open zN3utr4l opened this issue 1 year ago • 12 comments

I added some more buttons in the submit_line.html as different guides say (https://stackoverflow.com/questions/67463654/add-custom-button-near-save-button-django-admin, you%20need%20to%20override%20%22change_form.).

I just don't get the value of the button I pressed, I noticed that it works with all django models, except with the admins created with etc.admin.CustomModelPage.

Not even if I try to activate the save buttons, etc like this:

def view_custom(self, request):
        context: dict = {
            'show_save_and_continue': True,
            'show_save_and_add_another': True,
            'show_save_as_new': True,
            'show_save': True,
            .........
          return self._changeform_view(request, object_id=None, form_url='', extra_context=context)

The value of the submit on click is not passed.

zN3utr4l avatar Aug 09 '23 14:08 zN3utr4l

I just don't get the value of the button I pressed, [...]

And how and there do you try to get that value? What's in self.bound_request.POST in model.save()?

idlesign avatar Aug 10 '23 01:08 idlesign

in Admin response_add:

def response_add(self, request, obj):
        a4 = request.POST.get('_button_name')
        if '_button_name' in request.POST:
            self.test(request, obj)

        return super().response_add(request, obj) 

zN3utr4l avatar Aug 10 '23 06:08 zN3utr4l

But model.save() is called before response_add.

idlesign avatar Aug 10 '23 06:08 idlesign

image

There is nothing here either, even if I try to use django's default buttons, _save, _saveasnew, _continue, they are not taken in this POST

zN3utr4l avatar Aug 10 '23 07:08 zN3utr4l

There is nothing here either, [...]

Use F12 in broswer developer console to see what data is actually submitted to server. N.b.: only a value of the pressed button is submitted (not others).

idlesign avatar Aug 10 '23 07:08 idlesign

image

image

Already seen, the first image refers to an admin created with your library, it does not send me information about the button, the second refers to an admin created via django and sends me information about the button.

zN3utr4l avatar Aug 10 '23 07:08 zN3utr4l

Already seen, the first image refers to an admin created with your library, it does not send me information about the button, [...]

It's time to look at the html: 1. one that sends; 2. another that fails to send. Please save those and attach here.

idlesign avatar Aug 10 '23 07:08 idlesign

I just override submit_line.html like this:

{% load i18n admin_urls %}
<div class="submit-row">
{% block submit-row %}
{% if testbla %}<input type="submit" value="{% translate 'test 2' %}" name="_test 2">{% endif %}
{% if testblabla %}<input type="submit" value="{% translate 'test' %}" name="_test">{% endif %}
{% if show_save %}<input type="submit" value="{% translate 'Save' %}" class="default" name="_save">{% endif %}
{% if show_delete_link and original %}
    {% url opts|admin_urlname:'delete' original.pk|admin_urlquote as delete_url %}
    <p class="deletelink-box"><a href="{% add_preserved_filters delete_url %}" class="deletelink">{% translate "Delete" %}</a></p>
{% endif %}
{% if show_save_as_new %}<input type="submit" value="{% translate 'Save as new' %}" name="_saveasnew">{% endif %}
{% if show_save_and_add_another %}<input type="submit" value="{% translate 'Save and add another' %}" name="_addanother">{% endif %}
{% if show_save_and_continue %}<input type="submit" value="{% if can_change %}{% translate 'Save and continue editing' %}{% else %}{% translate 'Save and view' %}{% endif %}" name="_continue">{% endif %}
{% if show_close %}<a href="{% url opts|admin_urlname:'changelist' %}" class="closelink">{% translate 'Close' %}</a>{% endif %}
{% endblock %}
</div>

Only these 2 lines have been added, the template is from django 3.2.20

{% if testbla %}<input type="submit" value="{% translate 'test 2' %}" name="_test 2">{% endif %}
{% if testblabla %}<input type="submit" value="{% translate 'test' %}" name="_test">{% endif %}

image

image

zN3utr4l avatar Aug 10 '23 07:08 zN3utr4l

The rendered html I meant, not the templates.

idlesign avatar Aug 10 '23 07:08 idlesign

I updated the first comment, the first image is from the admin with etc, the second is not

zN3utr4l avatar Aug 10 '23 07:08 zN3utr4l

Were you able to replicate the problem?

zN3utr4l avatar Aug 10 '23 09:08 zN3utr4l

I see to reason for an html not to send the data. My guess is that you're trying to compare two different cases: one from edit page, another from a popup or something (thence the Close link). Please compare the same pages with and w/o django-etc: chances that the behaviour is not related to the app, since the app doesn't do anything with templates.

idlesign avatar Aug 11 '23 02:08 idlesign