[Django] #28068: Allow customizing popup window for selecting related objects in django admin

17 views
Skip to first unread message

Django

unread,
Apr 11, 2017, 3:27:52 AM4/11/17
to django-...@googlegroups.com
#28068: Allow customizing popup window for selecting related objects in django
admin
-----------------------------------------+------------------------
Reporter: tonnzor | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
In Django admin when you select related object in Django admin -- it shows
you popup window. Size of this popup is hardcoded to 800x500 px and does
not always match user expectations. It would be great to allow changing it
at least system-wide.

Proposal:

1. Provide a setting to change default popup size
2. Use some global Javascript variable for storing popup size so we could
override per page

Sample application:

{{{
#!python
# models.py

class Author(models.Model):
name = models.CharField(max_length=100)


class Book(models.Model):
author = models.ForeignKey(Author)
name = models.CharField(max_length=100)

# admin.py

@admin.register(Author)
class AuthorAdmin(admin.ModelAdmin):
pass


@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
raw_id_fields = ('author',)

}}}


Source code:
{{{
#!javascript
// RelatedObjectLookups.js

function showAdminPopup(triggeringLink, name_regexp, add_popup) {
var name = triggeringLink.id.replace(name_regexp, '');
name = id_to_windowname(name);
var href = triggeringLink.href;
if (add_popup) {
if (href.indexOf('?') === -1) {
href += '?_popup=1';
} else {
href += '&_popup=1';
}
}
var win = window.open(href, name,
'height=500,width=800,resizable=yes,scrollbars=yes');
win.focus();
return false;
}

//-----------------------------------------^ here it is

}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28068>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 11, 2017, 5:19:14 AM4/11/17
to django-...@googlegroups.com
#28068: Allow customizing popup window for selecting related objects in django
admin
-------------------------------+--------------------------------------

Reporter: tonnzor | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by tonnzor):

It is the workaround I had to add via base.html (does not work well with
Firefox and not smooth):

{{{
#!javascript

function resize_for_popup() {
if(/[?&]_popup=1(&|$)/.test(location.href)) {
// In Firefox you may need to set (via about:config):
dom.disable_window_move_resize = false
var reference = window.opener || screen;
var width = parseInt(reference.outerWidth * 2 / 3);
var height = parseInt(reference.outerHeight * 2 / 3);
window.resizeTo(width, height);
}
}

resize_for_popup();
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28068#comment:1>

Django

unread,
Apr 11, 2017, 1:33:34 PM4/11/17
to django-...@googlegroups.com
#28068: Allow customizing popup window for selecting related objects in django
admin
-------------------------------+--------------------------------------

Reporter: tonnzor | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Tim Graham):

Could you elaborate on "does not always match user expectations"? Maybe it
makes sense to change the default since monitor resolution has increased
over the years. I'm not sure if adding a setting for this is really
needed.

--
Ticket URL: <https://code.djangoproject.com/ticket/28068#comment:2>

Django

unread,
Apr 12, 2017, 5:48:34 AM4/12/17
to django-...@googlegroups.com
#28068: Allow customizing popup window for selecting related objects in django
admin
-------------------------------+--------------------------------------

Reporter: tonnzor | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by tonnzor):

Users expect something bigger than 800x500. It is hard to suggest a single
resolution for everyone -- some users have 1280x768, others have 1920x1080
monitors.

Another alternative is to calculate popup size in runtime by JavaScript
according to user screen size. We could reuse parts of my workaround (it
generates 2/3 of size of source window or screen).

--
Ticket URL: <https://code.djangoproject.com/ticket/28068#comment:3>

Django

unread,
Apr 12, 2017, 7:43:35 AM4/12/17
to django-...@googlegroups.com
#28068: Allow customizing popup window for selecting related objects in django
admin
-------------------------------+-----------------------------------------

Reporter: tonnzor | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Someday/Maybe

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+-----------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Someday/Maybe


Comment:

Maybe you could raise the idea on the DevelopersMailingList and ask for
ideas.

--
Ticket URL: <https://code.djangoproject.com/ticket/28068#comment:4>

Django

unread,
Oct 12, 2022, 9:35:07 AM10/12/22
to django-...@googlegroups.com
#28068: Allow customizing popup window for selecting related objects in django
admin
-------------------------------------+-------------------------------------
Reporter: Artem Skoretskiy | Owner: nobody

Type: New feature | Status: new
Component: contrib.admin | Version: dev

Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Someday/Maybe
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by oko-x):

Pretty simple is also to leave the browser to open it in new tab. Full
size of the browser is usually good sizing in admin as the user is not
taken out of context by popup.

{{{
var win = window.open(href, name);
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28068#comment:5>

Reply all
Reply to author
Forward
0 new messages