aboutsummaryrefslogtreecommitdiffstats
path: root/manage.py
diff options
context:
space:
mode:
authorGravatar Hassan Abouelela <[email protected]>2021-10-10 01:28:39 +0300
committerGravatar Hassan Abouelela <[email protected]>2021-10-10 01:28:39 +0300
commite9c4cdf56e2efd65786a4cf4aee0bb4e4e56bc95 (patch)
tree6c64590e814c3a55eacec9e7bdbb2a5deffc76ba /manage.py
parentMerge pull request #603 from python-discord/decrease-batch-size-for-user-list... (diff)
Adds Django Distill To Project
Adds django-distill to dependencies, and lays the basic groundwork to start building static routes. Adds a poetry task to help with testing.
Diffstat (limited to 'manage.py')
-rwxr-xr-xmanage.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/manage.py b/manage.py
index 578f4748..357134ec 100755
--- a/manage.py
+++ b/manage.py
@@ -1,6 +1,8 @@
#!/usr/bin/env python
import os
+import platform
import sys
+from pathlib import Path
import django
from django.contrib.auth import get_user_model
@@ -147,6 +149,22 @@ class SiteManager:
gunicorn.app.wsgiapp.run()
+def clean_up_static_files(build_folder: Path) -> None:
+ """Recursively loop over the build directory and fix links."""
+ for file in build_folder.iterdir():
+ if file.is_dir():
+ clean_up_static_files(file)
+ elif file.name.endswith(".html"):
+ # Fix parent host url
+ new = file.read_text(encoding="utf-8").replace(f"//{os.getenv('PARENT_HOST')}", "")
+
+ # Fix windows paths if on windows
+ if platform.system() == "Windows":
+ new = new.replace("%5C", "/")
+
+ file.write_text(new, encoding="utf-8")
+
+
def main() -> None:
"""Entry point for Django management script."""
# Use the custom site manager for launching the server
@@ -155,8 +173,21 @@ def main() -> None:
# Pass any others directly to standard management commands
else:
+ if _static_build := "distill" in sys.argv[1]:
+ # Build a static version of the site with no databases and API support
+ os.environ["STATIC_BUILD"] = "True"
+ if not os.getenv("PARENT_HOST"):
+ os.environ["PARENT_HOST"] = "REPLACE_THIS.HOST"
+
execute_from_command_line(sys.argv)
+ if _static_build:
+ # Clean up parent host in generated files
+ for arg in sys.argv[2:]:
+ if not arg.startswith("-"):
+ clean_up_static_files(Path(arg))
+ break
+
if __name__ == '__main__':
main()