[extensions-web: 27/30] When querying for a specific shell versions, include catch-alls
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web: 27/30] When querying for a specific shell versions, include catch-alls
- Date: Thu, 26 Jan 2012 10:42:47 +0000 (UTC)
commit 716264548a66c7523e645bc391276063843f3e89
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Thu Jan 12 17:59:41 2012 -0500
When querying for a specific shell versions, include catch-alls
When using AJAX queries to find extensions that support shell version "3.2.1",
as an example, include the catch-all "3.2" version as well to make sure that
we find all the extensions that are possible.
sweettooth/extensions/models.py | 25 +++++++++++++++++++++++++
sweettooth/extensions/tests.py | 18 ++++++++++++++++++
sweettooth/extensions/views.py | 20 +++++++++++++++-----
3 files changed, 58 insertions(+), 5 deletions(-)
---
diff --git a/sweettooth/extensions/models.py b/sweettooth/extensions/models.py
index 0b13fdf..ab71608 100644
--- a/sweettooth/extensions/models.py
+++ b/sweettooth/extensions/models.py
@@ -201,6 +201,31 @@ class ShellVersion(models.Model):
return "%d.%d.%d" % (self.major, self.minor, self.point)
+ @property
+ def is_unstable(self):
+ return self.minor % 2 != 0
+
+ @property
+ def is_stable(self):
+ return self.minor % 2 == 0
+
+ @property
+ def base_version(self):
+ if self.point == -1:
+ return None
+
+ if self.is_unstable:
+ return None
+
+ try:
+ # This is intended to be use to easily query for all extensions
+ # that are compatible with a specific shell version. As such,
+ # this doesn't use get_or_create -- no sense creating a shell
+ # version that no extensions are going to match.
+ return self._default_manager.get(major=self.major, minor=self.minor, point=-1)
+ except self.DoesNotExist:
+ return None
+
class InvalidExtensionData(Exception):
pass
diff --git a/sweettooth/extensions/tests.py b/sweettooth/extensions/tests.py
index 8d1c9c3..8262f17 100644
--- a/sweettooth/extensions/tests.py
+++ b/sweettooth/extensions/tests.py
@@ -275,21 +275,39 @@ class ExtensionVersionTest(BasicUserTestCase, TestCase):
class ShellVersionTest(TestCase):
def test_shell_version_parsing_basic(self):
+ lookup_version = models.ShellVersion.objects.lookup_for_version_string
get_version = models.ShellVersion.objects.get_for_version_string
version = get_version("3.0.0")
self.assertEquals(version.major, 3)
self.assertEquals(version.minor, 0)
self.assertEquals(version.point, 0)
+ self.assertTrue(version.is_stable)
version = get_version("3.2")
self.assertEquals(version.major, 3)
self.assertEquals(version.minor, 2)
self.assertEquals(version.point, -1)
+ self.assertTrue(version.is_stable)
with self.assertRaises(models.InvalidShellVersion):
version = get_version("3.1")
+ # Test that we don't track shell versions for unstable extensions
+ # (it doesn't really matter because we can't really create a base
+ # shell version for unstable extensions *anyway*, but oh well)
+ version = get_version("3.1.4")
+ self.assertEquals(version.base_version, None)
+
+ # Test that we don't create shell versions
+ version = get_version("3.4.1")
+ self.assertEquals(lookup_version("3.4"), None)
+ self.assertEquals(version.base_version, None)
+
+ # OK, go and create the base version and make sure we track it
+ base_version = get_version("3.4")
+ self.assertEquals(version.base_version, base_version)
+
class UpdateVersionTest(TestCase):
fixtures = [os.path.join(testdata_dir, 'test_upgrade_data.json')]
diff --git a/sweettooth/extensions/views.py b/sweettooth/extensions/views.py
index b97da02..9fdd7e1 100644
--- a/sweettooth/extensions/views.py
+++ b/sweettooth/extensions/views.py
@@ -75,14 +75,24 @@ def shell_update(request):
return operations
+def get_versions_for_version_strings(version_strings):
+ for version_string in version_strings:
+ version = models.ShellVersion.objects.lookup_for_version_string(version_string)
+ if version is None:
+ continue
+ yield version
+
+ base_version = version.base_version
+ if base_version is None:
+ continue
+ yield base_version
+
def ajax_query_params_query(request):
query_params = {}
- versions = request.GET.getlist('shell_version')
- if versions:
- versions = [models.ShellVersion.objects.lookup_for_version_string(v) for v in versions]
- versions = [v for v in versions if v is not None]
- query_params['versions__shell_versions__in'] = versions
+ version_strings = request.GET.getlist('shell_version')
+ if version_strings:
+ query_params['versions__shell_versions__in'] = get_versions_for_version_strings(version_strings)
uuids = request.GET.getlist('uuid')
if uuids:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]