From 00e096ddf0654d32e67ac8bc47f3de01ed7e740b Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Thu, 28 Apr 2011 13:00:27 -0500 Subject: isotests: style cleanup, ui improvements * Using radio buttons for widgets is smarter. * Model names cleanup. * Test.ms: totally un-descriptive field name, should be modules. * models, Iso: Likely need more than a date field here. Removed date and added name. * get_success_test/get_failed_test: now on abstract superclass * tests.py: I wasn't using these, so I might as well remove it. * admin.py: convention is not to use * imports. * models.py: "# Create your models here." -> not needed. * urls.py: I wasn't using info_dict anymore; I had a blank second pattern definition, and I should follow indentation patterns from elsewhere in the project. * views.py, add: switched to using mostly direct_to_template to avoid some of the boilerplate. * isotest/templates: was old, not used. * I had 4 + 1 templates, but only two views- these other ones were old, unnecessary and not wired up. Signed-off-by: Dan McGee --- isotests/admin.py | 12 ++-- isotests/fixtures/hardware.json | 12 ++-- isotests/models.py | 135 ++++++++++++--------------------------- isotests/templates/iso_list.html | 2 - isotests/tests.py | 23 ------- isotests/urls.py | 12 +--- isotests/views.py | 66 +++++++++++-------- 7 files changed, 97 insertions(+), 165 deletions(-) delete mode 100644 isotests/templates/iso_list.html delete mode 100644 isotests/tests.py (limited to 'isotests') diff --git a/isotests/admin.py b/isotests/admin.py index b03ddea3..0cde0f83 100644 --- a/isotests/admin.py +++ b/isotests/admin.py @@ -1,14 +1,16 @@ -from isotests.models import * +from isotests.models import Iso, Architecture, IsoType, BootType +from isotests.models import HardwareType, InstallType, Source +from isotests.models import ClockChoice, Filesystem, Module, Bootloader from django.contrib import admin admin.site.register(Iso) admin.site.register(Architecture) -admin.site.register(Isotype) -admin.site.register(Boottype) -admin.site.register(Hardware) +admin.site.register(IsoType) +admin.site.register(BootType) +admin.site.register(HardwareType) admin.site.register(InstallType) admin.site.register(Source) -admin.site.register(Clockchoice) +admin.site.register(ClockChoice) admin.site.register(Filesystem) admin.site.register(Module) admin.site.register(Bootloader) diff --git a/isotests/fixtures/hardware.json b/isotests/fixtures/hardware.json index c9169146..335a50f6 100644 --- a/isotests/fixtures/hardware.json +++ b/isotests/fixtures/hardware.json @@ -1,42 +1,42 @@ [ { "pk": 1, - "model": "isotests.hardware", + "model": "isotests.hardwaretype", "fields": { "name": "virtualbox" } }, { "pk": 2, - "model": "isotests.hardware", + "model": "isotests.hardwaretype", "fields": { "name": "qemu" } }, { "pk": 3, - "model": "isotests.hardware", + "model": "isotests.hardwaretype", "fields": { "name": "intel i686" } }, { "pk": 4, - "model": "isotests.hardware", + "model": "isotests.hardwaretype", "fields": { "name": "intel x86_64" } }, { "pk": 5, - "model": "isotests.hardware", + "model": "isotests.hardwaretype", "fields": { "name": "amd i686" } }, { "pk": 6, - "model": "isotests.hardware", + "model": "isotests.hardwaretype", "fields": { "name": "amd x86_64" } diff --git a/isotests/models.py b/isotests/models.py index d9cfc78c..bffb2d94 100644 --- a/isotests/models.py +++ b/isotests/models.py @@ -1,128 +1,77 @@ from django.db import models from django.db.models import Max -from datetime import datetime -# Create your models here. -class Iso(models.Model): - date = models.DateField() - - def __unicode__(self): - return str(self.date) +class IsoOption(models.Model): + class Meta: + abstract = True -class Architecture(models.Model): name = models.CharField(max_length=200) def __unicode__(self): - return self.name + return str(self.name) def get_success_test(self): - return self.test_set.filter(success=True).aggregate(Max('iso__date'))['iso__date__max'] - def get_failed_test(self): - return self.test_set.filter(success=False).aggregate(Max('iso__date'))['iso__date__max'] - -class Isotype(models.Model): - name = models.CharField(max_length=200) + test = self.test_set.filter(success=True).annotate(Max('iso__id')) + if test: + return test[0].iso.name + return None - def __unicode__(self): - return self.name - def get_success_test(self): - return self.test_set.filter(success=True).aggregate(Max('iso__date'))['iso__date__max'] def get_failed_test(self): - return self.test_set.filter(success=False).aggregate(Max('iso__date'))['iso__date__max'] + test = self.test_set.filter(success=False).annotate(Max('iso__id')) + if test: + return test[0].iso.name + return None -class Boottype(models.Model): - name = models.CharField(max_length=200) +class Iso(models.Model): + name = models.CharField(max_length=500) + active = models.BooleanField(default=True) def __unicode__(self): return self.name - def get_success_test(self): - return self.test_set.filter(success=True).aggregate(Max('iso__date'))['iso__date__max'] - def get_failed_test(self): - return self.test_set.filter(success=False).aggregate(Max('iso__date'))['iso__date__max'] -class Hardware(models.Model): - name = models.CharField(max_length=200) +class Architecture(IsoOption): + pass - def __unicode__(self): - return self.name - def get_success_test(self): - return self.test_set.filter(success=True).aggregate(Max('iso__date'))['iso__date__max'] - def get_failed_test(self): - return self.test_set.filter(success=False).aggregate(Max('iso__date'))['iso__date__max'] +class IsoType(IsoOption): + pass -class InstallType(models.Model): - name = models.CharField(max_length=200) +class BootType(IsoOption): + pass - def __unicode__(self): - return self.name - def get_success_test(self): - return self.test_set.filter(success=True).aggregate(Max('iso__date'))['iso__date__max'] - def get_failed_test(self): - return self.test_set.filter(success=False).aggregate(Max('iso__date'))['iso__date__max'] +class HardwareType(IsoOption): + pass -class Source(models.Model): - name = models.CharField(max_length=200) +class InstallType(IsoOption): + pass - def __unicode__(self): - return self.name - def get_success_test(self): - return self.test_set.filter(success=True).aggregate(Max('iso__date'))['iso__date__max'] - def get_failed_test(self): - return self.test_set.filter(success=False).aggregate(Max('iso__date'))['iso__date__max'] - -class Clockchoice(models.Model): - name = models.CharField(max_length=200) - - def __unicode__(self): - return self.name - def get_success_test(self): - return self.test_set.filter(success=True).aggregate(Max('iso__date'))['iso__date__max'] - def get_failed_test(self): - return self.test_set.filter(success=False).aggregate(Max('iso__date'))['iso__date__max'] - -class Filesystem(models.Model): - name = models.CharField(max_length=200) - - def __unicode__(self): - return self.name - def get_success_test(self): - return self.test_set.filter(success=True).aggregate(Max('iso__date'))['iso__date__max'] - def get_failed_test(self): - return self.test_set.filter(success=False).aggregate(Max('iso__date'))['iso__date__max'] +class Source(IsoOption): + pass -class Module(models.Model): - name = models.CharField(max_length=200) +class ClockChoice(IsoOption): + pass - def __unicode__(self): - return self.name - def get_success_test(self): - return self.test_set.filter(success=True).aggregate(Max('iso__date'))['iso__date__max'] - def get_failed_test(self): - return self.test_set.filter(success=False).aggregate(Max('iso__date'))['iso__date__max'] +class Filesystem(IsoOption): + pass -class Bootloader(models.Model): - name = models.CharField(max_length=200) +class Module(IsoOption): + pass - def __unicode__(self): - return self.name - def get_success_test(self): - return self.test_set.filter(success=True).aggregate(Max('iso__date'))['iso__date__max'] - def get_failed_test(self): - return self.test_set.filter(success=False).aggregate(Max('iso__date'))['iso__date__max'] +class Bootloader(IsoOption): + pass class Test(models.Model): user_name = models.CharField(max_length=500) user_email = models.EmailField() iso = models.ForeignKey(Iso) - arch = models.ForeignKey(Architecture) - isotype = models.ForeignKey(Isotype) - boottype = models.ForeignKey(Boottype) - hardwaretype = models.ForeignKey(Hardware) - installtype = models.ForeignKey(InstallType) + architecture = models.ForeignKey(Architecture) + iso_type = models.ForeignKey(IsoType) + boot_type = models.ForeignKey(BootType) + hardware_type = models.ForeignKey(HardwareType) + install_type = models.ForeignKey(InstallType) source = models.ForeignKey(Source) - clock = models.ForeignKey(Clockchoice) + clock_choice = models.ForeignKey(ClockChoice) filesystem = models.ForeignKey(Filesystem) - ms = models.ManyToManyField(Module, null=True, blank=True) + modules = models.ManyToManyField(Module, null=True, blank=True) rollback = models.BooleanField() rollback_filesystem = models.ForeignKey(Filesystem, related_name="rollback_test", null=True, blank=True) diff --git a/isotests/templates/iso_list.html b/isotests/templates/iso_list.html deleted file mode 100644 index 06572739..00000000 --- a/isotests/templates/iso_list.html +++ /dev/null @@ -1,2 +0,0 @@ -hello there -bla diff --git a/isotests/tests.py b/isotests/tests.py deleted file mode 100644 index 2247054b..00000000 --- a/isotests/tests.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -This file demonstrates two different styles of tests (one doctest and one -unittest). These will both pass when you run "manage.py test". - -Replace these with more appropriate tests for your application. -""" - -from django.test import TestCase - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.failUnlessEqual(1 + 1, 2) - -__test__ = {"doctest": """ -Another way to test that 1 + 1 is equal to 2. - ->>> 1 + 1 == 2 -True -"""} - diff --git a/isotests/urls.py b/isotests/urls.py index e28497aa..f60f0bc9 100644 --- a/isotests/urls.py +++ b/isotests/urls.py @@ -1,16 +1,8 @@ from django.conf.urls.defaults import patterns -from isotests.models import Test - -info_dict = { - 'queryset': Test.objects.all() -} urlpatterns = patterns('isotests.views', - (r'^$', 'view_results'), - (r'^add/$', 'add_result') - ) - -urlpatterns += patterns('', + (r'^$', 'view_results'), + (r'^add/$', 'add_result') ) # vim: set ts=4 sw=4 et: diff --git a/isotests/views.py b/isotests/views.py index 738fa90d..cb7f23c5 100644 --- a/isotests/views.py +++ b/isotests/views.py @@ -1,50 +1,64 @@ -# Create your views here. from django.http import HttpResponse, HttpResponseRedirect -from django.forms import ModelForm, DateField -from isotests.models import * -from django.shortcuts import render_to_response -from django.template import RequestContext, Context, loader +from django.forms import ModelForm, RadioSelect, CheckboxSelectMultiple +from django.forms import ModelChoiceField +from isotests.models import Iso, Architecture, IsoType, BootType +from isotests.models import HardwareType, InstallType, Source, Test +from isotests.models import ClockChoice, Filesystem, Module, Bootloader +from django.template import Context, loader +from django.views.generic.simple import direct_to_template class TestForm(ModelForm): class Meta: model = Test + widgets = { + "architecture": RadioSelect(), + "iso_type": RadioSelect(), + "boot_type": RadioSelect(), + "hardware_type": RadioSelect(), + "install_type": RadioSelect(), + "source": RadioSelect(), + "clock_choice": RadioSelect(), + "filesystem": RadioSelect(), + "rollback_filesystem": RadioSelect(), + "bootloader": RadioSelect(), + "modules": CheckboxSelectMultiple(), + "rollback_modules": CheckboxSelectMultiple(), + } + iso = ModelChoiceField(queryset=Iso.objects.filter(active=True)) def add_result(request): - if request.method == 'POST': # If the form has been submitted... - form = TestForm(request.POST) # A form bound to the post data - if form.is_valid(): # All validation rules pass + if request.method == 'POST': + form = TestForm(request.POST) + if form.is_valid(): form.save() - return HttpResponseRedirect('/isotests') # Redirect after POST + return HttpResponseRedirect('/isotests') else: - form = TestForm() # An unbound form + form = TestForm() - return render_to_response('isotests/add.html', { 'form': form, }, - context_instance=RequestContext(request)) + context = {'form': form} + return direct_to_template(request, 'isotests/add.html', context) def view_results(request): - result_success_list = Test.objects.filter(success=True) - result_failed_list = Test.objects.filter(success=False) - architecture_list = Architecture.objects.all() - isotype_list = Isotype.objects.all() - boottype_list = Boottype.objects.all() - hardware_list = Hardware.objects.all() - installtype_list = InstallType.objects.all() + iso_type_list = IsoType.objects.all() + boot_type_list = BootType.objects.all() + hardware_type_list = HardwareType.objects.all() + install_type_list = InstallType.objects.all() source_list = Source.objects.all() - clockchoice_list = Clockchoice.objects.all() + clock_choice_list = ClockChoice.objects.all() module_list = Module.objects.all() filesystem_list = Filesystem.objects.all() bootloader_list = Bootloader.objects.all() t = loader.get_template("isotests/results.html") c = Context({ - 'arch_choices': architecture_list, - 'isotype_choices': isotype_list, - 'boottype_choices': boottype_list, - 'hardware_list': hardware_list, - 'installtype_list': installtype_list, + 'architecture_list': architecture_list, + 'iso_type_list': iso_type_list, + 'boot_type_list': boot_type_list, + 'hardware_type_list': hardware_type_list, + 'install_type_list': install_type_list, 'source_list': source_list, - 'clock_choices': clockchoice_list, + 'clock_choices_list': clock_choice_list, 'filesystem_list': filesystem_list, 'module_list': module_list, 'bootloader_list': bootloader_list, -- cgit v1.2.3-2-g168b