Coverage for src/backend/InvenTree/web/urls.py: 100%

8 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 17:47 +0000

1"""URLs for web app.""" 

2 

3from django.conf import settings 

4from django.urls import include, path, re_path 

5from django.views.decorators.csrf import ensure_csrf_cookie 

6from django.views.generic import RedirectView, TemplateView 

7 

8spa_view = ensure_csrf_cookie(TemplateView.as_view(template_name='web/index.html')) 

9 

10 

11def cui_compatibility_urls(base: str) -> list: 

12 """Generate a list of URL patterns for compatibility with old (CUI) URLs. 

13 

14 These URLs are provided for backwards compatibility with older versions of InvenTree, 

15 before we moved to a SPA (Single Page Application) architecture in the 1.0.0 release. 

16 

17 At some future point these may be removed? 

18 

19 Args: 

20 base (str): The base URL to use for generating the patterns. 

21 

22 Returns: 

23 list: A list of URL patterns. 

24 """ 

25 return [ 

26 # Old 'index' view - reroute to the dashboard 

27 path('index/', RedirectView.as_view(url=f'/{base}')), 

28 path('settings/', RedirectView.as_view(url=f'/{base}/settings')), 

29 # Company patterns 

30 path( 

31 'company/', 

32 include([ 

33 path( 

34 'customers/', 

35 RedirectView.as_view(url=f'/{base}/sales/index/customers'), 

36 ), 

37 path( 

38 'manufacturers/', 

39 RedirectView.as_view(url=f'/{base}/purchasing/index/manufacturers'), 

40 ), 

41 path( 

42 'suppliers/', 

43 RedirectView.as_view(url=f'/{base}/purchasing/index/suppliers'), 

44 ), 

45 re_path( 

46 r'(?P<pk>\d+)/', RedirectView.as_view(url=f'/{base}/company/%(pk)s') 

47 ), 

48 ]), 

49 ), 

50 # "Part" app views 

51 re_path( 

52 r'^part/(?P<path>.*)$', RedirectView.as_view(url=f'/{base}/part/%(path)s') 

53 ), 

54 # "Stock" app views 

55 re_path( 

56 r'^stock/(?P<path>.*)$', RedirectView.as_view(url=f'/{base}/stock/%(path)s') 

57 ), 

58 # "Build" app views (requires some custom handling) 

59 path( 

60 'build/', 

61 include([ 

62 re_path( 

63 r'^(?P<pk>\d+)/', 

64 RedirectView.as_view( 

65 url=f'/{base}/manufacturing/build-order/%(pk)s' 

66 ), 

67 ), 

68 re_path('.*', RedirectView.as_view(url=f'/{base}/manufacturing/')), 

69 ]), 

70 ), 

71 # "Order" app views 

72 path( 

73 'order/', 

74 include([ 

75 path( 

76 'purchase-order/', 

77 include([ 

78 re_path( 

79 r'^(?P<pk>\d+)/', 

80 RedirectView.as_view( 

81 url=f'/{base}/purchasing/purchase-order/%(pk)s' 

82 ), 

83 ), 

84 re_path( 

85 '.*', 

86 RedirectView.as_view( 

87 url=f'/{base}/purchasing/index/purchaseorders/' 

88 ), 

89 ), 

90 ]), 

91 ), 

92 path( 

93 'sales-order/', 

94 include([ 

95 re_path( 

96 r'^(?P<pk>\d+)/', 

97 RedirectView.as_view( 

98 url=f'/{base}/sales/sales-order/%(pk)s' 

99 ), 

100 ), 

101 re_path( 

102 '.*', 

103 RedirectView.as_view( 

104 url=f'/{base}/sales/index/salesorders/' 

105 ), 

106 ), 

107 ]), 

108 ), 

109 path( 

110 'return-order/', 

111 include([ 

112 re_path( 

113 r'^(?P<pk>\d+)/', 

114 RedirectView.as_view( 

115 url=f'/{base}/sales/return-order/%(pk)s' 

116 ), 

117 ), 

118 re_path( 

119 '.*', 

120 RedirectView.as_view( 

121 url=f'/{base}/sales/index/returnorders/' 

122 ), 

123 ), 

124 ]), 

125 ), 

126 ]), 

127 ), 

128 ] 

129 

130 

131urlpatterns = [ 

132 path( 

133 f'{settings.FRONTEND_URL_BASE}/', 

134 include([ 

135 path( 

136 'set-password?uid=<uid>&token=<token>', 

137 spa_view, 

138 name='password_reset_confirm', 

139 ), 

140 re_path('.*', spa_view, name='web-wildcard'), 

141 ]), 

142 ), 

143 path(settings.FRONTEND_URL_BASE, spa_view, name='web'), 

144]