Skip to content

Commit

Permalink
add database model for maintenance mode info (#192)
Browse files Browse the repository at this point in the history
Co-authored-by: akochari <[email protected]>
  • Loading branch information
sandstromviktor and akochari authored Apr 16, 2024
1 parent 50b2829 commit 24ff103
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 7 deletions.
3 changes: 2 additions & 1 deletion common/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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.
6 changes: 6 additions & 0 deletions common/context_processors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from .models import MaintenanceMode


def maintenance_mode(request):
data = MaintenanceMode.objects.all()
return {"maintenance_mode": data}
21 changes: 21 additions & 0 deletions common/migrations/0005_maintenancemode.py
Original file line number Diff line number Diff line change
@@ -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)),
],
),
]
6 changes: 6 additions & 0 deletions common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 8 additions & 0 deletions customtags/templatetags/is_login_signup_disabled.py
Original file line number Diff line number Diff line change
@@ -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()
3 changes: 3 additions & 0 deletions portal/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def test_home_view_class():
assert "<title>Home | SciLifeLab Serve (beta)</title>" in response.content.decode()


@pytest.mark.django_db
def test_about_view():
# Get correct request
request = RequestFactory().get(reverse("portal:about"))
Expand All @@ -54,6 +55,7 @@ def test_about_view():
assert "<title>About | SciLifeLab Serve (beta)</title>" in response.content.decode()


@pytest.mark.django_db
def test_teaching_view():
# Get correct request
request = RequestFactory().get(reverse("portal:teaching"))
Expand All @@ -64,6 +66,7 @@ def test_teaching_view():
assert "<title>Teaching | SciLifeLab Serve (beta)</title>" in response.content.decode()


@pytest.mark.django_db
def test_privacy_view():
# Get correct request
request = RequestFactory().get(reverse("portal:privacy"))
Expand Down
1 change: 1 addition & 0 deletions studio/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
11 changes: 11 additions & 0 deletions templates/common/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@
{% get_setting "DEBUG" as debug_mode %}

<div class="footer border-top bg-light text-muted small pt-4 mt-auto">

<div class="container">

{# In case we want to display a maintenance message or similar#}
{% for obj in maintenance_mode %}
{% if obj.message_in_footer %}
<div class="alert alert-warning small" role="alert">
{{ obj.message_in_footer }}
</div>
{% endif %}
{% endfor %}

<div class="row pb-2">
<div class="col-lg-2">
<ul class="list-unstyled">
Expand Down
21 changes: 18 additions & 3 deletions templates/common/navbar.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load static %}

{% load is_login_signup_disabled %}
<nav class="bg-light shadow-sm mb-3 py-2">
<div class="container">
<div class="row">
Expand Down Expand Up @@ -53,10 +53,10 @@
{% else %}

<li class="nav-item flex-wrap">
<a class="btn btn-profile order-lg-2 order-1 mx-2" href="{% url 'common:signup' %}">
<a class="btn btn-profile order-lg-2 order-1 mx-2 {% if maintenance_mode|is_login_signup_disabled %}disabled{% endif %}" href="{% url 'common:signup' %}">
<i class="bi bi-person-plus"></i> Register
</a>
<a class="btn btn-profile order-lg-1 order-2 mx-2" href="{% url 'login' %}">
<a class="btn btn-profile order-lg-1 order-2 mx-2 {% if maintenance_mode|is_login_signup_disabled %}disabled{% endif %}" href="{% url 'login' %}">
<i class="bi bi-box-arrow-in-right"></i> Log in
</a>
</li>
Expand All @@ -67,3 +67,18 @@
</div>
</div>
</nav>

{% for obj in maintenance_mode %}
{% if obj.message_in_header %}
<div class="container">
<div class="row d-flex justify-content-center">
<div class="col-12 col-md-8 text-center">
<div class="alert alert-warning border" role="alert">
<p class="mb-0 fs-5"><i class="bi-exclamation-triangle"></i></p>
<p>{{ obj.message_in_header | safe }}</p>
</div>
</div>
</div>
</div>
{% endif %}
{% endfor %}
2 changes: 2 additions & 0 deletions templates/portal/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ <h5 class="">{{ model.name|truncatechars:30 }}</h5>
</div>
</div>

{% if news_objects %}
<div class="row text-center mt-5">
<div class="col-12 text-center">
<h3>News
Expand Down Expand Up @@ -175,6 +176,7 @@ <h5 class="text-grape">{{ news.title }}</h5>
</div>
{% endif %}
</div>
{% endif %}

{% if collection_objects %}
<div class="row text-center mt-5 align-items-center" id="collections">
Expand Down
8 changes: 7 additions & 1 deletion templates/registration/login.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
{% extends 'base.html' %}
{% load static %}

{% load is_login_signup_disabled %}
{% block title %}Login{% endblock %}

{% block content %}

<div class="container">
<!-- Outer Row -->
{% if not maintenance_mode|is_login_signup_disabled %}
<div class="row justify-content-center">
<div class="col-12 col-md-9">
{% include 'common/flash_messages.html' %}
<div class="card border-0 shadow-lg my-5 py-5">
<div class="card-body">
<!-- Nested Row within Card Body -->
<div class="col-lg-6 offset-lg-3">

<div class="col text-center">
<h2 class="text-dark mb-4">Log in</h2>
</div>
Expand All @@ -36,6 +38,8 @@ <h2 class="text-dark mb-4">Log in</h2>
</div>
{% endif %}



<div class="py-4 d-flex justify-content-center">

<div class="w-100">
Expand All @@ -61,11 +65,13 @@ <h2 class="text-dark mb-4">Log in</h2>
<div class="text-center">
<a href="{% url 'common:signup' %}">Don't have an account? Sign up here</a>
</div>

</div>
</div>
</div>
</div>
</div>
{% endif %}
</div>


Expand Down
5 changes: 3 additions & 2 deletions templates/registration/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
{% block title %}Register{% endblock %}

{% load static %}

{% load is_login_signup_disabled %}
{% block extra_scripts %}
<script src="{% static 'js/form-helpers.js' %}"></script>
{% endblock %}


{% block content %}
<div class="container">
{% if not maintenance_mode|is_login_signup_disabled %}
<div class="card border-0 shadow-lg my-5">
<div class="card-body p-0">
<!-- Nested Row within Card Body -->
Expand Down Expand Up @@ -180,6 +181,6 @@ <h2 class="text-dark mb-4 text-center">Register</h2>
</div>
</div>
</div>
</div>
{% endif %}
</div>
{% endblock %}

0 comments on commit 24ff103

Please sign in to comment.