1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
from harvest.filters import filters, containers
from harvest.common.ordereddict import OrderedDict
import models
class PkgNameFilter(filters.EditFilter):
def process_queryset(self, queryset):
return queryset.filter(name__startswith = self.get_value())
class PkgSetFilter(filters.ChoiceFilter):
def default_choices_dict(self):
choices_dict = OrderedDict()
for s in models.PackageSet.objects.all(): #TODO: find a way to sort these
choices_dict[s.name] = s
return choices_dict
def process_queryset(self, queryset):
return queryset.filter(packagesets__in = self.get_selected_choices())
class OppFeaturedFilter(filters.Filter):
def process_queryset(self, queryset):
return queryset.filter(opportunitylist__featured = True)
class OppListFilter(filters.ChoiceFilter):
def default_choices_dict(self):
choices_dict = OrderedDict()
for l in models.OpportunityList.objects.all(): #TODO: find a way to sort these
choices_dict[l.name] = l
return choices_dict
def process_queryset(self, queryset):
return queryset.filter(opportunitylist__in = self.get_selected_choices())
#we don't really need to create a special type here, but it may be handy
class HarvestFilters(containers.FilterSystem):
def __init__(self):
super(HarvestFilters, self).__init__(
[
filters.FilterGroup('pkg', [
PkgNameFilter('name', name='Named'),
PkgSetFilter('set', name='Package sets')
], name='Packages' ),
filters.FilterGroup('opp', [
OppFeaturedFilter('featured', name='Featured'),
OppListFilter('list', name='Selected')
], name='Opportunities' )
],
default_parameters = { 'pkg' : 'set',
'pkg:set' : 'ubuntu-desktop',
'opp' : 'list',
'opp:list' : 'bitesize' }
#TODO: change to no defaults, detect that case in view and templates and provide helpful instructions in the results pane.
)
|