From 8a6e120062147743387df346f0d9c591ecbccb60 Mon Sep 17 00:00:00 2001
From: Jonathan Weth <mail@jonathanweth.de>
Date: Sat, 4 Jan 2020 11:40:53 +0100
Subject: [PATCH] Setup dbsettings for more options
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

- mail out name and address, impress and privacy policy URL
- Move dbsettings to own file to prevent importing in circle
- Add context processor to provide dbsettings in templates
- Add "Katharineum zu Lübeck" in footer menu

Close #128
---
 aleksis/core/db_settings.py           | 29 +++++++++++++++
 aleksis/core/mailer.py                |  9 +++--
 aleksis/core/menus.py                 |  3 +-
 aleksis/core/models.py                | 10 ------
 aleksis/core/processors.py            |  5 +++
 aleksis/core/settings.py              |  1 +
 aleksis/core/templates/core/base.html | 51 +++++++++++++++------------
 aleksis/core/util/sass_helpers.py     |  2 +-
 8 files changed, 73 insertions(+), 37 deletions(-)
 create mode 100644 aleksis/core/db_settings.py
 create mode 100644 aleksis/core/processors.py

diff --git a/aleksis/core/db_settings.py b/aleksis/core/db_settings.py
new file mode 100644
index 000000000..7e5c82293
--- /dev/null
+++ b/aleksis/core/db_settings.py
@@ -0,0 +1,29 @@
+from django.utils.translation import ugettext_lazy as _
+
+import dbsettings
+
+
+class ThemeSettings(dbsettings.Group):
+    colour_primary = dbsettings.StringValue(_("Primary colour"), default="#007bff")
+    colour_secondary = dbsettings.StringValue(_("Secondary colour"), default="#007bff")
+
+
+class MailSettings(dbsettings.Group):
+    mail_out_name = dbsettings.StringValue(_("Mail out name"), default="AlekSIS", required=False)
+    mail_out = dbsettings.StringValue(_("Mail out address"), default="no-reply@aleksis.org")
+
+
+class FooterSettings(dbsettings.Group):
+    privacy_url = dbsettings.StringValue(_("Link to privacy policy"), default="")
+    impress_url = dbsettings.StringValue(_("Link to impress"), default="")
+
+
+theme_settings = ThemeSettings(_("Global theme settings"))
+mail_settings = MailSettings(_("Mail settings"))
+footer_settings = FooterSettings(_("Footer links"))
+
+db_settings = {
+    "theme": theme_settings,
+    "mail": mail_settings,
+    "footer": footer_settings
+}
diff --git a/aleksis/core/mailer.py b/aleksis/core/mailer.py
index 6cd4c0c98..8ae90edb9 100644
--- a/aleksis/core/mailer.py
+++ b/aleksis/core/mailer.py
@@ -1,10 +1,13 @@
 from django.core.mail import send_mail
 from django.template.loader import render_to_string
 
-SENDER_EMAIL = 'SchoolApps <infoplan@katharineum.de>'
+from aleksis.core.db_settings import mail_settings
 
+mail_out = "{} <{}>".format(mail_settings.mail_out_name,
+                            mail_settings.mail_out) if mail_settings.mail_out_name != "" else mail_settings.mail_out
 
-def send_mail_with_template(title, receivers, plain_template, html_template, context={}, sender_email=SENDER_EMAIL):
+
+def send_mail_with_template(title, receivers, plain_template, html_template, context={}, mail_out=mail_out):
     msg_plain = render_to_string(plain_template, context)
     msg_html = render_to_string(html_template, context)
 
@@ -12,7 +15,7 @@ def send_mail_with_template(title, receivers, plain_template, html_template, con
         send_mail(
             title,
             msg_plain,
-            sender_email,
+            mail_out,
             receivers,
             html_message=msg_html,
         )
diff --git a/aleksis/core/menus.py b/aleksis/core/menus.py
index c4ba24e2a..a7662bc71 100644
--- a/aleksis/core/menus.py
+++ b/aleksis/core/menus.py
@@ -129,8 +129,9 @@ MENUS = {
         },
     ],
     "FOOTER_MENU_CORE": [
-        {"name": _("Website"), "url": "https://aleksis.edugit.org/"},
+        {"name": _("Website"), "url": "https://aleksis.edugit.io/"},
         {"name": "Teckids e.V.", "url": "https://www.teckids.org/"},
+        {"name": "Katharineum zu Lübeck", "url": "https://katharineum-zu-luebeck.de"}
     ],
     "DATA_MANAGEMENT_MENU": [],
     "SCHOOL_MANAGEMENT_MENU": [
diff --git a/aleksis/core/models.py b/aleksis/core/models.py
index 811cfaeb0..c3faec8d5 100644
--- a/aleksis/core/models.py
+++ b/aleksis/core/models.py
@@ -5,8 +5,6 @@ from django.contrib.auth.models import User
 from django.db import models
 from django.utils import timezone
 from django.utils.translation import ugettext_lazy as _
-
-import dbsettings
 from image_cropping import ImageCropField, ImageRatioField
 from phonenumber_field.modelfields import PhoneNumberField
 
@@ -14,14 +12,6 @@ from .mailer import send_mail_with_template
 from .mixins import ExtensibleModel
 
 
-class ThemeSettings(dbsettings.Group):
-    colour_primary = dbsettings.StringValue(default="#007bff")
-    colour_secondary = dbsettings.StringValue(default="#007bff")
-
-
-theme_settings = ThemeSettings("Global theme settings")
-
-
 class School(models.Model):
     """A school that will have many other objects linked to it.
     AlekSIS has multi-tenant support by linking all objects to a school,
diff --git a/aleksis/core/processors.py b/aleksis/core/processors.py
new file mode 100644
index 000000000..fcfe15407
--- /dev/null
+++ b/aleksis/core/processors.py
@@ -0,0 +1,5 @@
+from aleksis.core.db_settings import db_settings
+
+
+def db_settings_processor(request):
+    return {"DB_SETTINGS": db_settings}
diff --git a/aleksis/core/settings.py b/aleksis/core/settings.py
index 55f09f24d..68d09cdca 100644
--- a/aleksis/core/settings.py
+++ b/aleksis/core/settings.py
@@ -119,6 +119,7 @@ TEMPLATES = [
                 "django.contrib.messages.context_processors.messages",
                 "maintenance_mode.context_processors.maintenance_mode",
                 "settings_context_processor.context_processors.settings",
+                "aleksis.core.processors.db_settings_processor"
             ],
         },
     },
diff --git a/aleksis/core/templates/core/base.html b/aleksis/core/templates/core/base.html
index 8b6995696..c2978a978 100644
--- a/aleksis/core/templates/core/base.html
+++ b/aleksis/core/templates/core/base.html
@@ -101,28 +101,35 @@
   </div>
   <div class="footer-copyright">
     <div class="container">
-            <span class="left">
-              <a class="blue-text text-lighten-4" href="https://aleksis.edugit.org/">
-                AlekSIS — The Free School Information System
-            </a>
-              © The AlekSIS Team @
-              <a class="blue-text text-lighten-4" href="https://www.teckids.org">
-              Teckids e.V.
-            </a>
-              and
-              <a class="blue-text text-lighten-4" href="https://katharineum-zu-luebeck.de">
-                Katharineum zu Lübeck
-              </a>
-            </span>
-      <span class="right">
-                <span id="doit"></span>
-
-                <a class="blue-text text-lighten-4" href="https://katharineum-zu-luebeck.de/impressum/">Impressum</a>
-                ·
-                <a class="blue-text text-lighten-4" href="https://katharineum-zu-luebeck.de/datenschutzerklaerung/">
-                    Datenschutzerklärung
-                </a>
-            </span>
+      <div class="left">
+        <a class="blue-text text-lighten-4" href="https://aleksis.edugit.org/">
+          AlekSIS — The Free School Information System
+        </a>
+        © The AlekSIS Team @
+        <a class="blue-text text-lighten-4" href="https://www.teckids.org">
+          Teckids e.V.
+        </a>
+        and
+        <a class="blue-text text-lighten-4" href="https://katharineum-zu-luebeck.de">
+          Katharineum zu Lübeck
+        </a>
+      </div>
+      <div class="right">
+        <span id="doit"></span>
+        {% if DB_SETTINGS.footer.impress_url %}
+          <a class="blue-text text-lighten-4" href="{{ DB_SETTINGS.footer.impress_url }}">
+            {% trans "Impress" %}
+          </a>
+        {% endif %}
+        {% if DB_SETTINGS.footer.privacy_url and DB_SETTINGS.footer.impress_url %}
+          ·
+        {% endif %}
+        {% if DB_SETTINGS.footer.privacy_url %}
+          <a class="blue-text text-lighten-4" href="{{ DB_SETTINGS.footer.privacy_url }}">
+            {% trans "Privacy Policy" %}
+          </a>
+        {% endif %}
+      </div>
     </div>
   </div>
 </footer>
diff --git a/aleksis/core/util/sass_helpers.py b/aleksis/core/util/sass_helpers.py
index 2bb44b09c..0c883ffd4 100644
--- a/aleksis/core/util/sass_helpers.py
+++ b/aleksis/core/util/sass_helpers.py
@@ -1,7 +1,7 @@
 from colour import web2hex
 from sass import SassColor
 
-from aleksis.core.models import theme_settings
+from aleksis.core.db_settings import theme_settings
 
 
 def get_colour(html_colour: str) -> SassColor:
-- 
GitLab