aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSlava Bacherikov <slava@bacher09.org>2012-08-27 18:43:06 +0300
committerSlava Bacherikov <slava@bacher09.org>2012-08-27 18:50:23 +0300
commit9041adff94fb2a6e78bdb6481b803ace4306465d (patch)
tree1207b7e32c28d33a52c41ef79b4230a26692d3b1
parentAdd scan only overlays option (diff)
downloadgentoo-packages-9041adff94fb2a6e78bdb6481b803ace4306465d.tar.gz
gentoo-packages-9041adff94fb2a6e78bdb6481b803ace4306465d.tar.bz2
gentoo-packages-9041adff94fb2a6e78bdb6481b803ace4306465d.zip
Extend filtering mixin
-rw-r--r--gpackages/apps/generic/views.py26
-rw-r--r--gpackages/apps/packages/views.py18
2 files changed, 36 insertions, 8 deletions
diff --git a/gpackages/apps/generic/views.py b/gpackages/apps/generic/views.py
index faf8559..da0048e 100644
--- a/gpackages/apps/generic/views.py
+++ b/gpackages/apps/generic/views.py
@@ -96,6 +96,32 @@ class MultipleFilterListViewMixin(object):
with ``distinct`` attribute.
"""
+ @classmethod
+ def get_url_kwargs(cls, filters, order = None, rev = False):
+ kwargs = {}
+ for name, value in filters.iteritems():
+ if not value or name not in cls.allowed_filter:
+ continue
+
+ if name in cls.boolean_filters:
+ value = 'yes' if value else 'no'
+ elif name in cls.allowed_many:
+ if not isinstance(value, (str, unicode)):
+ count = cls.allowed_many[name]
+ if count > 0:
+ value = value[:count]
+ value = ','.join(value)
+
+ kwargs[name] = value
+
+ if order is not None and order in self.allowed_order:
+ kwargs['order'] = order
+
+ if rev:
+ kwargs['rev'] = 'rev'
+
+ return kwargs
+
def get_context_data(self, **kwargs):
"""In addition to default context value will return all filters as
:py:class:`.dict`.
diff --git a/gpackages/apps/packages/views.py b/gpackages/apps/packages/views.py
index 5167a31..b597a12 100644
--- a/gpackages/apps/packages/views.py
+++ b/gpackages/apps/packages/views.py
@@ -115,7 +115,7 @@ class MaintainersListView(CacheFilterListView, ContextListView):
cache_time = 560
allowed_filter = { 'dev' : 'is_dev',
'herd' : 'herdsmodel__name'}
- allowed_order = { None: 'name'}
+ allowed_order = { None: 'name', 'dev' : 'is_dev'}
boolean_filters = ('dev',)
paginate_by = 40
extra_context = {'page_name': 'Maintainers',}
@@ -213,14 +213,16 @@ class PackagesListsView(CacheFilterListView, ContextArchListView):
'herd':'herds__name',
'maintainer': 'maintainers__pk',
'license': 'ebuildmodel__licenses__name',
- 'use': 'ebuildmodel__use_flags__name'
+ 'use': 'ebuildmodel__use_flags__name',
+ # it's too slow
+ #'arch' : 'ebuildmodel__keyword__arch__name'
}
m2m_filter = set(['herd', 'maintainer', 'license', 'use'])
allowed_order = { 'create': 'created_datetime',
'update': 'updated_datetime',
- 'rand':'?', # it slow
+ #'rand':'?', # it is slow
None: '-updated_datetime'
}
allowed_many = {'repo': 5, 'use' : 3, 'herd': 4, 'category': 4, 'license': 3}
@@ -361,11 +363,11 @@ class FilteringView(FormView):
def get_success_url(self):
dct = {}
- for k, v in self.params_dict.iteritems():
- vv = self.form_data[k]
- if vv:
- dct[v] = ','.join(vv)
- return reverse('packages', kwargs = dct)
+ for k,v in self.params_dict.iteritems():
+ dct[v] = self.form_data[k]
+
+ kwargs = PackagesListsView.get_url_kwargs(dct)
+ return reverse('packages', kwargs = kwargs)
class RepoDetailView(ArchesCacheViewMixin, DetailView):
cache_time = 900