summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-04-28 13:59:53 -0500
committerDan McGee <dan@archlinux.org>2011-04-28 14:00:54 -0500
commit6516220b17d7987900961863a0b6dec23ac14855 (patch)
tree8988d3233e32c6038f6c069d742e2896673a6b98
parent1ea5be1a0693d8f24b5d147092fd4a15c7fdd4a7 (diff)
isotests: update some syntax and ways of doing things
To be more Django-like, Pythonic, or to fit better in the existing archweb project. Also add some created fields to the models, as storing dates for anything is almost always a good idea. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--isotests/admin.py5
-rw-r--r--isotests/management/commands/syncisos.py17
-rw-r--r--isotests/models.py31
-rw-r--r--isotests/views.py64
-rw-r--r--settings.py4
5 files changed, 67 insertions, 54 deletions
diff --git a/isotests/admin.py b/isotests/admin.py
index 17303c58..10acaa98 100644
--- a/isotests/admin.py
+++ b/isotests/admin.py
@@ -1,8 +1,7 @@
from django.contrib import admin
-from isotests.models import Iso, Architecture, IsoType, BootType
-from isotests.models import HardwareType, InstallType, Source
-from isotests.models import ClockChoice, Filesystem, Module, Bootloader
+from .models import (Architecture, BootType, Bootloader, ClockChoice,
+ Filesystem, HardwareType, InstallType, Iso, IsoType, Module, Source)
admin.site.register(Iso)
admin.site.register(Architecture)
diff --git a/isotests/management/commands/syncisos.py b/isotests/management/commands/syncisos.py
index 4cc6908e..9c76ccda 100644
--- a/isotests/management/commands/syncisos.py
+++ b/isotests/management/commands/syncisos.py
@@ -2,10 +2,10 @@ import re
import urllib
from HTMLParser import HTMLParser, HTMLParseError
+from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from isotests.models import Iso
-from settings import ISOLISTURL
class IsoListParser(HTMLParser):
def __init__(self):
@@ -23,25 +23,22 @@ class IsoListParser(HTMLParser):
def parse(self, url):
try:
- f = urllib.urlopen(url)
-
- s = f.read()
- f.close()
-
- self.feed(s)
+ remote_file = urllib.urlopen(url)
+ data = remote_file.read()
+ remote_file.close()
+ self.feed(data)
self.close()
-
return self.hyperlinks
except HTMLParseError:
raise CommandError('Couldn\'t parse "%s"' % url)
class Command(BaseCommand):
- help = 'Gets new isos from %s' % ISOLISTURL
+ help = 'Gets new isos from %s' % settings.ISO_LIST_URL
def handle(self, *args, **options):
parser = IsoListParser()
isonames = Iso.objects.values_list('name', flat=True)
- new_isos = parser.parse(ISOLISTURL)
+ new_isos = parser.parse(settings.ISO_LIST_URL)
for iso in new_isos:
if iso not in isonames:
diff --git a/isotests/models.py b/isotests/models.py
index 7b7eb5e7..55c1bd0d 100644
--- a/isotests/models.py
+++ b/isotests/models.py
@@ -1,3 +1,5 @@
+from datetime import datetime
+
from django.db import models
from django.db.models import Max
@@ -15,7 +17,8 @@ class IsoOption(models.Model):
def get_success_test(self):
if not self.success_tests:
- self.success_tests = self.test_set.filter(success=True).annotate(Max('iso__id'))
+ self.success_tests = self.test_set.filter(
+ success=True).annotate(Max('iso__id'))
if self.success_tests:
return self.success_tests[0].iso
@@ -23,7 +26,8 @@ class IsoOption(models.Model):
def get_failed_test(self):
if not self.failed_tests:
- self.failed_tests = self.test_set.filter(success=False).annotate(Max('iso__id'))
+ self.failed_tests = self.test_set.filter(
+ success=False).annotate(Max('iso__id'))
if self.failed_tests:
return self.failed_tests[0].iso
@@ -38,7 +42,8 @@ class RollbackOption(IsoOption):
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'))
+ self.success_rollback_tests = self.rollback_test_set.filter(
+ success=True).annotate(Max('iso__id'))
if self.success_rollback_tests:
return self.success_rollback_tests[0].iso
@@ -46,14 +51,16 @@ class RollbackOption(IsoOption):
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'))
+ self.failed_rollback_tests = self.rollback_test_set.filter(
+ success=False).annotate(Max('iso__id'))
if self.failed_rollback_tests:
return self.failed_rollback_tests[0].iso
return None
class Iso(models.Model):
- name = models.CharField(max_length=500)
+ name = models.CharField(max_length=255)
+ created = models.DateTimeField(editable=False)
active = models.BooleanField(default=True)
def __unicode__(self):
@@ -92,6 +99,7 @@ class Bootloader(IsoOption):
class Test(models.Model):
user_name = models.CharField(max_length=500)
user_email = models.EmailField()
+ created = models.DateTimeField(editable=False)
iso = models.ForeignKey(Iso)
architecture = models.ForeignKey(Architecture)
iso_type = models.ForeignKey(IsoType)
@@ -110,4 +118,17 @@ class Test(models.Model):
success = models.BooleanField()
comments = models.TextField(null=True, blank=True)
+def set_created_field(sender, **kwargs):
+ # We use this same callback for both Isos and Tests
+ obj = kwargs['instance']
+ if not obj.created:
+ obj.created = datetime.utcnow()
+
+from django.db.models.signals import pre_save
+
+pre_save.connect(set_created_field, sender=Iso,
+ dispatch_uid="isotests.models")
+pre_save.connect(set_created_field, sender=Test,
+ dispatch_uid="isotests.models")
+
# vim: set ts=4 sw=4 et:
diff --git a/isotests/views.py b/isotests/views.py
index dd041ebc..0bb92356 100644
--- a/isotests/views.py
+++ b/isotests/views.py
@@ -1,15 +1,12 @@
-from django.forms import ModelChoiceField, CharField, TextInput
-from django.forms import ModelForm, RadioSelect, CheckboxSelectMultiple
-from django.forms import ModelMultipleChoiceField, BooleanField
-from django.http import HttpResponse, HttpResponseRedirect
-from django.template import Context, loader
+from django import forms
+from django.http import HttpResponseRedirect
from django.views.generic.simple import direct_to_template
-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 .models import (Architecture, BootType, Bootloader, ClockChoice,
+ Filesystem, HardwareType, InstallType, Iso, IsoType, Module, Source,
+ Test)
-class TestForm(ModelForm):
+class TestForm(forms.ModelForm):
class Meta:
model = Test
fields = ("user_name", "user_email", "iso", "architecture",
@@ -18,35 +15,35 @@ class TestForm(ModelForm):
"modules", "rollback_filesystem", "rollback_modules",
"bootloader", "success", "comments")
widgets = {
- "architecture": RadioSelect(),
- "iso_type": RadioSelect(),
- "boot_type": RadioSelect(),
- "hardware_type": RadioSelect(),
- "install_type": RadioSelect(),
- "source": RadioSelect(),
- "clock_choice": RadioSelect(),
- "bootloader": RadioSelect(),
- "modules": CheckboxSelectMultiple(),
+ "architecture": forms.RadioSelect(),
+ "iso_type": forms.RadioSelect(),
+ "boot_type": forms.RadioSelect(),
+ "hardware_type": forms.RadioSelect(),
+ "install_type": forms.RadioSelect(),
+ "source": forms.RadioSelect(),
+ "clock_choice": forms.RadioSelect(),
+ "bootloader": forms.RadioSelect(),
+ "modules": forms.CheckboxSelectMultiple(),
}
- success = BooleanField(help_text="Only check this if everything went fine. " \
+ success = forms.BooleanField(help_text="Only check this if everything went fine. " \
"If you you ran into any errors please specify them in the " \
"comments.", required=False)
- iso = ModelChoiceField(queryset=Iso.objects.filter(active=True))
- filesystem = ModelChoiceField(queryset=Filesystem.objects.all(),
+ iso = forms.ModelChoiceField(queryset=Iso.objects.filter(active=True))
+ filesystem = forms.ModelChoiceField(queryset=Filesystem.objects.all(),
help_text="Check the installed system, including fstab.",
- widget=RadioSelect())
- modules = ModelMultipleChoiceField(queryset=Module.objects.all(),
- help_text="", widget=CheckboxSelectMultiple(), required=False)
- rollback_filesystem = ModelChoiceField(queryset=Filesystem.objects.all(),
+ widget=forms.RadioSelect())
+ modules = forms.ModelMultipleChoiceField(queryset=Module.objects.all(),
+ help_text="", widget=forms.CheckboxSelectMultiple(), required=False)
+ rollback_filesystem = forms.ModelChoiceField(queryset=Filesystem.objects.all(),
help_text="If you did a rollback followed by a new attempt to setup " \
"your lockdevices/filesystems, select which option you took here.",
- widget=RadioSelect(), required=False)
- rollback_modules = ModelMultipleChoiceField(queryset=Module.objects.all(),
+ widget=forms.RadioSelect(), required=False)
+ rollback_modules = forms.ModelMultipleChoiceField(queryset=Module.objects.all(),
help_text="If you did a rollback followed b a new attempt to setup " \
"your lockdevices/filesystems, select which option you took here.",
- widget=CheckboxSelectMultiple(), required=False)
- website = CharField(label='',
- widget=TextInput(attrs={'style': 'display:none;'}), required=False)
+ widget=forms.CheckboxSelectMultiple(), required=False)
+ website = forms.CharField(label='',
+ widget=forms.TextInput(attrs={'style': 'display:none;'}), required=False)
def add_result(request):
if request.POST:
@@ -72,8 +69,7 @@ def view_results(request):
filesystem_list = Filesystem.objects.all()
bootloader_list = Bootloader.objects.all()
- t = loader.get_template("isotests/results.html")
- c = Context({
+ context = {
'architecture_list': architecture_list,
'iso_type_list': iso_type_list,
'boot_type_list': boot_type_list,
@@ -84,8 +80,8 @@ def view_results(request):
'filesystem_list': filesystem_list,
'module_list': module_list,
'bootloader_list': bootloader_list,
- })
- return HttpResponse(t.render(c))
+ }
+ return direct_to_template(request, 'isotests/results.html', context)
def view_results_iso(request, isoid):
iso = Iso.objects.get(pk=isoid)
diff --git a/settings.py b/settings.py
index d4d3d96b..a21205d3 100644
--- a/settings.py
+++ b/settings.py
@@ -124,7 +124,7 @@ if DEBUG_TOOLBAR:
INSTALLED_APPS = list(INSTALLED_APPS) + [ 'debug_toolbar' ]
-# rtf settings
-ISOLISTURL = 'http://releng.archlinux.org/isos/'
+# URL to fetch a current list of available ISOs
+ISO_LIST_URL = 'http://releng.archlinux.org/isos/'
# vim: set ts=4 sw=4 et: