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

liqd / adhocracy-plus / 18908688697

29 Oct 2025 12:59PM UTC coverage: 44.622% (-44.5%) from 89.135%
18908688697

Pull #2986

github

web-flow
Merge 1dfde8ee7 into 445e1d498
Pull Request #2986: Draft: Speed up Github Ci Tests

3012 of 6750 relevant lines covered (44.62%)

0.45 hits per line

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

38.89
/apps/organisations/mixins.py
1
from django import forms
1✔
2
from django.urls import reverse
1✔
3
from django.utils.html import mark_safe
1✔
4
from django.utils.translation import gettext_lazy as _
1✔
5
from django.views.generic import FormView
1✔
6

7
from apps.organisations.models import OrganisationTermsOfUse
1✔
8

9

10
class OrganisationTermsOfUseMixin(forms.ModelForm):
1✔
11
    """
12
    Add org terms checkbox to form when user has not yet agreed.
13

14
    Make sure, that the user is added to the form_kwargs in the
15
    respective view. You can use the UserFormViewMixin to do that.
16
    """
17

18
    organisation_terms_of_use = forms.BooleanField(
1✔
19
        required=False,
20
        help_text=_("You can still manage all your preferences on User Agreements."),
21
    )
22

23
    def __init__(self, *args, **kwargs):
1✔
24
        self.user = kwargs.pop("user")
×
25
        super().__init__(*args, **kwargs)
×
26

27
        self.fields["organisation_terms_of_use"].label = self._get_terms_of_use_label
×
28

29
        if self.user.has_agreed_on_org_terms(self.module.project.organisation):
×
30
            del self.fields["organisation_terms_of_use"]
×
31

32
    def clean(self):
1✔
33
        cleaned_data = super().clean()
×
34
        if "organisation_terms_of_use" in cleaned_data:
×
35
            organisation_terms_of_use = cleaned_data.get("organisation_terms_of_use")
×
36
            if not organisation_terms_of_use:
×
37
                self.add_error(
×
38
                    "organisation_terms_of_use",
39
                    _(
40
                        "Please agree on the organisation's terms "
41
                        "of use to be allowed to create content."
42
                    ),
43
                )
44
        return cleaned_data
×
45

46
    def save(self, commit=True):
1✔
47
        instance = super().save(commit=commit)
×
48
        if commit and "organisation_terms_of_use" in self.cleaned_data:
×
49
            OrganisationTermsOfUse.objects.update_or_create(
×
50
                user=self.user,
51
                organisation=self.module.project.organisation,
52
                defaults={"has_agreed": self.cleaned_data["organisation_terms_of_use"]},
53
            )
54
        return instance
×
55

56
    def _get_terms_of_use_label(self):
1✔
57
        label_text = _(
×
58
            "Yes, I have read and agree to this organisation's " "{}terms of use{}."
59
        )
60
        url = reverse(
×
61
            "organisation-terms-of-use",
62
            kwargs={"organisation_slug": self.module.project.organisation.slug},
63
        )
64
        label = label_text.format('<a href="' + url + '" target="_blank">', "</a>")
×
65
        return mark_safe(label)
×
66

67

68
class UserFormViewMixin(FormView):
1✔
69
    """Adds the user from the request to the form_kwargs."""
70

71
    def get_form_kwargs(self):
1✔
72
        kwargs = super().get_form_kwargs()
×
73
        kwargs["user"] = self.request.user
×
74
        return kwargs
×
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

© 2025 Coveralls, Inc