• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ephios-dev / ephios / 16780026293

06 Aug 2025 02:35PM UTC coverage: 83.871% (-1.8%) from 85.684%
16780026293

Pull #1559

github

web-flow
Merge aa76b8638 into 103d9834b
Pull Request #1559: Add questionnaires

3532 of 4082 branches covered (86.53%)

Branch coverage included in aggregate %.

373 of 789 new or added lines in 28 files covered. (47.28%)

43 existing lines in 4 files now uncovered.

13160 of 15820 relevant lines covered (83.19%)

0.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.6
/ephios/plugins/questionnaires/forms.py
1
from django import forms
1✔
2
from django.db.models import Q
1✔
3
from django.utils.translation import gettext_lazy as _
1✔
4
from django_select2.forms import Select2MultipleWidget
1✔
5

6
from ephios.core.forms.events import BasePluginFormMixin
1✔
7
from ephios.plugins.questionnaires.models import Question, Questionnaire, SavedAnswer
1✔
8

9

10
class ChoiceForm(forms.Form):
1✔
11
    name = forms.CharField(
1✔
12
        label=_("Choice name"),
13
        max_length=100,
14
    )
15

16

17
ChoicesFormset = forms.formset_factory(ChoiceForm, can_delete=True, extra=2)
1✔
18

19

20
class QuestionForm(forms.ModelForm):
1✔
21
    class Meta:
1✔
22
        model = Question
1✔
23
        fields = ["name", "question_text", "description", "required", "type"]
1✔
24

25
    def __init__(self, data=None, **kwargs):
1✔
NEW
26
        super().__init__(data, **kwargs)
×
NEW
27
        self.choices = ChoicesFormset(
×
28
            initial=[{"name": choice} for choice in self.instance.choices],
29
            data=data,
30
            prefix="choices",
31
        )
32

33
    def save(self, commit=True):
1✔
NEW
34
        self.instance.choices = [
×
35
            choice_form_data["name"]
36
            for choice_form_data in self.choices.cleaned_data
37
            if choice_form_data and not choice_form_data["DELETE"]
38
        ]
NEW
39
        return super().save(commit)
×
40

41

42
class QuestionArchiveForm(forms.ModelForm):
1✔
43
    archived = forms.BooleanField(required=False, widget=forms.HiddenInput)
1✔
44

45
    class Meta:
1✔
46
        model = Question
1✔
47
        fields = ["archived"]
1✔
48

49
    def __init__(self, *args, set_archived: bool, **kwargs):
1✔
NEW
50
        kwargs["initial"] = {"archived": set_archived} | kwargs.get("initial", {})
×
NEW
51
        super().__init__(*args, **kwargs)
×
NEW
52
        self.set_archived = set_archived
×
53

54

55
class QuestionnaireForm(BasePluginFormMixin, forms.ModelForm):
1✔
56
    questions = forms.ModelMultipleChoiceField(
1✔
57
        queryset=Question.objects.filter(archived=False),
58
        widget=Select2MultipleWidget,
59
        required=False,
60
    )
61

62
    class Meta:
1✔
63
        model = Questionnaire
1✔
64
        fields = ["questions"]
1✔
65

66
    def __init__(self, *args, shift, **kwargs):
1✔
67
        kwargs.setdefault("prefix", "questionnaires")
1✔
68
        self.shift = shift
1✔
69
        try:
1✔
70
            kwargs.setdefault("instance", Questionnaire.objects.get(shift_id=shift.id))
1✔
71
        except (AttributeError, Questionnaire.DoesNotExist):
1✔
72
            pass
1✔
73
        super().__init__(*args, **kwargs)
1✔
74
        if self.instance.pk:
1!
NEW
75
            self.fields["questions"].queryset = Question.objects.filter(
×
76
                Q(archived=False) | Q(pk__in=self.instance.questions.values_list("pk", flat=True))
77
            )
78

79
    def save(self, commit=True):
1✔
80
        if self.cleaned_data.get("questions"):
1!
NEW
81
            self.instance.shift = self.shift
×
NEW
82
            super().save(commit)
×
83
        elif self.instance.pk:
1!
NEW
84
            self.instance.delete()
×
85

86
    @property
1✔
87
    def heading(self):
1✔
88
        return _("Questionnaire")
1✔
89

90
    def is_function_active(self):
1✔
91
        return self.instance.pk and self.instance.questions.count() > 0
1✔
92

93

94
class SavedAnswerForm(forms.ModelForm):
1✔
95
    class Meta:
1✔
96
        model = SavedAnswer
1✔
97
        fields = ["answer"]
1✔
98

99
    def __init__(self, *args, **kwargs):
1✔
NEW
100
        super().__init__(*args, **kwargs)
×
101

NEW
102
        self.fields["answer"] = self.instance.question.get_saved_answer_form_field()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc