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
=== added file 'loco_directory/common/widgets.py'
--- loco_directory/common/widgets.py 1970-01-01 00:00:00 +0000
+++ loco_directory/common/widgets.py 2010-07-29 12:07:42 +0000
@@ -0,0 +1,58 @@
1# Modified copy of django.contrib.admin.widgets.RelatedFieldWidgetWrapper
2# Removed reverences to admin_site, and instead accept a popup_url
3
4from django import forms
5from django.conf import settings
6from django.utils.translation import ugettext as _
7from django.utils.safestring import mark_safe
8import copy
9
10class PopupRelatedFieldWidgetWrapper(forms.Widget):
11 """
12 This class is a wrapper to a given widget to add the add icon for the
13 admin interface.
14 """
15 def __init__(self, widget, popup_url):
16 self.is_hidden = widget.is_hidden
17 self.needs_multipart_form = widget.needs_multipart_form
18 self.attrs = widget.attrs
19 self.choices = widget.choices
20 self.widget = widget
21 self.popup_url = popup_url
22
23 def __deepcopy__(self, memo):
24 obj = copy.copy(self)
25 obj.widget = copy.deepcopy(self.widget, memo)
26 obj.attrs = self.widget.attrs
27 memo[id(self)] = obj
28 return obj
29
30 def _media(self):
31 wm = self.widget.media
32 wm.add_js(['%sjs/admin/RelatedObjectLookups.js'%settings.ADMIN_MEDIA_PREFIX,])
33 return wm
34 media = property(_media)
35
36 def render(self, name, value, *args, **kwargs):
37
38 self.widget.choices = self.choices
39 output = [self.widget.render(name, value, *args, **kwargs)]
40 output.append(u'<a href="%s" class="add-another" id="add_id_%s" onclick="return showAddAnotherPopup(this);"> ' % \
41 (self.popup_url, name))
42 output.append(u'<img src="%simg/admin/icon_addlink.gif" width="10" height="10" alt="%s"/></a>' % (settings.ADMIN_MEDIA_PREFIX, _('Add Another')))
43 return mark_safe(u''.join(output))
44
45 def build_attrs(self, extra_attrs=None, **kwargs):
46 "Helper function for building an attribute dictionary."
47 self.attrs = self.widget.build_attrs(extra_attrs=None, **kwargs)
48 return self.attrs
49
50 def value_from_datadict(self, data, files, name):
51 return self.widget.value_from_datadict(data, files, name)
52
53 def _has_changed(self, initial, data):
54 return self.widget._has_changed(initial, data)
55
56 def id_for_label(self, id_):
57 return self.widget.id_for_label(id_)
58
059
=== modified file 'loco_directory/events/forms.py'
--- loco_directory/events/forms.py 2010-06-19 21:35:39 +0000
+++ loco_directory/events/forms.py 2010-07-29 12:07:42 +0000
@@ -2,6 +2,7 @@
22
3from django import forms3from django import forms
4from django.utils.translation import ugettext as _4from django.utils.translation import ugettext as _
5from django.core.urlresolvers import reverse
56
6from models import BaseEvent, GlobalEvent, TeamEvent, Attendee, TeamEventComment7from models import BaseEvent, GlobalEvent, TeamEvent, Attendee, TeamEventComment
7from venues.models import Venue8from venues.models import Venue
@@ -60,6 +61,8 @@
60 def __init__(self, *args, **kargs):61 def __init__(self, *args, **kargs):
61 super(TeamEventForm, self).__init__(*args, **kargs)62 super(TeamEventForm, self).__init__(*args, **kargs)
62 self.fields['venue'].choices = self.grouped_venue_list()63 self.fields['venue'].choices = self.grouped_venue_list()
64 from common.widgets import PopupRelatedFieldWidgetWrapper
65 self.fields['venue'].widget = PopupRelatedFieldWidgetWrapper(self.fields['venue'].widget, reverse('venue-new'))
63 66
64 def grouped_venue_list(self):67 def grouped_venue_list(self):
65 """68 """
6669
=== modified file 'loco_directory/settings.py'
--- loco_directory/settings.py 2010-07-18 16:34:12 +0000
+++ loco_directory/settings.py 2010-07-29 12:07:42 +0000
@@ -100,6 +100,7 @@
100if uw_import:100if uw_import:
101 TEMPLATE_CONTEXT_PROCESSORS += (101 TEMPLATE_CONTEXT_PROCESSORS += (
102 "ubuntu_website.media_processor",102 "ubuntu_website.media_processor",
103 "ubuntu_website.popup_check",
103 )104 )
104 TEMPLATE_DIRS += (105 TEMPLATE_DIRS += (
105 ubuntu_website.TEMPLATE_DIR,106 ubuntu_website.TEMPLATE_DIR,
106107
=== modified file 'loco_directory/templates/venues/venue_update.html'
--- loco_directory/templates/venues/venue_update.html 2010-06-24 19:18:57 +0000
+++ loco_directory/templates/venues/venue_update.html 2010-07-29 12:07:42 +0000
@@ -30,7 +30,7 @@
30 <table>30 <table>
31 {{ form.as_table }}31 {{ form.as_table }}
32 </table>32 </table>
33 <p><input type="submit" value="Submit" /></p>33 <p>{% if is_popup %}<input type="hidden" name="_popup" value="1">{% endif %}<input type="submit" value="Submit" /></p>
34 </form>34 </form>
35</article>35</article>
3636
3737
=== modified file 'loco_directory/venues/views.py'
--- loco_directory/venues/views.py 2010-06-19 20:20:12 +0000
+++ loco_directory/venues/views.py 2010-07-29 12:07:42 +0000
@@ -2,9 +2,10 @@
2from django.shortcuts import render_to_response2from django.shortcuts import render_to_response
3from django.shortcuts import get_object_or_4043from django.shortcuts import get_object_or_404
4from django.contrib.auth.decorators import login_required4from django.contrib.auth.decorators import login_required
5from django.http import HttpResponseRedirect5from django.http import HttpResponse, HttpResponseRedirect
6from django.core.urlresolvers import reverse6from django.core.urlresolvers import reverse
7from django.utils.translation import ugettext as _7from django.utils.translation import ugettext as _
8from django.utils.html import escape
8from django.db.models import Q9from django.db.models import Q
910
10from models import Venue11from models import Venue
@@ -47,12 +48,18 @@
47 """48 """
48 new venue49 new venue
49 """50 """
51 venue_object = Venue()
50 if request.method == 'POST': 52 if request.method == 'POST':
51 form = VenueForm(data=request.POST)53 form = VenueForm(data=request.POST, instance=venue_object)
52 if form.is_valid():54 if form.is_valid():
53 form.save()55 form.save()
54 request.user.message_set.create(message=_('New Venue created'))56 request.user.message_set.create(message=_('New Venue created'))
55 return HttpResponseRedirect( reverse( 'venue-list' ) )57 if request.REQUEST.has_key('_popup'):
58 return HttpResponse('<script type="text/javascript">opener.dismissAddAnotherPopup(window, "%s", "%s");</script>' % \
59 # escape() calls force_unicode.
60 (escape(venue_object.pk), escape(venue_object)))
61 else:
62 return HttpResponseRedirect( reverse( 'venue-list' ) )
56 else:63 else:
57 form = VenueForm()64 form = VenueForm()
58 65

Subscribers

People subscribed via source and target branches