Merge lp:~mhall119/loco-team-portal/579828 into lp:loco-team-portal

Proposed by Michael Hall
Status: Merged
Merged at revision: 214
Proposed branch: lp:~mhall119/loco-team-portal/579828
Merge into: lp:loco-team-portal
Diff against target: 144 lines (+73/-4)
5 files modified
loco_directory/common/widgets.py (+58/-0)
loco_directory/events/forms.py (+3/-0)
loco_directory/settings.py (+1/-0)
loco_directory/templates/venues/venue_update.html (+1/-1)
loco_directory/venues/views.py (+10/-3)
To merge this branch: bzr merge lp:~mhall119/loco-team-portal/579828
Reviewer Review Type Date Requested Status
Daniel Holbach (community) Approve
Review via email: mp+31147@code.launchpad.net

This proposal supersedes a proposal from 2010-07-20.

Description of the change

Uses some modified bits of code from the Django Admin app to allow a popup window creating new venues without leaving the Event edit page.

Requires an update of ubuntu_website

To post a comment you must log in.
Revision history for this message
Daniel Holbach (dholbach) wrote : Posted in a previous version of this proposal

A few quick things:
 - we need to use our version of "reverse"
 - a left-over print

Which part is borrowed from which part of Django Admin? How was it modified?

Is copy imported somewhere?

Is all of this needed? Or can we drop some parts?

review: Needs Fixing
Revision history for this message
Daniel Holbach (dholbach) wrote : Posted in a previous version of this proposal

Which part is borrowed from which part of Django Admin? How was it modified?

review: Needs Information
Revision history for this message
Michael Hall (mhall119) wrote :

