diff options
Diffstat (limited to 'releng/views.py')
-rw-r--r-- | releng/views.py | 98 |
1 files changed, 71 insertions, 27 deletions
diff --git a/releng/views.py b/releng/views.py index fc81d410..ad4b07d1 100644 --- a/releng/views.py +++ b/releng/views.py @@ -1,19 +1,23 @@ +from base64 import b64decode + from django import forms from django.conf import settings from django.db.models import Count, Max -from django.http import Http404 -from django.shortcuts import get_object_or_404, redirect -from django.views.generic.simple import direct_to_template +from django.http import Http404, HttpResponse +from django.shortcuts import get_object_or_404, redirect, render +from django.views.generic import DetailView, ListView from .models import (Architecture, BootType, Bootloader, ClockChoice, Filesystem, HardwareType, InstallType, Iso, IsoType, Module, Source, - Test) + Test, Release) + def standard_field(model, empty_label=None, help_text=None, required=True): return forms.ModelChoiceField(queryset=model.objects.all(), widget=forms.RadioSelect(), empty_label=empty_label, help_text=help_text, required=required) + class TestForm(forms.ModelForm): iso = forms.ModelChoiceField(queryset=Iso.objects.filter( active=True).order_by('-id')) @@ -25,29 +29,34 @@ class TestForm(forms.ModelForm): source = standard_field(Source) clock_choice = standard_field(ClockChoice) filesystem = standard_field(Filesystem, - help_text="Verify /etc/fstab, `df -hT` output and commands like " \ + help_text="Verify /etc/fstab, `df -hT` output and commands like " "lvdisplay for special modules.") modules = forms.ModelMultipleChoiceField(queryset=Module.objects.all(), - help_text="", widget=forms.CheckboxSelectMultiple(), required=False) + widget=forms.CheckboxSelectMultiple(), required=False) bootloader = standard_field(Bootloader, - help_text="Verify that the entries in the bootloader config looks OK.") + help_text="Verify that the entries in the bootloader config " + "looks OK.") rollback_filesystem = standard_field(Filesystem, - help_text="If you did a rollback followed by a new attempt to setup " \ - "your blockdevices/filesystems, select which option you took here.", + help_text="If you did a rollback followed by a new attempt to " + "setup your blockdevices/filesystems, select which option you " + "took here.", empty_label="N/A (did not rollback)", required=False) - rollback_modules = forms.ModelMultipleChoiceField(queryset=Module.objects.all(), - help_text="If you did a rollback followed by a new attempt to setup " \ - "your blockdevices/filesystems, select which option you took here.", + rollback_modules = forms.ModelMultipleChoiceField( + queryset=Module.objects.all(), + help_text="If you did a rollback followed by a new attempt to " + "setup your blockdevices/filesystems, select which option you " + "took here.", widget=forms.CheckboxSelectMultiple(), required=False) success = forms.BooleanField( - help_text="Only check this if everything went fine. " \ - "If you ran into problems please create a ticket on <a " \ - "href=\"https://bugs.archlinux.org/index.php?project=6\">the " \ - "bugtracker</a> (or check that one already exists) and link to " \ + help_text="Only check this if everything went fine. " + "If you ran into problems please create a ticket on <a " + "href=\"https://bugs.archlinux.org/index.php?project=6\">the " + "bugtracker</a> (or check that one already exists) and link to " "it in the comments.", required=False) website = forms.CharField(label='', - widget=forms.TextInput(attrs={'style': 'display:none;'}), required=False) + widget=forms.TextInput(attrs={'style': 'display:none;'}), + required=False) class Meta: model = Test @@ -60,6 +69,7 @@ class TestForm(forms.ModelForm): "modules": forms.CheckboxSelectMultiple(), } + def submit_test_result(request): if request.POST: form = TestForm(request.POST) @@ -73,7 +83,8 @@ def submit_test_result(request): form = TestForm() context = {'form': form} - return direct_to_template(request, 'releng/add.html', context) + return render(request, 'releng/add.html', context) + def calculate_option_overview(field_name): field = Test._meta.get_field(field_name) @@ -109,6 +120,7 @@ def calculate_option_overview(field_name): return option + def options_fetch_iso(options): '''Replaces the Iso PK with a full Iso model object in a list of options used on the overview page. We do it this way to only have to query the Iso @@ -129,13 +141,19 @@ def options_fetch_iso(options): return options + def test_results_overview(request): # data structure produced: - # [ { option, name, is_rollback, values: [ { value, success, failure } ... ] } ... ] + # [ { + # option, name, is_rollback, + # values: [ { value, success, failure } ... ] + # } + # ... + # ] all_options = [] - fields = [ 'architecture', 'iso_type', 'boot_type', 'hardware_type', + fields = ['architecture', 'iso_type', 'boot_type', 'hardware_type', 'install_type', 'source', 'clock_choice', 'filesystem', 'modules', - 'bootloader', 'rollback_filesystem', 'rollback_modules' ] + 'bootloader', 'rollback_filesystem', 'rollback_modules'] for field in fields: all_options.append(calculate_option_overview(field)) @@ -145,7 +163,8 @@ def test_results_overview(request): 'options': all_options, 'iso_url': settings.ISO_LIST_URL, } - return direct_to_template(request, 'releng/results.html', context) + return render(request, 'releng/results.html', context) + def test_results_iso(request, iso_id): iso = get_object_or_404(Iso, pk=iso_id) @@ -154,7 +173,8 @@ def test_results_iso(request, iso_id): 'iso_name': iso.name, 'test_list': test_list } - return direct_to_template(request, 'releng/result_list.html', context) + return render(request, 'releng/result_list.html', context) + def test_results_for(request, option, value): if option not in Test._meta.get_all_field_names(): @@ -170,10 +190,12 @@ def test_results_for(request, option, value): 'value_id': value, 'test_list': test_list } - return direct_to_template(request, 'releng/result_list.html', context) + return render(request, 'releng/result_list.html', context) + def submit_test_thanks(request): - return direct_to_template(request, "releng/thanks.html", None) + return render(request, "releng/thanks.html", None) + def iso_overview(request): isos = Iso.objects.all().order_by('-pk') @@ -187,11 +209,33 @@ def iso_overview(request): # only show "useful" rows, currently active ISOs or those with results isos = [iso for iso in isos if - iso.active == True or iso.successes > 0 or iso.failures > 0] + iso.active is True or iso.successes > 0 or iso.failures > 0] context = { 'isos': isos } - return direct_to_template(request, 'releng/iso_overview.html', context) + return render(request, 'releng/iso_overview.html', context) + + +class ReleaseListView(ListView): + model = Release + + +class ReleaseDetailView(DetailView): + model = Release + slug_field = 'version' + slug_url_kwarg = 'version' + + +def release_torrent(request, version): + release = get_object_or_404(Release, version=version) + if not release.torrent_data: + raise Http404 + data = b64decode(release.torrent_data) + response = HttpResponse(data, content_type='application/x-bittorrent') + # TODO: this is duplicated from Release.iso_url() + filename = 'archlinux-%s-dual.iso.torrent' % release.version + response['Content-Disposition'] = 'attachment; filename=%s' % filename + return response # vim: set ts=4 sw=4 et: |