Project

General

Profile

0001-misc-remove-unused-settings.CDNS-64434.patch

Frédéric Péters, 21 April 2022 02:38 PM

Download (2.13 KB)

View differences:

Subject: [PATCH] misc: remove unused settings.CDNS (#64434)

 README.txt                  |  5 -----
 gadjo/templatetags/gadjo.py | 24 ------------------------
 2 files changed, 29 deletions(-)
README.txt
21 21
  STATICFILES_FINDERS = global_settings.STATICFILES_FINDERS + \
22 22
    ('gadjo.finders.XStaticFinder',)
23 23

  
24
There is a CDNS settings, that can contain a list of (cdn name, protocol)
25
tuples; for example:
26

  
27
  CDNS = [('google', 'https')]
28

  
29 24

  
30 25
Additional static files
31 26
------------------------
gadjo/templatetags/gadjo.py
15 15

  
16 16
@register.simple_tag
17 17
def xstatic(modname, filename):
18
    try:
19
        # list of tuples of the form (cdnname, protocol)
20
        cdns = settings.CDNS
21
    except AttributeError:
22
        cdns = []
23 18
    if settings.DEBUG:
24 19
        filename = filename.replace('.min.', '.')
25

  
26
    if cdns:
27
        modname = str(modname.replace('-', '_'))
28
        pkg = __import__('xstatic.pkg', fromlist=[modname])
29
        mod = getattr(pkg, modname)
30
        for cdnname, protocol in cdns:
31
            try:
32
                base_url = XStatic(mod, provider=cdnname, protocol=protocol).base_url
33
            except KeyError:
34
                continue
35
            if isinstance(base_url, str):
36
                # base_url is often a str
37
                return base_url + '/' + filename
38
            else:
39
                # But it also can be a dict (which maps relative paths to
40
                # full urls) (this happens with jquery CDN)
41
                if filename in base_url:
42
                    return base_url.get(filename)
43

  
44 20
    return settings.STATIC_URL + 'xstatic/' + filename
45 21

  
46 22

  
47
-