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

gcivil-nyu-org / INT2-Monday-Spring2024-Team-2 / 809

04 May 2024 03:36PM UTC coverage: 91.716%. Remained the same
809

Pull #253

travis-pro

web-flow
Merge 26fc3c1b5 into 48120f46f
Pull Request #253: Survey

2015 of 2197 relevant lines covered (91.72%)

1.37 hits per line

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

100.0
/Community/forms.py
1
from typing import Any
2✔
2
from django import forms
2✔
3
from TutorRegister.models import Post, Reply
2✔
4
from TutorRegister.presets import EXPERTISE_CHOICES
2✔
5

6

7
class CreatePostForm(forms.ModelForm):
2✔
8
    class Meta:
2✔
9
        model = Post
2✔
10

11
        fields = ["title", "content", "label", "attachment", "topics"]
2✔
12

13
        labels = {
2✔
14
            "title": "Title",
15
            "content": "Content",
16
            "label": "Label",
17
            "attachment": "Attachment",
18
            "topics": "Topic",
19
        }
20

21
        widgets = {
2✔
22
            "title": forms.TextInput(attrs={"class": "form-control"}),
23
            "content": forms.Textarea(attrs={"class": "form-control"}),
24
            "label": forms.RadioSelect(attrs={"class": "form-check-input"}),
25
            "attachment": forms.FileInput(attrs={"class": "form-control-file"}),
26
            "topics": forms.Select(attrs={"class": "form-control"}),
27
        }
28

29
    def __init__(self, *args, **kwargs):
2✔
30
        super(CreatePostForm, self).__init__(*args, **kwargs)
2✔
31

32
        self.fields["label"].choices = [
2✔
33
            ("resource", "Resource"),
34
            ("question", "Question"),
35
        ]
36

37
        self.fields["topics"] = forms.ChoiceField(
2✔
38
            choices=EXPERTISE_CHOICES,
39
            widget=self.Meta.widgets["topics"],
40
            required=False,
41
        )
42

43

44
class CreateReplyForm(forms.ModelForm):
2✔
45
    class Meta:
2✔
46
        model = Reply
2✔
47

48
        fields = ["content"]
2✔
49

50
        labels = {"content": "Content"}
2✔
51

52
        widgets = {"content": forms.Textarea(attrs={"class": "form-control"})}
2✔
53

54

55
class SearchFilterForm(forms.Form):
2✔
56
    search = forms.CharField(
2✔
57
        required=False,
58
        max_length=320,
59
        widget=forms.TextInput(
60
            attrs={"placeholder": "Search posts...", "class": "form-control"}
61
        ),
62
    )
63
    label = forms.ChoiceField(
2✔
64
        required=False,
65
        choices=[("", "None"), ("resource", "Resource"), ("question", "Question")],
66
        label="Label",
67
        widget=forms.Select(attrs={"class": "form-control"}),
68
    )
69
    topic = forms.ChoiceField(
2✔
70
        required=False,
71
        choices=[("", "None")] + EXPERTISE_CHOICES,
72
        label="Topic",
73
        widget=forms.Select(attrs={"class": "form-control"}),
74
    )
75
    sort = forms.ChoiceField(
2✔
76
        required=False,
77
        choices=[
78
            ("", "None"),
79
            ("highest_rating", "Highest Rating"),
80
            ("most_viewed", "Most Viewed"),
81
            ("earliest_post", "Earliest Post"),
82
        ],
83
        label="Sort",
84
        widget=forms.Select(attrs={"class": "form-control"}),
85
    )
86

87
    def clean(self):
2✔
88
        cleaned_data = super().clean()
1✔
89

90
        for key in cleaned_data:
1✔
91
            value = cleaned_data[key]
1✔
92
            if isinstance(value, str):
1✔
93
                cleaned_data[key] = value.strip()
1✔
94
            if not value:
1✔
95
                cleaned_data[key] = None
1✔
96

97
        return cleaned_data
1✔
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