Unexpected behavior in admin views for _popup=1

137 views
Skip to first unread message

e.generalov

unread,
Jun 26, 2014, 10:00:02 AM6/26/14
to django-d...@googlegroups.com
Hello!

In my AngularJs application I want to reuse some django admin forms (to "add", "edit" and "delete" orders) 
but show them in the iframe instead of popup windows.
 
In order to display "add" form in iframe I create a template:

<iframe src="/admin/order/order/add/?_popup=1" width="300" height="200"></iframe>
<script>
    window.dismissAddAnotherPopup = function customDismissAddAnotherPopup(window, val, obj) {
    };
</script>

And redefine admin/popup_response.html template to search dissmissAddAnotherPopup function in the window.parent (that is in iframe) too:

<!DOCTYPE html>
<html>
  <head><title></title></head>
  <body>
    <script type="text/javascript">
      (window.opener || window.parent).dismissAddAnotherPopup(window, "{{ value }}", "{{ obj }}");
    </script>
  </body>
</html>

When user submit "add" form in the iframe then django responds with `admin/popup_response.html` template 
and my JavaScript application takes notification from dismissAddAnotherPopup function. 
It works as expected.

I have a trouble then try to implement the same logic for "edit" and "delete" forms (/admin/order/order/1/?_popup=1 and /admin/order/order/1/delete/?_popup=1 urls). 
When user submit form data then Django responds with redirect to usual list of objects instead of admin/popup_response.html.

The difference is in implementation. The render_add method (https://github.com/django/django/blob/master/django/contrib/admin/options.py#L1081) takes in considiration IS_POPUP_VAR in request.POST and renders admin/popup_response.html template when _popup parameter is present. 

The delete_view method does not hides decoration (breadcrumbs and footer) then _popup is present (/admin/order/order/1/delete/?_popup=1). It was unexpected for me too.

Do you assess these features as errors and will you accept a PR to correct them?

Tim Graham

unread,
Jun 26, 2014, 2:33:40 PM6/26/14
to django-d...@googlegroups.com
The Django admin doesn't generate links to render the change or delete pages in pop-ups which is the reason this functionality wasn't implemented. While it seems like a reasonable request, I'm hesitant to add support for them because if such pages aren't in the normal admin workflow they will probably tend to get overlooked (and potentially broken) when adding new features.

Ivan Kharlamov

unread,
Jun 27, 2014, 12:02:05 AM6/27/14
to django-d...@googlegroups.com
> takes in considiration IS_POPUP_VARinrequest.POST and
> renders admin/popup_response.html template when _popup parameter is
> present.
> But the response_change
> (https://github.com/django/django/blob/master/django/contrib/admin/options.py#L1128)
> and response_delete
> (https://github.com/django/django/blob/master/django/contrib/admin/options.py#L1271) methods
> does not. It was unexpected for me.
>
> The delete_viewmethod does not hides decoration (breadcrumbs and footer)
> then _popup is present (/admin/order/order/1/delete/?_popup=1). It was
> unexpected for me too.
>
> Do you assess these features as errors and will you accept a PR to
> correct them?

You might be interested in django-admin2, which should be considerably
easier to integrate with AngularJS because it has REST API built in.

https://github.com/pydanny/django-admin2

> --
> You received this message because you are subscribed to the Google
> Groups "Django developers" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-develop...@googlegroups.com
> <mailto:django-develop...@googlegroups.com>.
> To post to this group, send email to django-d...@googlegroups.com
> <mailto:django-d...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/django-developers.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/5ae48bd4-4aba-4b03-8d54-baf2b279c08d%40googlegroups.com
> <https://groups.google.com/d/msgid/django-developers/5ae48bd4-4aba-4b03-8d54-baf2b279c08d%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages