@@ -41,6 +41,8 @@ def __init__(
4141 databases : Optional [dict ] = None ,
4242 media_directory : Optional [str ] = None ,
4343 static_directory : Optional [str ] = None ,
44+ media_url : Optional [str ] = None ,
45+ static_url : Optional [str ] = None ,
4446 debug : Optional [bool ] = None ,
4547 opts : Optional [dict ] = None ,
4648 request : Optional [HttpRequest ] = None ,
@@ -50,6 +52,8 @@ def __init__(
5052 self ._databases = databases or {}
5153 self ._media_directory = None
5254 self ._static_directory = None
55+ self ._media_url = media_url
56+ self ._static_url = static_url
5357 self ._debug = debug
5458 self ._request = request # passed when used in the context of a webserver.
5559 self ._session = None
@@ -120,6 +124,14 @@ def __init__(
120124 elif "CEI_NEXUS_LOCAL_STATIC_DIR" in os .environ :
121125 self ._static_directory = self ._check_dir (os .environ ["CEI_NEXUS_LOCAL_STATIC_DIR" ])
122126
127+ def _is_sqlite (self , database : str ) -> bool :
128+ return "sqlite" in self ._databases .get (database , {}).get ("ENGINE" , "" )
129+
130+ def _get_db_dir (self , database : str ) -> str :
131+ if self ._is_sqlite (database ):
132+ return self ._databases .get (database , {}).get ("NAME" , "" )
133+ return ""
134+
123135 def _get_install_directory (self , ansys_installation : str ) -> Path :
124136 dirs_to_check = []
125137 if ansys_installation :
@@ -209,6 +221,26 @@ def setup(self, collect_static: bool = False) -> None:
209221 if self ._static_directory is not None :
210222 overrides ["STATIC_ROOT" ] = str (self ._static_directory )
211223
224+ # relative URLs: By default, ADR serves static files from the URL /static/
225+ # and media files from the URL /media/. These can be changed using the
226+ # static_url and media_url options. URLs must be relative and start and end with
227+ # a forward slash.
228+ if self ._media_url is not None :
229+ if not self ._media_url .startswith ("/" ) or not self ._media_url .endswith ("/" ):
230+ raise ImproperlyConfiguredError (
231+ "The 'media_url' option must be a relative URL and start and end with a forward slash."
232+ " Example: '/media/'"
233+ )
234+ overrides ["MEDIA_URL" ] = self ._media_url
235+
236+ if self ._static_url is not None :
237+ if not self ._static_url .startswith ("/" ) or not self ._static_url .endswith ("/" ):
238+ raise ImproperlyConfiguredError (
239+ "The 'static_url' option must be a relative URL and start and end with a forward slash."
240+ " Example: '/static/'"
241+ )
242+ overrides ["STATIC_URL" ] = self ._static_url
243+
212244 if self ._databases :
213245 if "default" not in self ._databases :
214246 raise ImproperlyConfiguredError (
@@ -462,14 +494,6 @@ def create_objects(
462494 count += 1
463495 return count
464496
465- def _is_sqlite (self , database : str ) -> bool :
466- return "sqlite" in self ._databases [database ]["ENGINE" ]
467-
468- def _get_db_dir (self , database : str ) -> str :
469- if self ._is_sqlite (database ):
470- return self ._databases [database ]["NAME" ]
471- return ""
472-
473497 def _copy_template (self , template : Template , ** kwargs ) -> Template :
474498 # depth-first walk down from the root, which is 'template',
475499 # and copy the children along the way.
0 commit comments