File: views.py

package info (click to toggle)
freedombox 26.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 82,976 kB
  • sloc: python: 48,504; javascript: 1,736; xml: 481; makefile: 290; sh: 167; php: 32
file content (34 lines) | stat: -rw-r--r-- 975 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# SPDX-License-Identifier: AGPL-3.0-or-later
"""
Views for roundcube.
"""

from django.contrib import messages
from django.utils.translation import gettext_lazy as _

from plinth.views import AppView

from . import privileged
from .forms import RoundcubeForm


class RoundcubeAppView(AppView):
    """Roundcube configuration page."""
    app_id = 'roundcube'
    form_class = RoundcubeForm

    def get_initial(self):
        """Return the values to fill in the form."""
        initial = super().get_initial()
        initial['local_only'] = privileged.get_config()['local_only']
        return initial

    def form_valid(self, form):
        """Change the config of Roundcube app."""
        old_data = form.initial
        data = form.cleaned_data
        if old_data['local_only'] != data['local_only']:
            privileged.set_config(data['local_only'])
            messages.success(self.request, _('Configuration updated'))

        return super().form_valid(form)