Merge lp:~dylanmccall/harvest/721486 into lp:harvest

Proposed by Dylan McCall
Status: Merged
Merged at revision: 299
Proposed branch: lp:~dylanmccall/harvest/721486
Merge into: lp:harvest
Diff against target: 254 lines (+77/-45)
4 files modified
harvest/filters/filters.py (+9/-13)
harvest/opportunities/filters.py (+48/-16)
harvest/opportunities/views.py (+5/-11)
harvest/opportunities/wrappers.py (+15/-5)
To merge this branch: bzr merge lp:~dylanmccall/harvest/721486
Reviewer Review Type Date Requested Status
Daniel Holbach Approve
Review via email: mp+50692@code.launchpad.net

Description of the change

Fix for bug #721486. There are some nearby changes with my other proposed merge, (lp:~dylanmccall/harvest/filter-applied), so this depends on that in order to merge cleanly.

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

Excellent!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'harvest/filters/filters.py'
2--- harvest/filters/filters.py 2010-12-08 08:15:50 +0000
3+++ harvest/filters/filters.py 2011-02-22 04:20:48 +0000
4@@ -289,18 +289,10 @@
5
6 html_class = 'filter setfilter choicefilter'
7
8- def __init__(self, id_str, choices_dict = None, **kwargs):
9+ def __init__(self, id_str, choices_dict = None, choices_labels_dict = None, **kwargs):
10 SetFilter.__init__(self, id_str, **kwargs)
11- if choices_dict:
12- self.choices_dict = choices_dict
13- else:
14- self.choices_dict = self.default_choices_dict()
15-
16- def default_choices_dict(self):
17- """
18- @return the default dictionary of choices if none is given to __init__
19- """
20- return None
21+ self.choices_dict = choices_dict
22+ self.choices_labels_dict = choices_labels_dict
23
24 def id_allowed(self, item_id): #overrides SetFilter
25 return item_id in self.choices_dict
26@@ -326,8 +318,12 @@
27 def render_html_value_choice(self, item_id):
28 toggle_params = self.serialize(self.get_value_with_selection(item_id))
29 item_href = self.get_system().get_url_with_parameters(toggle_params)
30-
31- return '<a class="item-toggle" href="%s">%s</a>' % (item_href, item_id)
32+ item_label = item_id
33+
34+ if self.choices_labels_dict and item_id in self.choices_labels_dict:
35+ item_label = self.choices_labels_dict[item_id]
36+
37+ return '<a class="item-toggle" href="%s">%s</a>' % (item_href, item_label)
38
39
40 class FilterGroup(FilterContainer, ChoiceFilter): #final
41
42=== modified file 'harvest/opportunities/filters.py'
43--- harvest/opportunities/filters.py 2010-12-08 08:15:50 +0000
44+++ harvest/opportunities/filters.py 2011-02-22 04:20:48 +0000
45@@ -9,11 +9,16 @@
46 return queryset.filter(name__startswith = self.get_value())
47
48 class PkgSetFilter(filters.ChoiceFilter):
49- def default_choices_dict(self):
50- choices_dict = OrderedDict()
51+ def __init__(self, id_str, **kwargs):
52+ choices = OrderedDict()
53 for s in models.PackageSet.objects.all(): #TODO: find a way to sort these
54- choices_dict[s.name] = s
55- return choices_dict
56+ choices[s.name] = s
57+
58+ filters.ChoiceFilter.__init__(
59+ self,
60+ id_str,
61+ choices_dict = choices,
62+ **kwargs)
63
64 def process_queryset(self, queryset):
65 return queryset.filter(packagesets__in = self.get_selected_choices())
66@@ -25,12 +30,17 @@
67 return queryset.filter(opportunitylist__featured = True)
68
69 class OppListFilter(filters.ChoiceFilter):
70- def default_choices_dict(self):
71- choices_dict = OrderedDict()
72+ def __init__(self, id_str, **kwargs):
73+ choices = OrderedDict()
74 for l in models.OpportunityList.objects.all(): #TODO: find a way to sort these
75 if l.active:
76- choices_dict[l.name] = l
77- return choices_dict
78+ choices[l.name] = l
79+
80+ filters.ChoiceFilter.__init__(
81+ self,
82+ id_str,
83+ choices_dict = choices,
84+ **kwargs)
85
86 def process_queryset(self, queryset):
87 return queryset.filter(opportunitylist__in = self.get_selected_choices())
88@@ -49,24 +59,46 @@
89 self.choices_dict[item_id].explanation
90 return '<a class="item-toggle" href="%s" %s>%s</a> %s' % (item_href, title_attribute, item_id, help_html)
91
92+class OppStatusFilter(filters.ChoiceFilter):
93+ def __init__(self, id_str, **kwargs):
94+ choices = OrderedDict.fromkeys(['applied', 'irrelevant'])
95+ labels = {'applied' : _("Applied"),
96+ 'irrelevant' : _("Irrelevant")}
97+
98+ filters.ChoiceFilter.__init__(
99+ self,
100+ id_str,
101+ choices_dict = choices,
102+ choices_labels_dict = labels,
103+ **kwargs)
104+
105+ def process_queryset(self, queryset):
106+ selection = self.get_value()
107+ if not 'applied' in selection:
108+ queryset = queryset.exclude(applied = True)
109+ if not 'irrelevant' in selection:
110+ queryset = queryset.exclude(reviewed = True)
111+ return queryset
112
113 #we don't really need to create a special type here, but it may be handy
114 class HarvestFilters(containers.FilterSystem):
115 def __init__(self):
116- super(HarvestFilters, self).__init__(
117+ containers.FilterSystem.__init__(
118+ self,
119 [
120 filters.FilterGroup('pkg', [
121- PkgNameFilter('name', name='Named'),
122+ PkgNameFilter('name', name=_('Named')),
123 PkgSetFilter('set', name=_('Limit to'))
124 ], name='Packages' ),
125 filters.FilterGroup('opp', [
126- OppFeaturedFilter('featured', name='Featured'),
127- OppListFilter('list', name=_('Limit to'))
128+ OppFeaturedFilter('featured', name=_('Featured')),
129+ OppListFilter('list', name=_('Limit to')),
130+ OppStatusFilter('status', name=_('Status'))
131 ], name='Opportunities' )
132 ],
133- default_parameters = { 'pkg' : 'set',
134- 'pkg.set' : ['ubuntu-desktop'],
135- 'opp' : 'list',
136- 'opp.list' : ['bitesize'] }
137+ default_parameters = { 'pkg' : ['set'],
138+ 'pkg.set' : ['ubuntu-desktop'],
139+ 'opp' : ['list', 'status'],
140+ 'opp.list' : ['bitesize'] }
141 )
142
143
144=== modified file 'harvest/opportunities/views.py'
145--- harvest/opportunities/views.py 2011-01-14 21:32:09 +0000
146+++ harvest/opportunities/views.py 2011-02-22 04:20:48 +0000
147@@ -1,6 +1,5 @@
148 # -*- coding: utf-8 -*-
149 from django.contrib.auth.decorators import login_required
150-from django.db.models import F
151 from django.http import HttpResponseRedirect, HttpResponse
152 from django.shortcuts import get_object_or_404
153 from django.shortcuts import render_to_response as render
154@@ -14,21 +13,16 @@
155
156 import json
157
158-# Returns all valid opportunities in the given QuerySet
159-def _get_valid_opportunities(opportunities_list):
160- return opportunities_list.filter(valid=True, opportunitylist__active=True,
161- last_updated=F('opportunitylist__last_updated'))
162-
163 def _create_packages_list(request, filters_pkg, filters_opp):
164 # XXX: rockstar: Eep! We shouldn't be storing the None as a string. We
165 # should re-think this model relationship.
166 #sourcepackages_list = models.SourcePackage.objects.exclude(name='None')
167
168- sourcepackages_list = models.SourcePackage.objects
169+ sourcepackages_list = models.SourcePackage.objects.all()
170 sourcepackages_list = filters_pkg.process_queryset(sourcepackages_list)
171
172 #opportunities_list is filtered right away to only check opportunities belonging to selected packages
173- opportunities_list = _get_valid_opportunities(models.Opportunity.objects)
174+ opportunities_list = models.Opportunity.objects.all()
175 opportunities_list = opportunities_list.filter(sourcepackage__in=sourcepackages_list)
176 opportunities_list = filters_opp.process_queryset(opportunities_list)
177
178@@ -66,7 +60,7 @@
179 def single_package(request, package_name):
180 package = get_object_or_404(models.SourcePackage, name=package_name)
181
182- opportunities_list = _get_valid_opportunities(package.opportunity_set)
183+ opportunities_list = package.opportunity_set
184 package_wrapper = PackageWrapper(request, package, visible_opportunities = opportunities_list)
185
186 context = {
187@@ -80,7 +74,7 @@
188
189 def json_package_summary(request, package_name):
190 package = get_object_or_404(models.SourcePackage, name=package_name)
191- opportunities_list = _get_valid_opportunities(package.opportunity_set)
192+ opportunities_list = package.opportunity_set
193 data = {}
194 for opportunity in opportunities_list:
195 if not data.has_key(opportunity.opportunitylist.name):
196@@ -176,7 +170,7 @@
197
198 package = get_object_or_404(models.SourcePackage, id=package_id)
199
200- opportunities_list = _get_valid_opportunities(package.opportunity_set)
201+ opportunities_list = package.opportunity_set
202 opportunities_list = filters.find('opp').process_queryset(opportunities_list).all()
203
204 package_wrapper = PackageWrapper(request, package, visible_opportunities = opportunities_list, expanded = True)
205
206=== modified file 'harvest/opportunities/wrappers.py'
207--- harvest/opportunities/wrappers.py 2010-08-31 07:55:08 +0000
208+++ harvest/opportunities/wrappers.py 2011-02-22 04:20:48 +0000
209@@ -1,5 +1,13 @@
210+from django.db.models import F
211 from harvest.common.url_tools import update_url_with_parameters
212
213+# Returns all valid opportunities in the given QuerySet
214+def get_valid_opportunities(opportunities_list):
215+ if opportunities_list:
216+ return opportunities_list.filter(valid=True,
217+ opportunitylist__active=True,
218+ last_updated=F('opportunitylist__last_updated'))
219+
220 class PackageWrapper(object):
221 """
222 Describes a visible source package, for specific use in a
223@@ -32,15 +40,17 @@
224 #order_by should really happen in the template, but the template
225 #language's dictsort is unstable pending a fix to Django bug
226 #11008: <http://code.djangoproject.com/ticket/11008>
227- return self.visible_opportunities.order_by('-since', 'opportunitylist', 'experience')
228+ opps = get_valid_opportunities(self.visible_opportunities)
229+ return opps.order_by('-since', 'opportunitylist', 'experience')
230
231 def get_hidden_opportunities(self):
232 """
233 Returns opportunities that belong to the given package but have
234 been hidden from view
235 """
236- opps_visible = self.get_visible_opportunities()
237- return self.package.opportunity_set.exclude(id__in=opps_visible)
238+ visible_opps = self.get_visible_opportunities()
239+ all_opportunities = self.package.opportunity_set.exclude(id__in=visible_opps)
240+ return get_valid_opportunities(all_opportunities)
241
242 class PackageListWrapper(object):
243 """
244@@ -69,8 +79,8 @@
245 opps = opportunities_list.filter(sourcepackage=package)
246
247 package_wrapper = PackageWrapper(request, package,
248- visible_opportunities = opps,
249- expanded = expand)
250+ visible_opportunities = opps,
251+ expanded = expand)
252 self.visible_packages_list.append(package_wrapper)
253
254 else:

Subscribers

People subscribed via source and target branches

to all changes: