Merge lp:~dylanmccall/harvest/bug-685984 into lp:harvest

Proposed by Dylan McCall
Status: Merged
Merged at revision: 284
Proposed branch: lp:~dylanmccall/harvest/bug-685984
Merge into: lp:harvest
Diff against target: 51 lines (+12/-6)
1 file modified
harvest/opportunities/views.py (+12/-6)
To merge this branch: bzr merge lp:~dylanmccall/harvest/bug-685984
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+43024@code.launchpad.net

Description of the change

Some little changes to opportunities.views to ignore invalid opportunities. An invalid opportunity is identified as having its valid property set to False, belonging to an inactive opportunity list, or having a last_updated property different from its opportunity list.

While I was at it, I removed some calls to the .distinct() method for our querysets, which are leftovers from earlier fiddling.

To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

Looks good.

Thanks,

James

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'harvest/opportunities/views.py'
2--- harvest/opportunities/views.py 2010-10-21 08:47:37 +0000
3+++ harvest/opportunities/views.py 2010-12-07 23:01:55 +0000
4@@ -13,20 +13,24 @@
5 from filters import HarvestFilters
6 from wrappers import PackageWrapper, PackageListWrapper
7
8+# Returns all valid opportunities in the given QuerySet
9+def _get_valid_opportunities(opportunities_list):
10+ return opportunities_list.filter(valid=True, opportunitylist__active=True,
11+ last_updated=F('opportunitylist__last_updated'))
12+
13 def _create_packages_list(request, filters_pkg, filters_opp):
14 # XXX: rockstar: Eep! We shouldn't be storing the None as a string. We
15 # should re-think this model relationship.
16 #sourcepackages_list = models.SourcePackage.objects.exclude(name='None')
17
18- sourcepackages_list = models.SourcePackage.objects.distinct()
19+ sourcepackages_list = models.SourcePackage.objects
20 sourcepackages_list = filters_pkg.process_queryset(sourcepackages_list)
21
22 #opportunities_list is filtered right away to only check opportunities belonging to selected packages
23- opportunities_list = models.Opportunity.objects.distinct().filter(sourcepackage__in=sourcepackages_list,
24- last_updated=F('opportunitylist__last_updated'))
25+ opportunities_list = _get_valid_opportunities(models.Opportunity.objects)
26+ opportunities_list = opportunities_list.filter(sourcepackage__in=sourcepackages_list)
27 opportunities_list = filters_opp.process_queryset(opportunities_list)
28
29- #TODO: need to filter out opportunities with valid=False again
30 #TODO: would it be more efficient to group opportunities by their sourcepackages first, then run filters_opp.process_queryset() for each of those groups?
31
32 pkg_list_wrapper = PackageListWrapper(request, sourcepackages_list, opportunities_list)
33@@ -61,7 +65,8 @@
34 def single_package(request, package_name):
35 package = get_object_or_404(models.SourcePackage, name=package_name)
36
37- package_wrapper = PackageWrapper(request, package, visible_opportunities = package.opportunity_set)
38+ opportunities_list = _get_valid_opportunities(package.opportunity_set)
39+ package_wrapper = PackageWrapper(request, package, visible_opportunities = opportunities_list)
40
41 context = {
42 'package': package_wrapper
43@@ -158,7 +163,8 @@
44
45 package = get_object_or_404(models.SourcePackage, id=package_id)
46
47- opportunities_list = filters.find('opp').process_queryset(package.opportunity_set).all()
48+ opportunities_list = _get_valid_opportunities(package.opportunity_set)
49+ opportunities_list = filters.find('opp').process_queryset(opportunities_list).all()
50
51 package_wrapper = PackageWrapper(request, package, visible_opportunities = opportunities_list, expanded = True)
52

Subscribers

People subscribed via source and target branches

to all changes: