diff --git a/schoolapps/faq/admin.py b/schoolapps/faq/admin.py index 7e3ba6af8c234c7fe0a8dd98faa837e56ad7264c..4507a726511306807bdda1d93b81ce4ac28cfbc7 100644 --- a/schoolapps/faq/admin.py +++ b/schoolapps/faq/admin.py @@ -1,9 +1,8 @@ from django.contrib import admin -from faq.models import Question, FAQQuestion, FAQSection +from faq.models import FAQQuestion, FAQSection from django.utils.html import format_html -# Register your models here. def show(modeladmin, request, queryset): queryset.update(show=True) @@ -18,14 +17,6 @@ def hide(modeladmin, request, queryset): hide.short_description = "Ausgewählte Fragen nicht mehr veröffentlichen" -class QuestionAdmin(admin.ModelAdmin): - list_display = ("question_text", "pub_date", "user", "answered") - list_filter = ("answered",) - - -admin.site.register(Question, QuestionAdmin) - - class FAQSectionAdmin(admin.ModelAdmin): list_display = ("name", "_icon") diff --git a/schoolapps/faq/models.py b/schoolapps/faq/models.py index 5ff9a5a4c9c8ac52e82f226a98bfaa261476b4d9..177672ce6b6ea2fad7cdf4567216ecbaec654b0e 100644 --- a/schoolapps/faq/models.py +++ b/schoolapps/faq/models.py @@ -1,14 +1,18 @@ +import dbsettings from django.db import models from django.contrib.auth.models import User from .model_helper import COLORS, ICONS -# Create your models here. +class MailSettings(dbsettings.Group): + mail_questions = dbsettings.EmailValue("Email address for questions/help") + + class FAQSection(models.Model): name = models.CharField(max_length=200, verbose_name="Bezeichnung") icon = models.CharField(max_length=20, blank=True, default="question_answer", choices=ICONS, verbose_name="Symbol") - icon_color = models.CharField(max_length=10, default="black", choices=COLORS, verbose_name="Symbolfarbe") + icon_color = models.CharField(max_length=20, default="black", choices=COLORS, verbose_name="Symbolfarbe") def __str__(self): return self.name @@ -39,17 +43,4 @@ class FAQQuestion(models.Model): verbose_name_plural = "FAQ-Fragen" -class Question(models.Model): - question_text = models.TextField(verbose_name="Frage") - pub_date = models.DateTimeField(verbose_name="Veröffentlichungszeitpunkt") - - user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="Benutzer") - - answered = models.BooleanField(verbose_name="Beantwortet", default=False) - - def __str__(self): - return self.question_text - - class Meta: - verbose_name = "Frage" - verbose_name_plural = "Fragen" +mail_settings = MailSettings("Mail adresses") diff --git a/schoolapps/faq/templates/faq/ask.html b/schoolapps/faq/templates/faq/ask.html index 8ab712b21eb3f26ff872f14301816f283ca128cb..6c17f04745cd5802f9aef79e3e179e052c1cccd3 100644 --- a/schoolapps/faq/templates/faq/ask.html +++ b/schoolapps/faq/templates/faq/ask.html @@ -1,7 +1,7 @@ {% load widget_tweaks %} {% include 'partials/header.html' %} <main> - <h3 class="h-with-subtitle">Du hast eine Frage?</h3> + <h4 class="h-with-subtitle">Du hast eine Frage?</h4> <p class="flow-text"> Du hast eine Frage über SchoolApps oder andere Internetdienste des Katharineums und hast die Antwort auf deine Frage nicht in den diff --git a/schoolapps/faq/templates/faq/mail/question.html b/schoolapps/faq/templates/faq/mail/question.html new file mode 100755 index 0000000000000000000000000000000000000000..19ec7f214db6c59f150a157896d12b5beb400f02 --- /dev/null +++ b/schoolapps/faq/templates/faq/mail/question.html @@ -0,0 +1,11 @@ +{% include "mail/header.html" %} + +<main> + <blockquote> + Frage: {{ question }} + + <p>Übermittelt von {{ user.get_full_name }} ({{ user.username }})</p> + </blockquote> + + <em>Diese Frage wurde über SchoolApps übermittelt.</em> +</main> \ No newline at end of file diff --git a/schoolapps/faq/templates/faq/mail/question.txt b/schoolapps/faq/templates/faq/mail/question.txt new file mode 100755 index 0000000000000000000000000000000000000000..08abf00aed2e20db7a44b369cb5b0d7ab312b30f --- /dev/null +++ b/schoolapps/faq/templates/faq/mail/question.txt @@ -0,0 +1,6 @@ +Frage: {{ question }} + +Übermittelt von {{ user.get_full_name }} ({{ user.username }}) + + +Diese Frage wurde über SchoolApps übermittelt. \ No newline at end of file diff --git a/schoolapps/faq/urls.py b/schoolapps/faq/urls.py index 7af26253076537486ba5325d87208989e0662eb2..baf2cfe47913beace378ccd01f83fda6ef97ad6f 100644 --- a/schoolapps/faq/urls.py +++ b/schoolapps/faq/urls.py @@ -3,5 +3,5 @@ from . import views urlpatterns = [ path('', views.faq, name='faq'), - path('ask', views.ask, name='ask-faq') + path('ask/', views.ask, name='ask-faq') ] diff --git a/schoolapps/faq/views.py b/schoolapps/faq/views.py index 9ac63d6600d499f24a420f8a3fdec4ffc5627848..bdd7fc6b22117398cf1643f786b88b59aa0d69fd 100644 --- a/schoolapps/faq/views.py +++ b/schoolapps/faq/views.py @@ -1,13 +1,14 @@ -from django.shortcuts import render, redirect +from django.shortcuts import render from django.contrib.auth.decorators import login_required -from faq.models import FAQSection, FAQQuestion, Question +from faq.models import FAQSection, FAQQuestion, mail_settings from faq.forms import FAQForm from datetime import datetime from dashboard.models import Activity -# Create your views here. +from mailer import send_mail_with_template + def create_info(text): return '<div class="alert success"> <p> <i class="material-icons left">info</i>' + text + '</p> </div>' @@ -17,10 +18,11 @@ def faq(request): """ Shows the FAQ site, also if not logged in""" context = { "questions": FAQQuestion.objects.filter(show=True), - "sections": FAQSection.objects.all(), + "sections": FAQSection.objects.all(), } return render(request, 'faq/faq.html', context) + @login_required def ask(request): if request.method == 'POST': @@ -28,16 +30,20 @@ def ask(request): if form.is_valid(): # Read out form data question = form.cleaned_data['question'] - userid = request.user - - new_question = Question(question_text=question, pub_date=datetime.now(), user=userid) - - new_question.save() act = Activity(title="Du hast uns eine Frage gestellt.", description=question, app="FAQ", - user=userid) + user=request.user) act.save() + context = { + "question": question, + "user": request.user + } + send_mail_with_template("[FAQ QUESTION] {}".format(question), [mail_settings.mail_questions], + "faq/mail/question.txt", + "faq/mail/question.html", context, + "{} <{}>".format(request.user.get_full_name(), request.user.email)) + return render(request, 'faq/question_submitted.html') else: form = FAQForm() diff --git a/schoolapps/static/common/serviceworker.js b/schoolapps/static/common/serviceworker.js index 637d61da06351813116379fea7733931eb4a38ea..49e2e2f0960aa588ecdc29bcb22875383c42a9ff 100644 --- a/schoolapps/static/common/serviceworker.js +++ b/schoolapps/static/common/serviceworker.js @@ -24,20 +24,20 @@ const avoidCachingPaths = [ ]; function pathComparer(requestUrl, pathRegEx) { - return requestUrl.match(new RegExp(pathRegEx)); + return requestUrl.match(new RegExp(pathRegEx)); } function comparePaths(requestUrl, pathsArray) { - if (requestUrl) { - for (let index = 0; index < pathsArray.length; index++) { - const pathRegEx = pathsArray[index]; - if (pathComparer(requestUrl, pathRegEx)) { - return true; - } + if (requestUrl) { + for (let index = 0; index < pathsArray.length; index++) { + const pathRegEx = pathsArray[index]; + if (pathComparer(requestUrl, pathRegEx)) { + return true; + } + } } - } - return false; + return false; } self.addEventListener("install", function (event) { @@ -49,12 +49,12 @@ self.addEventListener("install", function (event) { event.waitUntil( caches.open(CACHE).then(function (cache) { console.log("[SchoolApps PWA] Caching pages during install."); - - return cache.addAll(precacheFiles).then(function () { - return cache.add(offlineFallbackPage); - }); - }) - ); + + return cache.addAll(precacheFiles).then(function () { + return cache.add(offlineFallbackPage); + }); + }) + ); }); // Allow sw to control of current page @@ -100,15 +100,14 @@ function fromCache(event) { return matching; }); - }); } function updateCache(request, response) { - if (!comparePaths(request.url, avoidCachingPaths)) { - return caches.open(CACHE).then(function (cache) { - return cache.put(request, response); - }); - } + if (!comparePaths(request.url, avoidCachingPaths)) { + return caches.open(CACHE).then(function (cache) { + return cache.put(request, response); + }); + } - return Promise.resolve(); + return Promise.resolve(); }