Coverage for /Users/davegaeddert/Developer/dropseed/plain/plain/plain/assets/urls.py: 80%

15 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-23 11:16 -0600

1from plain.runtime import settings 

2from plain.urls import path, reverse 

3 

4from .fingerprints import get_fingerprinted_url_path 

5from .views import AssetView 

6 

7default_namespace = "assets" 

8 

9 

10def get_asset_url(url_path): 

11 if settings.DEBUG: 

12 # In debug, we only ever use the original URL path. 

13 resolved_url_path = url_path 

14 else: 

15 # If a fingerprinted URL path is available, use that. 

16 if fingerprinted_url_path := get_fingerprinted_url_path(url_path): 

17 resolved_url_path = fingerprinted_url_path 

18 else: 

19 resolved_url_path = url_path 

20 

21 # If a base url is set (i.e. a CDN), 

22 # then do a simple join to get the full URL. 

23 if settings.ASSETS_BASE_URL: 

24 return settings.ASSETS_BASE_URL + resolved_url_path 

25 

26 return reverse(default_namespace + ":asset", kwargs={"path": resolved_url_path}) 

27 

28 

29urlpatterns = [ 

30 path("<path:path>", AssetView, name="asset"), 

31]