Server IP : 85.214.239.14 / Your IP : 3.146.206.87 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 : /proc/2/root/proc/2/cwd/proc/2/root/srv/modoboa/env/lib/python3.5/site-packages/reversion/ |
Upload File : |
from functools import wraps from reversion.revisions import create_revision as create_revision_base, set_user, get_user class _RollBackRevisionView(Exception): def __init__(self, response): self.response = response def _request_creates_revision(request): return request.method not in ("OPTIONS", "GET", "HEAD") def _set_user_from_request(request): if getattr(request, "user", None) and request.user.is_authenticated and get_user() is None: set_user(request.user) def create_revision(manage_manually=False, using=None, atomic=True, request_creates_revision=None): """ View decorator that wraps the request in a revision. The revision will have it's user set from the request automatically. """ request_creates_revision = request_creates_revision or _request_creates_revision def decorator(func): @wraps(func) def do_revision_view(request, *args, **kwargs): if request_creates_revision(request): try: with create_revision_base(manage_manually=manage_manually, using=using, atomic=atomic): response = func(request, *args, **kwargs) # Check for an error response. if response.status_code >= 400: raise _RollBackRevisionView(response) # Otherwise, we're good. _set_user_from_request(request) return response except _RollBackRevisionView as ex: return ex.response return func(request, *args, **kwargs) return do_revision_view return decorator class RevisionMixin(object): """ A class-based view mixin that wraps the request in a revision. The revision will have it's user set from the request automatically. """ revision_manage_manually = False revision_using = None revision_atomic = True def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.dispatch = create_revision( manage_manually=self.revision_manage_manually, using=self.revision_using, atomic=self.revision_atomic, request_creates_revision=self.revision_request_creates_revision )(self.dispatch) def revision_request_creates_revision(self, request): return _request_creates_revision(request)