aboutsummaryrefslogtreecommitdiff
path: root/newspipe/web/decorators.py
blob: c68edfee994acbf3d260c3fd0f458bdda45ee64e (plain)
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
#! /usr/bin/env python
# -*- coding: utf-8 -*-

from functools import wraps
from threading import Thread

from flask_login import login_required


def async_maker(f):
    """
    This decorator enables to launch a task (for examle sending an email or
    indexing the database) in background.
    This prevent the server to freeze.
    """

    def wrapper(*args, **kwargs):
        thr = Thread(target=f, args=args, kwargs=kwargs)
        thr.start()

    return wrapper


def pyagg_default_decorator(func):
    @login_required
    @wraps(func)
    def wrapper(*args, **kwargs):
        return func(*args, **kwargs)

    return wrapper
bgstack15