summaryrefslogtreecommitdiff
path: root/releng/views.py
blob: 796fc044dd01f2cea8bcf828283d5d64780a450d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
from django import forms
from django.conf import settings
from django.db.models import Count
from django.http import Http404
from django.shortcuts import get_object_or_404, redirect
from django.views.generic.simple import direct_to_template

from .models import (Architecture, BootType, Bootloader, ClockChoice,
        Filesystem, HardwareType, InstallType, Iso, IsoType, Module, Source,
        Test)

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'))
    architecture = standard_field(Architecture)
    iso_type = standard_field(IsoType)
    boot_type = standard_field(BootType)
    hardware_type = standard_field(HardwareType)
    install_type = standard_field(InstallType)
    source = standard_field(Source)
    clock_choice = standard_field(ClockChoice)
    filesystem = standard_field(Filesystem,
            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)
    bootloader = standard_field(Bootloader,
            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.",
            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.",
            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 " \
            "it in the comments.",
            required=False)
    website = forms.CharField(label='',
            widget=forms.TextInput(attrs={'style': 'display:none;'}), required=False)

    class Meta:
        model = Test
        fields = ("user_name", "user_email", "iso", "architecture",
                  "iso_type", "boot_type", "hardware_type",
                  "install_type", "source", "clock_choice", "filesystem",
                  "modules", "bootloader", "rollback_filesystem",
                  "rollback_modules", "success", "comments")
        widgets = {
            "modules": forms.CheckboxSelectMultiple(),
        }

def submit_test_result(request):
    if request.POST:
        form = TestForm(request.POST)
        if form.is_valid() and request.POST['website'] == '':
            test = form.save(commit=False)
            test.ip_address = request.META.get("REMOTE_ADDR", None)
            test.save()
            form.save_m2m()
            return redirect('releng-test-thanks')
    else:
        form = TestForm()

    context = {'form': form}
    return direct_to_template(request, 'releng/add.html', context)

def calculate_option_overview(field_name):
    field = Test._meta.get_field(field_name)
    model = field.rel.to
    is_rollback = field_name.startswith('rollback_')
    option = {
        'option': model,
        'name': field_name,
        'is_rollback': is_rollback,
        'values': []
    }
    for value in model.objects.all():
        data = { 'value': value }
        if is_rollback:
            data['success'] = value.get_last_rollback_success()
            data['failure'] = value.get_last_rollback_failure()
        else:
            data['success'] = value.get_last_success()
            data['failure'] = value.get_last_failure()
        option['values'].append(data)

    return option

def test_results_overview(request):
    # data structure produced:
    # [ { option, name, is_rollback, values: [ { value, success, failure } ... ] } ... ]
    all_options = []
    fields = [ 'architecture', 'iso_type', 'boot_type', 'hardware_type',
            'install_type', 'source', 'clock_choice', 'filesystem', 'modules',
            'bootloader', 'rollback_filesystem', 'rollback_modules' ]
    for field in fields:
        all_options.append(calculate_option_overview(field))

    context = {
            'options': all_options,
            'iso_url': settings.ISO_LIST_URL,
    }
    return direct_to_template(request, 'releng/results.html', context)

def test_results_iso(request, iso_id):
    iso = get_object_or_404(Iso, pk=iso_id)
    test_list = iso.test_set.select_related()
    context = {
        'iso_name': iso.name,
        'test_list': test_list
    }
    return direct_to_template(request, 'releng/result_list.html', context)

def test_results_for(request, option, value):
    if option not in Test._meta.get_all_field_names():
        raise Http404
    option_model = getattr(Test, option).field.rel.to
    real_value = get_object_or_404(option_model, pk=value)
    test_list = real_value.test_set.select_related().order_by(
            '-iso__name', '-pk')
    context = {
        'option': option,
        'value': real_value,
        'value_id': value,
        'test_list': test_list
    }
    return direct_to_template(request, 'releng/result_list.html', context)

def submit_test_thanks(request):
    return direct_to_template(request, "releng/thanks.html", None)

def iso_overview(request):
    isos = Iso.objects.all().order_by('-pk')
    successes = dict(Iso.objects.values_list('pk').filter(test__success=True).annotate(ct=Count('test')))
    failures = dict(Iso.objects.values_list('pk').filter(test__success=False).annotate(ct=Count('test')))
    for iso in isos:
        iso.successes = successes.get(iso.pk, 0)
        iso.failures = failures.get(iso.pk, 0)

    context = {
        'isos': isos
    }
    return direct_to_template(request, 'releng/iso_overview.html', context)

# vim: set ts=4 sw=4 et: