[extensions-web] review: Fix issue with reviewing the first version of an extension



commit 95e13470777b3180d3d8420d2ec4791bf3c1ad66
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sun Mar 4 13:26:05 2012 -0500

    review: Fix issue with reviewing the first version of an extension

 sweettooth/review/tests.py |    3 ++-
 sweettooth/review/views.py |    7 ++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/sweettooth/review/tests.py b/sweettooth/review/tests.py
index 7b29abb..322474a 100644
--- a/sweettooth/review/tests.py
+++ b/sweettooth/review/tests.py
@@ -16,14 +16,15 @@ class DiffViewTest(BasicUserTestCase, TestCase):
         version1 = models.ExtensionVersion.objects.create(extension=extension,
                                                           source=File(ContentFile("doot doo"), name="aa"),
                                                           status=models.STATUS_NEW)
+        self.assertEquals(None, get_old_version(version1, None))
 
         # This one is broken...
         version2 = models.ExtensionVersion.objects.create(extension=extension,
                                                           source="",
                                                           status=models.STATUS_NEW)
+        self.assertEquals(version1, get_old_version(version2, None))
 
         version3 = models.ExtensionVersion.objects.create(extension=extension,
                                                           source=File(ContentFile("doot doo"), name="bb"),
                                                           status=models.STATUS_NEW)
-
         self.assertEquals(version1, get_old_version(version3, None))
diff --git a/sweettooth/review/views.py b/sweettooth/review/views.py
index 9d1490c..21233d9 100644
--- a/sweettooth/review/views.py
+++ b/sweettooth/review/views.py
@@ -98,7 +98,12 @@ def get_old_version(version, old_version_number):
         # Try to get the latest version that's less than the current version
         # that actually has a source field. Sometimes the upload validation
         # fails, so work around it here.
-        old_version = extension.versions.filter(version__lt=version.version).exclude(source="").latest()
+        try:
+            old_version = extension.versions.filter(version__lt=version.version).exclude(source="").latest()
+        except models.ExtensionVersion.DoesNotExist:
+            # There's nothing before us that has a source, or this is the
+            # first version.
+            return None
 
     return old_version
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]