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

44 lines
1.4 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
2017-04-21 13:07:24 +00:00
@register_setting
class DataletsSettings(BaseSetting):
2017-04-21 13:17:53 +00:00
feedback_question = models.TextField(
help_text='Send us a question', blank=True)
2017-04-21 13:07:24 +00:00
feedback_status = models.IntegerField(
choices=(
2017-04-21 13:17:53 +00:00
(1, ':-('),
(2, ':-|'),
(3, ':-)'),
(4, ':-D'),
), blank=True, null=True,
help_text='How are you enjoying Wagtail?'
2017-04-21 13:07:24 +00:00
)
2017-04-21 13:17:53 +00:00
feedback_comment = models.TextField(
help_text='Any general feedback', blank=True)
2017-04-21 13:07:24 +00:00
class Meta:
2017-07-03 11:35:36 +00:00
verbose_name = 'Get support'
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,
), "wagtail@datalets.ch",
[ "support@datalets.ch" ]
)
instance.feedback_status = None
instance.feedback_question = ""
instance.feedback_comment = ""