Permalink
Browse files

Change field label on page when object is changed via popup.

  • Loading branch information...
1 parent fdbc6cb commit 9aeab948476c3cbdd236cea355cb523f4e434467 Mart Somermaa committed Jan 13, 2010
Showing with 10 additions and 12 deletions.
  1. +1 −1 AUTHORS
  2. +3 −3 django/contrib/admin/media/js/admin/RelatedObjectLookups.js
  3. +6 −8 django/contrib/admin/options.py
View
@@ -69,6 +69,7 @@ answer newbie questions, and generally made Django that much better:
Esdras Beleza <linux@esdrasbeleza.com>
Chris Bennett <chrisrbennett@yahoo.com>
James Bennett
+ Marco Beri <marcoberi@gmail.com>
Julian Bez
Arvis Bickovskis <viestards.lists@gmail.com>
Natalia Bidart
@@ -80,7 +81,6 @@ answer newbie questions, and generally made Django that much better:
Matías Bordese
Sean Brant
Andrew Brehaut <http://brehaut.net/blog>
- Marco Beri <marcoberi@gmail.com>
brut.alll@gmail.com
btoll@bestweb.net
Jonathan Buchanan <jonathan.buchanan@gmail.com>
@@ -37,9 +37,9 @@ function windowname_to_id(text) {
}
function showRelatedObjectPopup(triggeringLink) {
- // TODO: use proper id in name to update the label on change
- // see admin/options.py#641
- return openPopupWindow(triggeringLink.href, '_popup', 'showrelatedobject');
+ var name = triggeringLink.parentNode.id.replace(/^view_lookup_/, '');
+ name = id_to_windowname(name);
+ return openPopupWindow(triggeringLink.href, '_popup', name);
}
function showRelatedObjectLookupPopup(triggeringLink) {
@@ -5,7 +5,7 @@
from django.contrib.contenttypes.models import ContentType
from django.contrib.admin import widgets
from django.contrib.admin import helpers
-from django.contrib.admin.util import unquote, flatten_fieldsets, get_deleted_objects, model_ngettext, model_format_dict
+from django.contrib.admin.util import unquote, flatten_fieldsets, get_deleted_objects, model_ngettext, model_format_dict, obj_label, get_related_url
from django.contrib import messages
from django.views.decorators.csrf import csrf_protect
from django.core.exceptions import PermissionDenied, ValidationError
@@ -676,13 +676,11 @@ def response_change(self, request, obj):
return HttpResponseRedirect(request.path)
elif request.POST.has_key("_popup"):
# object changed via raw id link popup
- return HttpResponse('<script type="text/javascript">window.close();</script>')
- # TODO: this should update the object label in the href tag
- # see admin/media/js/admin/RelatedObjectLookups.js#39
- # return HttpResponse('<script type="text/javascript">
- # opener.dismissRelatedObjectPopup(window, "%s", "%s");</script>' % \
- # escape() calls force_unicode.
- # (escape(pk_value), escape(obj)))
+ obj_id = repr(force_unicode(obj._get_pk_val()))[1:]
+ obj_url = get_related_url(obj, obj.pk)
+ label = obj_label(obj).replace("&#39;", r"\'")
+ return HttpResponse('<script type="text/javascript">opener.dismissRelatedLookupPopup('
+ "window, %s, '%s', '%s');</script>" % (obj_id, obj_url, label))
elif request.POST.has_key("_saveasnew"):
msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % {'name': force_unicode(opts.verbose_name), 'obj': obj}
self.message_user(request, msg)

0 comments on commit 9aeab94

Please sign in to comment.