loco_directory/common/widgets.py is now the only borrowed code, which was necessary to point the popup window to a URL of our choosing, rather than a page from the admin site (which users wouldn't have permission to access).

Revision history for this message
Daniel Holbach (dholbach) wrote :

 - Module "ubuntu_website" does not define a "popup_check" callable request processor (at least on r13) - do I need to update? How can we make sure we document all the stuff that needs to be done for the next release, so we don't forget to tell IS?
 - "common/widgets.py:6: 'reverse' imported but unused"
 - they use "import django.utils.copycompat as copy" - does that make a difference?
 - Can we somehow avoid copying the code? I'm not 100% opposed to it, but I just wonder how we can stay up to date on changes in that piece of the code and how we'll maintain it.

The solution itself works nicely and is good stuff.

review: Needs Information
Revision history for this message
Michael Hall (mhall119) wrote :

Yes,ubuntu_website needs to be updated. Without sub-branches in bzr, I'm not sure how we can automatically keep it up to date. Perhaps we should just make updating that part of the normal LD release process?

I'm not sure how django.utils.copycompat differs, but it's what they used, so there must have been a reason for it.

We couldn't use the code from the admin app, because that would require giving everybody access to the admin app, since the popup it creates points to it's own pages.

I'll remove the unused 'reverse' import.

lp:~mhall119/loco-team-portal/579828 updated
205. By Michael Hall

Removed unused reverse function import

Revision history for this message
Daniel Holbach (dholbach) wrote :

You're using copy instead of django.utils.copycompat.

Can we make the update of ubuntu_website part of init-ld?

Revision history for this message
Michael Hall (mhall119) wrote :

Again, I'm using what they used, I don't want to change stuff without knowing why or what effects it will have.

I can add the update to init-ld, but does that get called every release?

Revision history for this message
Daniel Holbach (dholbach) wrote :

> Again, I'm using what they used, I don't want to change stuff without knowing
> why or what effects it will have.

I did a diff against the maverick version, maybe you copied from somewhere else?

> I can add the update to init-ld, but does that get called every release?

We have to tell them: https://wiki.ubuntu.com/LoCoDirectory/ReleaseProcess

Revision history for this message
Michael Hall (mhall119) wrote :

I pulled it from the Lucid version.

Would it be easier to just tell them to cd into ubuntu_website and bzr pull?

Revision history for this message
Daniel Holbach (dholbach) wrote :

Merged, thanks a lot.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'loco_directory/common/widgets.py'
2--- loco_directory/common/widgets.py 1970-01-01 00:00:00 +0000
3+++ loco_directory/common/widgets.py 2010-07-29 12:07:42 +0000
4@@ -0,0 +1,58 @@
5+# Modified copy of django.contrib.admin.widgets.RelatedFieldWidgetWrapper
6+# Removed reverences to admin_site, and instead accept a popup_url
7+
8+from django import forms
9+from django.conf import settings
10+from django.utils.translation import ugettext as _
11+from django.utils.safestring import mark_safe
12+import copy
13+
14+class PopupRelatedFieldWidgetWrapper(forms.Widget):
15+ """
16+ This class is a wrapper to a given widget to add the add icon for the
17+ admin interface.
18+ """
19+ def __init__(self, widget, popup_url):
20+ self.is_hidden = widget.is_hidden
21+ self.needs_multipart_form = widget.needs_multipart_form
22+ self.attrs = widget.attrs
23+ self.choices = widget.choices
24+ self.widget = widget
25+ self.popup_url = popup_url
26+
27+ def __deepcopy__(self, memo):
28+ obj = copy.copy(self)
29+ obj.widget = copy.deepcopy(self.widget, memo)
30+ obj.attrs = self.widget.attrs
31+ memo[id(self)] = obj
32+ return obj
33+
34+ def _media(self):
35+ wm = self.widget.media
36+ wm.add_js(['%sjs/admin/RelatedObjectLookups.js'%settings.ADMIN_MEDIA_PREFIX,])
37+ return wm
38+ media = property(_media)
39+
40+ def render(self, name, value, *args, **kwargs):
41+
42+ self.widget.choices = self.choices
43+ output = [self.widget.render(name, value, *args, **kwargs)]
44+ output.append(u'<a href="%s" class="add-another" id="add_id_%s" onclick="return showAddAnotherPopup(this);"> ' % \
45+ (self.popup_url, name))
46+ output.append(u'<img src="%simg/admin/icon_addlink.gif" width="10" height="10" alt="%s"/></a>' % (settings.ADMIN_MEDIA_PREFIX, _('Add Another')))
47+ return mark_safe(u''.join(output))
48+
49+ def build_attrs(self, extra_attrs=None, **kwargs):
50+ "Helper function for building an attribute dictionary."
51+ self.attrs = self.widget.build_attrs(extra_attrs=None, **kwargs)
52+ return self.attrs
53+
54+ def value_from_datadict(self, data, files, name):
55+ return self.widget.value_from_datadict(data, files, name)
56+
57+ def _has_changed(self, initial, data):
58+ return self.widget._has_changed(initial, data)
59+
60+ def id_for_label(self, id_):
61+ return self.widget.id_for_label(id_)
62+
63
64=== modified file 'loco_directory/events/forms.py'
65--- loco_directory/events/forms.py 2010-06-19 21:35:39 +0000
66+++ loco_directory/events/forms.py 2010-07-29 12:07:42 +0000
67@@ -2,6 +2,7 @@
68
69 from django import forms
70 from django.utils.translation import ugettext as _
71+from django.core.urlresolvers import reverse
72
73 from models import BaseEvent, GlobalEvent, TeamEvent, Attendee, TeamEventComment
74 from venues.models import Venue
75@@ -60,6 +61,8 @@
76 def __init__(self, *args, **kargs):
77 super(TeamEventForm, self).__init__(*args, **kargs)
78 self.fields['venue'].choices = self.grouped_venue_list()
79+ from common.widgets import PopupRelatedFieldWidgetWrapper
80+ self.fields['venue'].widget = PopupRelatedFieldWidgetWrapper(self.fields['venue'].widget, reverse('venue-new'))
81
82 def grouped_venue_list(self):
83 """
84
85=== modified file 'loco_directory/settings.py'
86--- loco_directory/settings.py 2010-07-18 16:34:12 +0000
87+++ loco_directory/settings.py 2010-07-29 12:07:42 +0000
88@@ -100,6 +100,7 @@
89 if uw_import:
90 TEMPLATE_CONTEXT_PROCESSORS += (
91 "ubuntu_website.media_processor",
92+ "ubuntu_website.popup_check",
93 )
94 TEMPLATE_DIRS += (
95 ubuntu_website.TEMPLATE_DIR,
96
97=== modified file 'loco_directory/templates/venues/venue_update.html'
98--- loco_directory/templates/venues/venue_update.html 2010-06-24 19:18:57 +0000
99+++ loco_directory/templates/venues/venue_update.html 2010-07-29 12:07:42 +0000
100@@ -30,7 +30,7 @@
101 <table>
102 {{ form.as_table }}
103 </table>
104- <p><input type="submit" value="Submit" /></p>
105+ <p>{% if is_popup %}<input type="hidden" name="_popup" value="1">{% endif %}<input type="submit" value="Submit" /></p>
106 </form>
107 </article>
108
109
110=== modified file 'loco_directory/venues/views.py'
111--- loco_directory/venues/views.py 2010-06-19 20:20:12 +0000
112+++ loco_directory/venues/views.py 2010-07-29 12:07:42 +0000
113@@ -2,9 +2,10 @@
114 from django.shortcuts import render_to_response
115 from django.shortcuts import get_object_or_404
116 from django.contrib.auth.decorators import login_required
117-from django.http import HttpResponseRedirect
118+from django.http import HttpResponse, HttpResponseRedirect
119 from django.core.urlresolvers import reverse
120 from django.utils.translation import ugettext as _
121+from django.utils.html import escape
122 from django.db.models import Q
123
124 from models import Venue
125@@ -47,12 +48,18 @@
126 """
127 new venue
128 """
129+ venue_object = Venue()
130 if request.method == 'POST':
131- form = VenueForm(data=request.POST)
132+ form = VenueForm(data=request.POST, instance=venue_object)
133 if form.is_valid():
134 form.save()
135 request.user.message_set.create(message=_('New Venue created'))
136- return HttpResponseRedirect( reverse( 'venue-list' ) )
137+ if request.REQUEST.has_key('_popup'):
138+ return HttpResponse('<script type="text/javascript">opener.dismissAddAnotherPopup(window, "%s", "%s");</script>' % \
139+ # escape() calls force_unicode.
140+ (escape(venue_object.pk), escape(venue_object)))
141+ else:
142+ return HttpResponseRedirect( reverse( 'venue-list' ) )
143 else:
144 form = VenueForm()
145

Subscribers

People subscribed via source and target branches