public-health-ch/publichealth/home/models/admin.py

46 lines
1.6 KiB
Python
Raw Normal View History

2017-04-21 13:07:24 +00:00
# -*- coding: utf-8 -*-
from django.db import models
from django.db.models.signals import pre_save
from django.dispatch import receiver
from django.core.mail import send_mail
from wagtail.contrib.settings.models import BaseSetting, register_setting
2017-07-03 11:35:36 +00:00
# A simple feedback module built into the site admin
2021-06-07 15:43:12 +00:00
@register_setting(icon='', classnames='icon icon-help')
2017-04-21 13:07:24 +00:00
class DataletsSettings(BaseSetting):
2017-10-13 21:22:34 +00:00
feedback_question = models.TextField(verbose_name='Name',
help_text='Who should we reply to for questions?', blank=True)
feedback_status = models.IntegerField(verbose_name='Rating',
2017-04-21 13:07:24 +00:00
choices=(
2017-10-13 21:22:34 +00:00
(1, u''),
(2, u''*2),
(3, u''*3),
(4, u''*4),
(5, u''*5),
2017-04-21 13:17:53 +00:00
), blank=True, null=True,
help_text='How are you enjoying Wagtail?'
2017-04-21 13:07:24 +00:00
)
2017-10-13 21:22:34 +00:00
feedback_comment = models.TextField(verbose_name='Comments..',
help_text='Any questions or general feedback', blank=True)
2017-04-21 13:07:24 +00:00
class Meta:
2017-10-13 21:22:34 +00:00
verbose_name = 'Datalets'
2017-04-21 13:07:24 +00:00
@receiver(pre_save, sender=DataletsSettings)
2017-04-21 13:17:53 +00:00
def handle_save_settings(sender, instance, *args, **kwargs):
if instance.feedback_status is not None:
send_mail("Response from Wagtail",
"%s\n--\n%s\n--\n%s" % (
str(instance.feedback_status),
instance.feedback_question,
instance.feedback_comment,
2022-01-27 16:55:12 +00:00
), "info@ungleich.ch",
[ "info@ungleich.ch" ]
2017-04-21 13:17:53 +00:00
)
instance.feedback_status = None
instance.feedback_question = ""
instance.feedback_comment = ""
2017-10-16 08:59:59 +00:00
instance.save()