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

rafalp / Misago / 9235638887

25 May 2024 12:58PM UTC coverage: 97.61% (-1.1%) from 98.716%
9235638887

Pull #1742

github

web-flow
Merge ef9c8656c into abad4f068
Pull Request #1742: Replace forum options with account settings

166 of 211 new or added lines in 20 files covered. (78.67%)

655 existing lines in 146 files now uncovered.

51625 of 52889 relevant lines covered (97.61%)

0.98 hits per line

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

72.09
/misago/threads/admin/forms.py
1
from django import forms
1✔
2
from django.utils.translation import pgettext, pgettext_lazy
1✔
3

4
from ..models import AttachmentType
1✔
5

6

7
def get_searchable_filetypes():
1✔
8
    choices = [(0, pgettext_lazy("admin attachments type filter choice", "All types"))]
1✔
9
    choices += [(a.id, a.name) for a in AttachmentType.objects.order_by("name")]
1✔
10
    return choices
1✔
11

12

13
class FilterAttachmentsForm(forms.Form):
1✔
14
    uploader = forms.CharField(
1✔
15
        label=pgettext_lazy("admin attachments filter form", "Uploader name contains"),
16
        required=False,
17
    )
18
    filename = forms.CharField(
1✔
19
        label=pgettext_lazy("admin attachments filter form", "Filename contains"),
20
        required=False,
21
    )
22
    filetype = forms.TypedChoiceField(
1✔
23
        label=pgettext_lazy("admin attachments filter form", "File type"),
24
        coerce=int,
25
        choices=get_searchable_filetypes,
26
        empty_value=0,
27
        required=False,
28
    )
29
    is_orphan = forms.ChoiceField(
1✔
30
        label=pgettext_lazy("admin attachments filter form", "State"),
31
        required=False,
32
        choices=[
33
            (
34
                "",
35
                pgettext_lazy(
36
                    "admin attachments orphan filter choice",
37
                    "All",
38
                ),
39
            ),
40
            (
41
                "yes",
42
                pgettext_lazy(
43
                    "admin attachments orphan filter choice",
44
                    "Only orphaned",
45
                ),
46
            ),
47
            (
48
                "no",
49
                pgettext_lazy(
50
                    "admin attachments orphan filter choice",
51
                    "Not orphaned",
52
                ),
53
            ),
54
        ],
55
    )
56

57
    def filter_queryset(self, criteria, queryset):
1✔
UNCOV
58
        if criteria.get("uploader"):
×
UNCOV
59
            queryset = queryset.filter(
×
60
                uploader_slug__contains=criteria["uploader"].lower()
61
            )
UNCOV
62
        if criteria.get("filename"):
×
UNCOV
63
            queryset = queryset.filter(filename__icontains=criteria["filename"])
×
UNCOV
64
        if criteria.get("filetype"):
×
UNCOV
65
            queryset = queryset.filter(filetype_id=criteria["filetype"])
×
UNCOV
66
        if criteria.get("is_orphan") == "yes":
×
UNCOV
67
            queryset = queryset.filter(post__isnull=True)
×
UNCOV
68
        elif criteria.get("is_orphan") == "no":
×
UNCOV
69
            queryset = queryset.filter(post__isnull=False)
×
UNCOV
70
        return queryset
×
71

72

73
class AttachmentTypeForm(forms.ModelForm):
1✔
74
    class Meta:
1✔
75
        model = AttachmentType
1✔
76
        fields = [
1✔
77
            "name",
78
            "extensions",
79
            "mimetypes",
80
            "size_limit",
81
            "status",
82
            "limit_uploads_to",
83
            "limit_downloads_to",
84
        ]
85
        labels = {
1✔
86
            "name": pgettext_lazy("admin attachment type form", "Type name"),
87
            "extensions": pgettext_lazy(
88
                "admin attachment type form", "File extensions"
89
            ),
90
            "mimetypes": pgettext_lazy("admin attachment type form", "Mimetypes"),
91
            "size_limit": pgettext_lazy(
92
                "admin attachment type form", "Maximum allowed uploaded file size"
93
            ),
94
            "status": pgettext_lazy("admin attachment type form", "Status"),
95
            "limit_uploads_to": pgettext_lazy(
96
                "admin attachment type form", "Limit uploads to"
97
            ),
98
            "limit_downloads_to": pgettext_lazy(
99
                "admin attachment type form", "Limit downloads to"
100
            ),
101
        }
102
        help_texts = {
1✔
103
            "extensions": pgettext_lazy(
104
                "admin attachment type form",
105
                "List of comma separated file extensions associated with this attachment type.",
106
            ),
107
            "mimetypes": pgettext_lazy(
108
                "admin attachment type form",
109
                "Optional list of comma separated mime types associated with this attachment type.",
110
            ),
111
            "size_limit": pgettext_lazy(
112
                "admin attachment type form",
113
                "Maximum allowed uploaded file size for this type, in kb. This setting is deprecated and has no effect. It will be deleted in Misago 1.0.",
114
            ),
115
            "status": pgettext_lazy(
116
                "admin attachment type form",
117
                "Controls this attachment type availability on your site.",
118
            ),
119
            "limit_uploads_to": pgettext_lazy(
120
                "admin attachment type form",
121
                "If you wish to limit option to upload files of this type to users with specific roles, select them on this list. Otherwise don't select any roles to allow all users with permission to upload attachments to be able to upload attachments of this type.",
122
            ),
123
            "limit_downloads_to": pgettext_lazy(
124
                "admin attachment type form",
125
                "If you wish to limit option to download files of this type to users with specific roles, select them on this list. Otherwise don't select any roles to allow all users with permission to download attachments to be able to download attachments of this type.",
126
            ),
127
        }
128
        widgets = {
1✔
129
            "limit_uploads_to": forms.CheckboxSelectMultiple,
130
            "limit_downloads_to": forms.CheckboxSelectMultiple,
131
        }
132

133
    def clean_extensions(self):
1✔
134
        data = self.clean_list(self.cleaned_data["extensions"])
1✔
135
        if not data:
1✔
UNCOV
136
            raise forms.ValidationError(
×
137
                pgettext("admin attachment type form", "This field is required.")
138
            )
139
        return data
1✔
140

141
    def clean_mimetypes(self):
1✔
142
        data = self.cleaned_data["mimetypes"]
1✔
143
        if data:
1✔
144
            return self.clean_list(data)
1✔
145

146
    def clean_list(self, value):
1✔
147
        items = [v.lstrip(".") for v in value.lower().replace(" ", "").split(",")]
1✔
148
        return ",".join(set(filter(bool, items)))
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