Completed
Pull Request — master (#51)
by Paolo
06:48
created

common.decorators.ajax_required()   A

Complexity

Conditions 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 2
nop 1
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
"""
4
Created on Mon Mar 18 12:21:07 2019
5
6
@author: Paolo Cozzi <[email protected]>
7
"""
8
9
from django.http import HttpResponseBadRequest
10
11
12
def ajax_required(f):
13
    def wrap(request, *args, **kwargs):
14
        if not request.is_ajax():
15
            return HttpResponseBadRequest()
16
17
        return f(request, *args, **kwargs)
18
19
    wrap.__doc__ = f.__doc__
20
    wrap.__name__ = f.__name__
21
22
    return wrap
23