From 24ff103528d1db63c748d1c0ec9ed7e199cefe1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sandstr=C3=B6m?= Date: Tue, 16 Apr 2024 13:02:34 +0200 Subject: [PATCH] add database model for maintenance mode info (#192) Co-authored-by: akochari --- common/admin.py | 3 ++- common/context_processors.py | 6 ++++++ common/migrations/0005_maintenancemode.py | 21 +++++++++++++++++++ common/models.py | 6 ++++++ .../templatetags/is_login_signup_disabled.py | 8 +++++++ portal/tests.py | 3 +++ studio/settings.py | 1 + templates/common/footer.html | 11 ++++++++++ templates/common/navbar.html | 21 ++++++++++++++++--- templates/portal/home.html | 2 ++ templates/registration/login.html | 8 ++++++- templates/registration/signup.html | 5 +++-- 12 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 common/context_processors.py create mode 100644 common/migrations/0005_maintenancemode.py create mode 100644 customtags/templatetags/is_login_signup_disabled.py diff --git a/common/admin.py b/common/admin.py index 991c863a..7721a7d0 100644 --- a/common/admin.py +++ b/common/admin.py @@ -2,7 +2,7 @@ from django.contrib.auth.admin import UserAdmin as DefaultUserAdmin from django.contrib.auth.models import User -from .models import EmailVerificationTable, UserProfile +from .models import EmailVerificationTable, MaintenanceMode, UserProfile class UserProfileInline(admin.StackedInline): @@ -32,5 +32,6 @@ def get_affiliation(self, instance): admin.site.unregister(User) admin.site.register(User, UserAdmin) +admin.site.register(MaintenanceMode) # Register your models here. diff --git a/common/context_processors.py b/common/context_processors.py new file mode 100644 index 00000000..70f90cd7 --- /dev/null +++ b/common/context_processors.py @@ -0,0 +1,6 @@ +from .models import MaintenanceMode + + +def maintenance_mode(request): + data = MaintenanceMode.objects.all() + return {"maintenance_mode": data} diff --git a/common/migrations/0005_maintenancemode.py b/common/migrations/0005_maintenancemode.py new file mode 100644 index 00000000..a8bc5655 --- /dev/null +++ b/common/migrations/0005_maintenancemode.py @@ -0,0 +1,21 @@ +# Generated by Django 4.2.7 on 2024-04-15 07:48 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("common", "0004_userprofile_deleted_on"), + ] + + operations = [ + migrations.CreateModel( + name="MaintenanceMode", + fields=[ + ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), + ("login_and_signup_disabled", models.BooleanField(default=False)), + ("message_in_header", models.TextField(blank=True, max_length=1000)), + ("message_in_footer", models.TextField(blank=True, max_length=1000)), + ], + ), + ] diff --git a/common/models.py b/common/models.py index 3b58968b..e1019d87 100644 --- a/common/models.py +++ b/common/models.py @@ -39,3 +39,9 @@ class FixtureVersion(models.Model): def __str__(self): return f"{self.filename} - {self.hash}" + + +class MaintenanceMode(models.Model): + login_and_signup_disabled = models.BooleanField(default=False) + message_in_header = models.TextField(max_length=1000, blank=True) + message_in_footer = models.TextField(max_length=1000, blank=True) diff --git a/customtags/templatetags/is_login_signup_disabled.py b/customtags/templatetags/is_login_signup_disabled.py new file mode 100644 index 00000000..7a7af8e5 --- /dev/null +++ b/customtags/templatetags/is_login_signup_disabled.py @@ -0,0 +1,8 @@ +from django import template + +register = template.Library() + + +@register.filter(name="is_login_signup_disabled") +def is_login_signup_disabled(queryset): + return queryset.filter(login_and_signup_disabled=True).exists() diff --git a/portal/tests.py b/portal/tests.py index 40d51f5f..0df530e3 100644 --- a/portal/tests.py +++ b/portal/tests.py @@ -44,6 +44,7 @@ def test_home_view_class(): assert "Home | SciLifeLab Serve (beta)" in response.content.decode() +@pytest.mark.django_db def test_about_view(): # Get correct request request = RequestFactory().get(reverse("portal:about")) @@ -54,6 +55,7 @@ def test_about_view(): assert "About | SciLifeLab Serve (beta)" in response.content.decode() +@pytest.mark.django_db def test_teaching_view(): # Get correct request request = RequestFactory().get(reverse("portal:teaching")) @@ -64,6 +66,7 @@ def test_teaching_view(): assert "Teaching | SciLifeLab Serve (beta)" in response.content.decode() +@pytest.mark.django_db def test_privacy_view(): # Get correct request request = RequestFactory().get(reverse("portal:privacy")) diff --git a/studio/settings.py b/studio/settings.py index 3ea2322c..8ed9d3ce 100644 --- a/studio/settings.py +++ b/studio/settings.py @@ -136,6 +136,7 @@ "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", + "common.context_processors.maintenance_mode", ] + DJANGO_WIKI_CONTEXT_PROCESSOR, "libraries": { diff --git a/templates/common/footer.html b/templates/common/footer.html index 81cab417..d5c942e4 100644 --- a/templates/common/footer.html +++ b/templates/common/footer.html @@ -6,7 +6,18 @@ {% get_setting "DEBUG" as debug_mode %}