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

liqd / a4-defakts / 13118789114

03 Feb 2025 04:48PM UTC coverage: 88.342% (+0.3%) from 88.022%
13118789114

push

github

m4ra
add projects tests from aplus

6070 of 6871 relevant lines covered (88.34%)

0.88 hits per line

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

96.23
/apps/projects/forms.py
1
from django import forms
1✔
2
from django.conf import settings
1✔
3
from django.contrib.auth import get_user_model
1✔
4
from django.core.exceptions import ValidationError
1✔
5
from django.utils.translation import gettext_lazy as _
1✔
6

7
from adhocracy4.dashboard.forms import ProjectDashboardForm
1✔
8
from adhocracy4.maps import widgets as maps_widgets
1✔
9
from adhocracy4.projects.models import Project
1✔
10
from apps.users import fields as user_fields
1✔
11

12
from .models import ModeratorInvite
1✔
13
from .models import ParticipantInvite
1✔
14

15
User = get_user_model()
1✔
16

17

18
class InviteForm(forms.ModelForm):
1✔
19
    accept = forms.CharField(required=False)
1✔
20
    reject = forms.CharField(required=False)
1✔
21

22
    def clean(self):
1✔
23
        data = self.data
1✔
24
        if "accept" not in data and "reject" not in data:
1✔
25
            raise ValidationError("Reject or accept")
×
26
        return data
1✔
27

28
    def is_accepted(self):
1✔
29
        data = self.data
1✔
30
        return "accept" in data and "reject" not in data
1✔
31

32

33
class ParticipantInviteForm(InviteForm):
1✔
34
    class Meta:
1✔
35
        model = ParticipantInvite
1✔
36
        fields = ["accept", "reject"]
1✔
37

38

39
class ModeratorInviteForm(InviteForm):
1✔
40
    class Meta:
1✔
41
        model = ModeratorInvite
1✔
42
        fields = ["accept", "reject"]
1✔
43

44

45
class InviteUsersFromEmailForm(forms.Form):
1✔
46
    add_users = user_fields.CommaSeparatedEmailField(
1✔
47
        required=False, label=_("Invite users via email")
48
    )
49

50
    add_users_upload = user_fields.EmailFileField(
1✔
51
        required=False,
52
        label=_("Invite users via file upload"),
53
        help_text=_("Upload a csv file containing email addresses."),
54
    )
55

56
    def __init__(self, *args, **kwargs):
1✔
57
        labels = kwargs.pop("labels", None)
1✔
58
        super().__init__(*args, **kwargs)
1✔
59

60
        if labels:
1✔
61
            self.fields["add_users"].label = labels[0]
1✔
62
            self.fields["add_users_upload"].label = labels[1]
1✔
63

64
    def clean(self):
1✔
65
        cleaned_data = super().clean()
1✔
66
        add_users = self.data.get("add_users")
1✔
67
        add_users_upload = self.files.get("add_users_upload")
1✔
68
        if not self.errors and not add_users and not add_users_upload:
1✔
69
            raise ValidationError(_("Please enter email addresses or upload a file"))
×
70
        return cleaned_data
1✔
71

72

73
class PointForm(ProjectDashboardForm):
1✔
74
    class Meta:
1✔
75
        model = Project
1✔
76
        fields = ["administrative_district", "point"]
1✔
77
        required_for_project_publish = []
1✔
78
        widgets = {
1✔
79
            "point": maps_widgets.MapChoosePointWidget(polygon=settings.BERLIN_POLYGON),
80
        }
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