public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Slava Bacherikov" <slava@bacherikov.org.ua>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/templates/
Date: Fri, 29 Jun 2012 19:25:34 +0000 (UTC)	[thread overview]
Message-ID: <1340997928.da1ad22983b481f3da07752ea18b1337955fd5b9.bacher09@gentoo> (raw)

commit:     da1ad22983b481f3da07752ea18b1337955fd5b9
Author:     Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Fri Jun 29 19:25:28 2012 +0000
Commit:     Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Fri Jun 29 19:25:28 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=da1ad229

Add dynamic packages filter

---
 gpackages/apps/packages/urls.py       |    3 +-
 gpackages/apps/packages/views.py      |   68 ++++++++++++++++++++++++++++++++-
 gpackages/templates/categories.html   |    3 +-
 gpackages/templates/herds.html        |    4 +-
 gpackages/templates/maintainers.html  |    3 +-
 gpackages/templates/repositories.html |    3 +-
 6 files changed, 77 insertions(+), 7 deletions(-)

diff --git a/gpackages/apps/packages/urls.py b/gpackages/apps/packages/urls.py
index ffb16ca..f597026 100644
--- a/gpackages/apps/packages/urls.py
+++ b/gpackages/apps/packages/urls.py
@@ -10,7 +10,8 @@ urlpatterns = patterns('',
     url(r'^repositories/$', RepositoriesListView.as_view(), name = 'repositories'),
     url(r'^license-groups/$', LicenseGroupsView.as_view(), name = 'license_groups'),
     url(r'^$', EbuildsListView.as_view(), name = 'ebuilds'),
-    url(r'^packages/$', PackagesListsView.as_view(), name = 'packages'),
+    url(r'^packages/(?:category/(?P<category>[^/]+)/)?(?:repo/(?P<repo>[^/]*)/)?(?:herd/(?P<herd>[^/]+)/)?(?:maintainer/(?P<maintainer_pk>[^/]+)/)?(?:order/(?P<order>[a-z]*)/)?(?P<rev>rev/)?$',
+    PackagesListsView.as_view(), name = 'packages'),
 
     # In Future I will write my onw URL Resolver !!!
     #url(r'^package/(?:(?P<pk>\d+)|(?P<category>[^/]+)/(?P<name>[^/]+))/$', PackageDetailView.as_view(), name = 'package'),

diff --git a/gpackages/apps/packages/views.py b/gpackages/apps/packages/views.py
index 2ec2758..2c75ed6 100644
--- a/gpackages/apps/packages/views.py
+++ b/gpackages/apps/packages/views.py
@@ -48,7 +48,53 @@ class EbuildsListView(ContextListView):
                        'package__virtual_package',
                        'package__virtual_package__category').prefetch_keywords(arches)
 
+# there is another dynamic filter for django, and it maybe better 
+# but it is too big and i need just a litle of its functionly
+# but if this code have to be grove maybe i replace it to django-filter
+# application or another.
+def dynamic_filter(filter_set, allowed):
+    result = {}
+    for k in allowed.iterkeys():
+        if k in filter_set:
+            result[allowed[k]] = filter_set[k]
+    return result
+
+def exclude_blank(res_dict):
+    result = {}
+    for k in res_dict.iterkeys():
+        if res_dict[k]:
+            result[k] = res_dict[k]
+    return result
+
+def dynamic_order(args_list, allowed_list, reverse = None):
+    order = allowed_list.get(None)
+    if reverse is None:
+        reverse = args_list.get('reverse', False)
+    if args_list.get('order') in allowed_list:
+        order = allowed_list.get(args_list.get('order'))
+
+    if order == '?':
+        return order
+    
+    if reverse and order[0] != '-':
+        order = '-' + order
+    elif reverse:
+        order =  order[1:]
+    return order
+
 class PackagesListsView(ContextListView):
+    allowed_filter = { 'category':'virtual_package__category__category',
+                       'repo':'repository__name',
+                       'herd':'herds__name',
+                       'maintainer_pk': 'maintainers__pk',
+                       'license': 'licenses__name'
+                    }
+
+    allowed_order = { 'create': 'created_datetime',
+                      'update': 'updated_datetime',
+                      'rand':'?', # it slow
+                      None: '-updated_datetime'
+                    }
     arches = ['alpha', 'amd64', 'arm', 'hppa', 'ia64', 'ppc', 'ppc64', 'sparc', 'x86']
     paginate_by = 40
     extra_context = {'page_name': 'Packages', 'arches': arches}
@@ -62,12 +108,32 @@ class PackagesListsView(ContextListView):
     #INNER JOIN packages_virtualpackagemodel vp 
     #ON( `vp`.id = t.virtual_package_id) INNER JOIN `packages_categorymodel` cp
     #ON (vp.category_id = cp.id);
-    queryset = PackageModel.objects.all(). \
+    base_queryset = PackageModel.objects.all(). \
         select_related('virtual_package',
                        'virtual_package__category'). \
         prefetch_related('repository'). \
         prefetch_keywords(arches)
 
