From 9df541f95f12d2fad5c9911008882b7ff35a9514 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Tue, 7 Sep 2010 16:04:56 -0500 Subject: Implement package difference filtering This is done as client-side JS which makes the page nice and fast. Minor versions can be excluded, as can packages in [multilib]. In addition, architecture filtering is in place so you can limit the subset of shown packages to those in any, both, one or the other. Signed-off-by: Dan McGee --- media/archweb.css | 11 ++--- packages/utils.py | 32 +++++++++++-- settings.py | 2 + templates/packages/differences.html | 95 +++++++++++++++++++++++++++++++------ 4 files changed, 117 insertions(+), 23 deletions(-) diff --git a/media/archweb.css b/media/archweb.css index e5e5e6e0..f417e5ee 100644 --- a/media/archweb.css +++ b/media/archweb.css @@ -175,7 +175,6 @@ table.results th.headerSortUp { background-color: #e4eeff; background-image: url table.results .flagged { color: red; } /* pkglist: layout */ -div#pkglist-search { margin-bottom: 1.5em; } div#pkglist-about { margin-top: 1.5em; } /* pkglist: results navigation */ @@ -184,11 +183,11 @@ div#pkglist-about { margin-top: 1.5em; } .pkglist-nav .prev { margin-right: 1em; } .pkglist-nav .next { margin-right: 1em; } -/* pkglist: search fields */ -#pkglist-search h3 { font-size: 1em; margin-top:0; } -#pkglist-search div { float: left; margin-right: 1.65em; font-size: 0.85em; } -#pkglist-search legend { display: none; } -#pkglist-search label { width: auto; display: block; font-weight: normal; } +/* search fields and other filter selections */ +.filter-criteria h3 { font-size: 1em; margin-top:0; } +.filter-criteria div { float: left; margin-right: 1.65em; font-size: 0.85em; } +.filter-criteria legend { display: none; } +.filter-criteria label { width: auto; display: block; font-weight: normal; } /* pkgdetails: details links that float on the right */ #pkgdetails #detailslinks { float: right; } diff --git a/packages/utils.py b/packages/utils.py index 204e5bf2..55b7acf9 100644 --- a/packages/utils.py +++ b/packages/utils.py @@ -44,6 +44,32 @@ def get_group_info(): groups.extend(val.itervalues()) return sorted(groups, key=itemgetter('name', 'arch')) +class Difference(object): + def __init__(self, pkgname, repo, pkg_a, pkg_b): + self.pkgname = pkgname + self.repo = repo + self.pkg_a = pkg_a + self.pkg_b = pkg_b + + def classes(self): + '''A list of CSS classes that should be applied to this row in any + generated HTML. Useful for sorting, filtering, etc. Contains whether + this difference is in both architectures or the sole architecture it + belongs to, as well as the repo name.''' + css_classes = [self.repo.name.lower()] + if self.pkg_a and self.pkg_b: + css_classes.append('both') + elif self.pkg_a: + css_classes.append(self.pkg_a.arch.name) + elif self.pkg_b: + css_classes.append(self.pkg_b.arch.name) + return ' '.join(css_classes) + + def __cmp__(self, other): + if isinstance(other, Difference): + return cmp(self.__dict__, other.__dict__) + return False + @cache_function(300) def get_differences_info(arch_a, arch_b): # This is a monster. Join packages against itself, looking for packages in @@ -87,17 +113,17 @@ SELECT p.id, q.id # We want arch_a to always appear first # pkg_a should never be None if pkg_a.arch == arch_a: - item = (pkg_a.pkgname, pkg_a.repo, pkg_a, pkg_b) + item = Difference(pkg_a.pkgname, pkg_a.repo, pkg_a, pkg_b) else: # pkg_b can be None in this case, so be careful name = pkg_a.pkgname if pkg_a else pkg_b.pkgname repo = pkg_a.repo if pkg_a else pkg_b.repo - item = (name, repo, pkg_b, pkg_a) + item = Difference(name, repo, pkg_b, pkg_a) if item not in differences: differences.append(item) # now sort our list by repository, package name - differences.sort(key=lambda a: (a[1].name, a[0])) + differences.sort(key=lambda a: (a.repo.name, a.pkgname)) return differences # vim: set ts=4 sw=4 et: diff --git a/settings.py b/settings.py index b1ad20ec..6e98adce 100644 --- a/settings.py +++ b/settings.py @@ -51,6 +51,8 @@ TEMPLATE_LOADERS = ( 'django.template.loaders.app_directories.load_template_source', ) +# This bug is a real bummer: +# http://code.djangoproject.com/ticket/14105 MIDDLEWARE_CLASSES = ( 'main.middleware.UpdateCacheMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', diff --git a/templates/packages/differences.html b/templates/packages/differences.html index 1c3e97e3..4c3b43c6 100644 --- a/templates/packages/differences.html +++ b/templates/packages/differences.html @@ -4,8 +4,30 @@ {% block content %} {% if differences %} -
+

Package Differences by Architecture

+

Filter Differences View

+
+
+ Select filter criteria +
+ +
+
+
+
+
+
+
+
+
+ +
@@ -16,19 +38,19 @@ - {% for name, repo, pkg1, pkg2 in differences %} - - - - {% if pkg1 %} - + {% for diff in differences %} + + + + {% if diff.pkg_a %} + {% else %}{% endif %} - {% if pkg2 %} - + {% if diff.pkg_b %} + {% else %}{% endif %} {% endfor %} @@ -38,8 +60,53 @@ {% load cdn %}{% jquery %} {% endif %} -- cgit v1.2.3-2-g168b
{{ name }}{{ repo.name }} - {{ pkg1.pkgver }}-{{ pkg1.pkgrel }}
{{ diff.pkgname }}{{ diff.repo.name }} + {{ diff.pkg_a.pkgver }}-{{ diff.pkg_a.pkgrel }}- - {{ pkg2.pkgver }}-{{ pkg2.pkgrel }} + {{ diff.pkg_b.pkgver }}-{{ diff.pkg_b.pkgrel }}-