From 1ff9c0fc5db1aab393eed5751e94ed8ac127c0c2 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 28 Apr 2011 17:44:43 -0500 Subject: isotests: massive overview refactor Copy pasted code sucks. Fix it. Also, ensure 500 errors aren't going to be popping up when people start typing invalid URLs for fun, among a lot of other small fixes going in here. Signed-off-by: Dan McGee --- isotests/models.py | 66 ++---- isotests/urls.py | 11 +- isotests/views.py | 84 ++++--- templates/isotests/result_list.html | 4 +- templates/isotests/result_section.html | 26 +++ templates/isotests/results.html | 411 +-------------------------------- 6 files changed, 110 insertions(+), 492 deletions(-) create mode 100644 templates/isotests/result_section.html diff --git a/isotests/models.py b/isotests/models.py index 1267fe85..de8dd13c 100644 --- a/isotests/models.py +++ b/isotests/models.py @@ -4,59 +4,43 @@ from django.db.models import Max class IsoOption(models.Model): - class Meta: - abstract = True - name = models.CharField(max_length=200) - success_tests = None - failed_tests = None - def __unicode__(self): - return str(self.name) - - def get_success_test(self): - if not self.success_tests: - self.success_tests = self.test_set.filter( - success=True).annotate(Max('iso__id')) + return self.name - if self.success_tests: - return self.success_tests[0].iso - return None + def get_test_result(self, success): + try: + return self.test_set.filter(success=success).select_related( + 'iso').latest('iso__id').iso + except Test.DoesNotExist: + return None - def get_failed_test(self): - if not self.failed_tests: - self.failed_tests = self.test_set.filter( - success=False).annotate(Max('iso__id')) + def get_last_success(self): + return self.get_test_result(True) - if self.failed_tests: - return self.failed_tests[0].iso - return None + def get_last_failure(self): + return self.get_test_result(False) -class RollbackOption(IsoOption): class Meta: abstract = True - success_rollback_tests = None - failed_rollback_tests = None - - def get_rollback_success_test(self): - if not self.success_rollback_tests: - self.success_rollback_tests = self.rollback_test_set.filter( - success=True).annotate(Max('iso__id')) +class RollbackOption(IsoOption): + def get_rollback_test_result(self, success): + try: + return self.rollback_test_set.filter(success=success).select_related( + 'iso').latest('iso__id').iso + except Test.DoesNotExist: + return None - if self.success_rollback_tests: - return self.success_rollback_tests[0].iso - return None + def get_last_rollback_success(self): + return self.get_rollback_test_result(True) - def get_rollback_failed_test(self): - if not self.failed_rollback_tests: - self.failed_rollback_tests = self.rollback_test_set.filter( - success=False).annotate(Max('iso__id')) + def get_last_rollback_failure(self): + return self.get_rollback_test_result(False) - if self.failed_rollback_tests: - return self.failed_rollback_tests[0].iso - return None + class Meta: + abstract = True class Iso(models.Model): name = models.CharField(max_length=255) @@ -112,11 +96,11 @@ class Test(models.Model): clock_choice = models.ForeignKey(ClockChoice) filesystem = models.ForeignKey(Filesystem) modules = models.ManyToManyField(Module, null=True, blank=True) + bootloader = models.ForeignKey(Bootloader) rollback_filesystem = models.ForeignKey(Filesystem, related_name="rollback_test_set", null=True, blank=True) rollback_modules = models.ManyToManyField(Module, related_name="rollback_test_set", null=True, blank=True) - bootloader = models.ForeignKey(Bootloader) success = models.BooleanField() comments = models.TextField(null=True, blank=True) diff --git a/isotests/urls.py b/isotests/urls.py index 7f438368..12497cde 100644 --- a/isotests/urls.py +++ b/isotests/urls.py @@ -1,12 +1,11 @@ from django.conf.urls.defaults import patterns urlpatterns = patterns('isotests.views', - (r'^$', 'view_results'), - (r'^add/$', 'add_result'), - (r'^thanks/$', 'thanks'), - (r'^results/$', 'view_results'), - (r'^results/(?P