Passed
Push — master ( 62d7d9...8230b1 )
by Alexander
03:29
created

tcms.bugs.forms   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 28
dl 0
loc 62
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A NewBugForm.populate() 0 7 2
A BugCommentForm.populate() 0 2 1
1
# Copyright (c) 2019 Alexander Todorov <[email protected]>
2
3
# Licensed under the GPL 2.0: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
4
5
from django import forms
6
from django.utils.translation import ugettext_lazy as _
7
8
from tcms.bugs.models import Bug
9
from tcms.core.widgets import SimpleMDE
10
from tcms.management.models import Version, Build
11
12
13
class NewBugForm(forms.ModelForm):
14
    class Meta:
15
        model = Bug
16
        fields = ['summary', 'assignee', 'reporter', 'product', 'version', 'build']
17
18
    text = forms.CharField(
19
        widget=SimpleMDE(),
20
        required=False,
21
        initial=_("""Description of problem:
22
23
24
How often reproducible:
25
26
27
Steps to Reproduce:
28
1.
29
2.
30
3.
31
32
Actual results:
33
34
35
Expected results:
36
37
38
Additional info:
39
"""))
40
41
    def populate(self, product_id=None):
42
        if product_id:
43
            self.fields['version'].queryset = Version.objects.filter(product_id=product_id)
44
            self.fields['build'].queryset = Build.objects.filter(product_id=product_id)
45
        else:
46
            self.fields['version'].queryset = Version.objects.all()
47
            self.fields['build'].queryset = Build.objects.all()
48
49
50
class BugCommentForm(forms.Form):
51
    bug = forms.ModelChoiceField(
52
        queryset=Bug.objects.all(),
53
    )
54
55
    text = forms.CharField(
56
        widget=SimpleMDE(),
57
        required=False,
58
    )
59
60
    def populate(self, bug_id):
61
        self.fields['bug'].queryset = Bug.objects.filter(pk=bug_id)
62