prepare_filename_decorator()   B
last analyzed

Complexity

Conditions 5

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
c 2
b 0
f 0
dl 0
loc 17
rs 8.5454
1
# coding=utf-8
2
"""
3
"""
4
__author__ = 'Alisue <[email protected]>'
5
from functools import wraps
6
from roughpages.conf import settings
7
8
9
def prepare_filename_decorator(fn):
10
    """
11
    A decorator of `prepare_filename` method
12
13
    1. It automatically assign `settings.ROUGHPAGES_INDEX_FILENAME` if the
14
       `normalized_url` is ''.
15
    2. It automatically assign file extensions to the output list.
16
    """
17
    @wraps(fn)
18
    def inner(self, normalized_url, request):
19
        ext = settings.ROUGHPAGES_TEMPLATE_FILE_EXT
20
        if not normalized_url:
21
            normalized_url = settings.ROUGHPAGES_INDEX_FILENAME
22
        filenames = fn(self, normalized_url, request)
23
        filenames = [x + ext for x in filenames if x]
24
        return filenames
25
    return inner
26