From b049f6eacee98f9459b86dd132ffa0ce8e1b676c Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Mon, 30 Jan 2023 23:19:30 -0600 Subject: [PATCH] Create option to use subdomain --- README.md | 2 ++ dmoj/settings.py | 3 +++ judge/middleware.py | 5 ++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 97c9512..7087452 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,8 @@ celery -A dmoj_celery worker node websocket/daemon.js ``` +7. To use subdomain for each organization, go to admin page -> navigation bar -> sites, add domain name (e.g, "localhost:8000"). Then go to add `USE_SUBDOMAIN = True` to local_settings.py. + ## Deploy Most of the steps are similar to Django tutorials. Here are two usual steps: diff --git a/dmoj/settings.py b/dmoj/settings.py index 80f42bc..b445574 100644 --- a/dmoj/settings.py +++ b/dmoj/settings.py @@ -469,6 +469,9 @@ MESSAGES_TO_LOAD = 15 ML_OUTPUT_PATH = None +# Use subdomain for organizations +USE_SUBDOMAIN = False + try: with open(os.path.join(os.path.dirname(__file__), "local_settings.py")) as f: exec(f.read(), globals()) diff --git a/judge/middleware.py b/judge/middleware.py index 159860e..931e047 100644 --- a/judge/middleware.py +++ b/judge/middleware.py @@ -95,10 +95,13 @@ class SubdomainMiddleware(object): self.get_response = get_response def __call__(self, request): + request.organization = None + if not settings.USE_SUBDOMAIN: + return self.get_response(request) + domain = request.get_host() site = get_current_site(request).domain subdomain = domain[: len(domain) - len(site)] - request.organization = None if len(subdomain) > 1: subdomain = subdomain[:-1] try: