16
16
from filters import HarvestFilters
17
17
from wrappers import PackageWrapper, PackageListWrapper
19
def opportunity_index(request):
20
sources_list = models.SourcePackage.objects.all()
21
paginator = Paginator(sources_list, 50)
22
# Make sure page request is an int. If not, deliver first page.
24
page = int(request.GET.get('page', '1'))
27
# If page request (9999) is out of range, deliver last page of results.
29
sources = paginator.page(page)
30
except (EmptyPage, InvalidPage):
31
sources = paginator.page(paginator.num_pages)
33
'pageSection': 'opportunities',
36
return render('opportunities/opportunity_index.html', context,
37
context_instance=RequestContext(request))
39
def opportunity_list(request):
40
return list_detail.object_list(
42
queryset = models.Opportunity.objects.all(),
44
template_object_name = 'opportunity',
47
19
def opportunity_detail(request, opportunity_id):
48
20
return list_detail.object_detail(
89
61
}, RequestContext(request))
92
def opportunitylist_list(request):
93
return list_detail.object_list(
95
queryset = models.OpportunityList.objects.annotate(Count('opportunity')),
99
def opportunitylist_detail(request, opportunitylist_slug):
100
opportunitylist = get_object_or_404(models.OpportunityList, name=opportunitylist_slug)
101
return list_detail.object_list(
103
queryset = models.Opportunity.objects.filter(opportunitylist__name=opportunitylist_slug),
105
template_name = 'opportunities/opportunitylist_detail.html',
106
extra_context = {'opportunitylist': opportunitylist},
109
def sourcepackage_list(request):
110
return list_detail.object_list(
112
queryset = models.SourcePackage.objects.annotate(Count('opportunity')),
116
def sourcepackage_detail(request, sourcepackage_slug):
117
opportunities = models.Opportunity.objects.filter(sourcepackage__name=sourcepackage_slug)
118
return list_detail.object_detail(
120
queryset = models.SourcePackage.objects.all(),
121
slug = sourcepackage_slug,
123
extra_context = {'opportunities': opportunities},
126
def opportunities_filter(request):
127
filters = HarvestFilters()
128
filters.update_from_http(request)
129
filters_pkg = filters.find('pkg')
130
filters_opp = filters.find('opp')
132
packages_list = models.SourcePackage.objects.distinct()
133
packages_list = filters_pkg.process_queryset(packages_list)
64
def _create_packages_list(request, filters_pkg, filters_opp):
65
sourcepackages_list = models.SourcePackage.objects.distinct()
66
sourcepackages_list = filters_pkg.process_queryset(sourcepackages_list)
135
68
#opportunities_list is filtered right away to only check opportunities belonging to selected packages
136
opportunities_list = models.Opportunity.objects.distinct().filter(sourcepackage__in=packages_list)
69
opportunities_list = models.Opportunity.objects.distinct().filter(sourcepackage__in=sourcepackages_list)
137
70
opportunities_list = filters_opp.process_queryset(opportunities_list)
138
72
#TODO: need to filter out opportunities with valid=False again
139
73
#TODO: would it be more efficient to group opportunities by their sourcepackages first, then run filters_opp.process_queryset() for each of those groups?
141
pkg_list_wrapper = PackageListWrapper(request, packages_list, opportunities_list)
75
pkg_list_wrapper = PackageListWrapper(request, sourcepackages_list, opportunities_list)
77
return pkg_list_wrapper
80
def opportunities_filter(request):
81
filters = HarvestFilters()
82
filters.update_from_http(request)
83
filters_pkg = filters.find('pkg')
84
filters_opp = filters.find('opp')
86
pkg_list_wrapper = _create_packages_list(request, filters_pkg, filters_opp)
144
89
'grouping': 'package',
153
98
context_instance=RequestContext(request))
155
101
#TODO: package_filter_detail(request, sourcepackage, opportunities_list)
157
def opportunities_by_type(request):
158
types_list = models.OpportunityList.objects.all()
159
paginator = Paginator(types_list, 50)
161
# Make sure page request is an int. If not, deliver first page.
163
page = int(request.GET.get('page', '1'))
167
# If page request (9999) is out of range, deliver last page of results.
169
types = paginator.page(page)
170
except (EmptyPage, InvalidPage):
171
types = paginator.page(paginator.num_pages)
174
'pageSection': 'opportunities',
180
'opportunities/opportunities_by_type.html',
182
context_instance=RequestContext(request))
184
def opportunities_by_package(request, packageset_slug=None):
185
# XXX: rockstar: Eep! We shouldn't be storing the None as a string. We
186
# should re-think this model relationship.
187
sources_list = models.SourcePackage.objects.exclude(name='None')
189
packageset = get_object_or_404(models.PackageSet, name=packageset_slug)
190
sources_list = sources_list.filter(packagesets=packageset)
191
paginator = Paginator(sources_list, 50)
193
# Make sure page request is an int. If not, deliver first page.
195
page = int(request.GET.get('page', '1'))
199
# If page request (9999) is out of range, deliver last page of results.
201
sources = paginator.page(page)
202
except (EmptyPage, InvalidPage):
203
sources = paginator.page(paginator.num_pages)
206
'pageSection': 'opportunities',
104
def opportunities_results(request):
105
filters = HarvestFilters()
106
filters.update_from_http(request)
108
packages_list = _create_packages_list(request, filters.find('pkg'), filters.find('opp'))
208
111
'grouping': 'package',
112
'packages_list': packages_list
212
'opportunities/opportunities_by_package.html',
116
'opportunities/results.html',
214
118
context_instance=RequestContext(request))
216
def packageset_list(request):
217
packagesets = models.PackageSet.objects.all()
219
'packagesets': packagesets
221
return render('opportunities/packageset_list.html',
223
context_instance=RequestContext(request))