• 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

0.0
/apps/account/views.py
1
from django.conf import settings
×
2
from django.contrib.auth import logout
×
3
from django.contrib.auth.mixins import LoginRequiredMixin
×
4
from django.contrib.messages.views import SuccessMessageMixin
×
5
from django.core.exceptions import ValidationError
×
6
from django.db import transaction
×
7
from django.shortcuts import get_object_or_404
×
8
from django.utils.translation import gettext_lazy as _
×
9
from django.views import generic
×
10
from django.views.generic.base import RedirectView
×
11

12
from apps.users.models import User
×
13
from apps.users.utils import set_session_language
×
14

15
from . import forms
×
16
from .emails import AccountDeletionEmail
×
17

18

19
class AccountView(RedirectView):
×
20
    permanent = False
×
21
    pattern_name = "account_profile"
×
22
    # Placeholder View to be replaced if we want to use a custom account
23
    # dashboard function overview.
24

25

26
class ProfileUpdateView(LoginRequiredMixin, SuccessMessageMixin, generic.UpdateView):
×
27
    model = User
×
28
    template_name = "a4_candy_account/profile.html"
×
29
    form_class = forms.ProfileForm
×
30
    success_message = _("Your profile was successfully updated.")
×
31

32
    def get_object(self):
×
33
        return get_object_or_404(User, pk=self.request.user.id)
×
34

35
    def get_success_url(self):
×
36
        return self.request.path
×
37

38
    def form_valid(self, form):
×
39
        set_session_language(self.request.user.email, form.cleaned_data["language"])
×
40
        return super(ProfileUpdateView, self).form_valid(form)
×
41

42
    def render_to_response(self, context, **response_kwargs):
×
43
        set_session_language(self.request.user.email, self.request.user.language)
×
44
        response = super().render_to_response(context, **response_kwargs)
×
45
        response.set_cookie(settings.LANGUAGE_COOKIE_NAME, self.request.user.language)
×
46
        return response
×
47

48

49
class AccountDeletionView(LoginRequiredMixin, SuccessMessageMixin, generic.DeleteView):
×
50
    template_name = "a4_candy_account/account_deletion.html"
×
51
    form_class = forms.AccountDeletionForm
×
52
    success_message = _("Your account was successfully deleted.")
×
53
    success_url = "/"
×
54

55
    def get_object(self):
×
56
        return get_object_or_404(User, pk=self.request.user.id)
×
57

58
    def form_valid(self, form):
×
59
        user = self.request.user
×
60
        password = form.cleaned_data.get("password")
×
61
        if not user.check_password(password):
×
62
            form.add_error(
×
63
                "password", ValidationError("Incorrect password.", "invalid")
64
            )
65
            return super().form_invalid(form)
×
66
        logout(self.request)
×
67
        AccountDeletionEmail.send(user)
×
68
        return super().form_valid(form)
×
69

70

71
class OrganisationTermsOfUseUpdateView(
×
72
    LoginRequiredMixin, SuccessMessageMixin, generic.UpdateView
73
):
74
    model = User
×
75
    template_name = "a4_candy_account/user_agreements.html"
×
76
    form_class = forms.OrganisationTermsOfUseForm
×
77
    success_message = _("Your agreements were successfully updated.")
×
78

79
    def get_object(self):
×
80
        return get_object_or_404(User, pk=self.request.user.id)
×
81

82
    def get_success_url(self):
×
83
        return self.request.path
×
84

85
    def get_context_data(self, **kwargs):
×
86
        context = super().get_context_data(**kwargs)
×
87
        if self.request.POST:
×
88
            context["formset"] = forms.OrganisationTermsOfUseFormSet(
×
89
                self.request.POST, instance=self.get_object()
90
            )
91
        else:
92
            context["formset"] = forms.OrganisationTermsOfUseFormSet(
×
93
                instance=self.get_object()
94
            )
95
        return context
×
96

97
    def form_valid(self, form):
×
98
        context = self.get_context_data()
×
99
        formset = context["formset"]
×
100
        with transaction.atomic():
×
101
            if formset.is_valid():
×
102
                formset.instance = self.get_object()
×
103
                formset.save()
×
104
        return super().form_valid(form)
×
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