+    def get_queryset(self):
+        qs = dynamic_filter(exclude_blank(self.request.GET),
+                                        self.allowed_filter)
+        qs.update( dynamic_filter(exclude_blank(self.kwargs),
+                                        self.allowed_filter) )
+        
+        if self.kwargs.get('rev') is None:
+            reverse = bool(self.request.GET.get('rev',False))
+        else:
+            reverse = bool(self.kwargs.get('rev',False))
+        
+        if 'order' in self.request.GET:
+            order = dynamic_order(self.request.GET, self.allowed_order,reverse)
+        else:
+            order = dynamic_order(self.kwargs, self.allowed_order, reverse)
+            if self.kwargs.get('order') not in self.allowed_order:
+                raise Http404('no such order')
+
+        return self.base_queryset.filter(**qs).order_by(order)
+
 class PackageDetailView(ContextView, DetailView):
     arches = ['alpha', 'amd64', 'arm', 'hppa', 'ia64', 'ppc', 'ppc64', 'sparc', 'x86']
     template_name = 'package.html'

diff --git a/gpackages/templates/categories.html b/gpackages/templates/categories.html
index 4163e90..52cfd1f 100644
--- a/gpackages/templates/categories.html
+++ b/gpackages/templates/categories.html
@@ -1,4 +1,5 @@
 {% extends "base.html" %}
+{% load url from future %}
 
 {% block content %}
 
@@ -16,7 +17,7 @@
     <tbody>
         {% for category in categories %}
             <tr>
-                <td class="nowrap"><a href="#">{{ category.category }}</a></td>
+                <td class="nowrap"><a href="{% url 'packages' category=category.category %}">{{ category.category }}</a></td>
                 <td>{{ category.description|default_if_none:"" }}</td>
             </tr>
         {% endfor %}

diff --git a/gpackages/templates/herds.html b/gpackages/templates/herds.html
index 5252576..b767967 100644
--- a/gpackages/templates/herds.html
+++ b/gpackages/templates/herds.html
@@ -1,6 +1,6 @@
 {% extends "base.html" %}
 {% load packages %}
-
+{% load url from future %}
 {% block content %}
 
 <table class='table table-striped table-hover'>
@@ -19,7 +19,7 @@
     <tbody>
         {% for herd in herds %}
             <tr>
-                <td class="nowrap"><a href="#">{{ herd.name }}</a></td>
+                <td class="nowrap"><a href="{% url 'packages' herd=herd.name %}">{{ herd.name }}</a></td>
                 <!-- email should be obfuscated -->
                 <td class="nowrap"><a href="{{ 'mailto:'|add:herd.email|obfuscate }}">{{ herd.email|obfuscate }}</a></td>
                 <td>{{ herd.description|default_if_none:"" }}</td>

diff --git a/gpackages/templates/maintainers.html b/gpackages/templates/maintainers.html
index 5646c99..ecd087e 100644
--- a/gpackages/templates/maintainers.html
+++ b/gpackages/templates/maintainers.html
@@ -1,5 +1,6 @@
 {% extends "base.html" %}
 {% load packages %}
+{% load url from future %}
 
 {% block content %}
 
@@ -17,7 +18,7 @@
     <tbody>
         {% for maintainer in maintainers %}
             <tr>
-                <td class="nowrap"><a href="#">{{ maintainer.name|default:"Not represented" }}</a></td>
+                <td class="nowrap"><a href="{% url 'packages' maintainer_pk=maintainer.pk %}">{{ maintainer.name|default:"Not represented" }}</a></td>
                 <!-- email should be obfuscated -->
                 <td class="nowrap"><a href="{{ 'mailto:'|add:maintainer.email|obfuscate }}">{{ maintainer.email|obfuscate }}</a></td>
             </tr>

diff --git a/gpackages/templates/repositories.html b/gpackages/templates/repositories.html
index 0fdb42a..591141f 100644
--- a/gpackages/templates/repositories.html
+++ b/gpackages/templates/repositories.html
@@ -1,4 +1,5 @@
 {% extends "base.html" %}
+{% load url from future %}
 
 {% block content %}
 
@@ -18,7 +19,7 @@
     <tbody>
         {% for repository in repositories %}
             <tr>
-                <td class="nowrap"><a href="#">{{ repository.name }}</a></td>
+                <td class="nowrap"><a href="{% url 'packages' repo=repository.name %}">{{ repository.name }}</a></td>
                 <td>{{ repository.description|default_if_none:"" }}</td>
                 <td>{{ repository.updated_datetime|date:"d m Y H:i:s" }}</td>
             </tr>



             reply	other threads:[~2012-06-29 19:25 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-29 19:25 Slava Bacherikov [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-08-20 13:03 [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/templates/ Slava Bacherikov
2012-07-19 23:50 Slava Bacherikov
2012-07-19 23:50 Slava Bacherikov
2012-07-12 22:16 Slava Bacherikov
2012-07-12 22:16 Slava Bacherikov
2012-07-10 23:13 Slava Bacherikov
2012-07-08 19:54 Slava Bacherikov
2012-07-08 19:54 Slava Bacherikov
2012-07-08 19:54 Slava Bacherikov
2012-07-06 23:09 Slava Bacherikov
2012-07-06 23:09 Slava Bacherikov
2012-07-04 22:13 Slava Bacherikov
2012-07-02 22:25 Slava Bacherikov
2012-06-30 21:02 Slava Bacherikov
2012-06-30 21:02 Slava Bacherikov
2012-06-30  0:22 Slava Bacherikov
2012-06-28 23:59 Slava Bacherikov
2012-06-27 22:52 Slava Bacherikov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1340997928.da1ad22983b481f3da07752ea18b1337955fd5b9.bacher09@gentoo \
    --to=slava@bacherikov.org.ua \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox