Browse Source

Email notifications

Denis Merigoux 9 years ago
parent
commit
341747532d
3 changed files with 20 additions and 1 deletions
  1. 1 0
      counter/models.py
  2. 10 1
      counter/views.py
  3. 9 0
      seum/settings.py

+ 1 - 0
counter/models.py

@@ -5,6 +5,7 @@ from babel.dates import format_timedelta
5 5
 # Create your models here.
6 6
 class Counter(models.Model):
7 7
     name = models.CharField("Nom",max_length=60)
8
+    email = models.EmailField("Email",max_length=264,default="null@localhost")
8 9
     trigramme = models.CharField("Trigramme", max_length=3)
9 10
 
10 11
     def __str__(self):

+ 10 - 1
counter/views.py

@@ -5,6 +5,7 @@ from datetime import datetime,timedelta
5 5
 from django import forms
6 6
 from django.http import HttpResponseRedirect
7 7
 from django.core import serializers
8
+from django.core.mail import send_mail
8 9
 from graphos.renderers import gchart
9 10
 from graphos.sources.simple import SimpleDataSource
10 11
 from graphos.sources.model import ModelDataSource
@@ -122,7 +123,15 @@ def resetCounter(request):
122 123
         reset.reason = data['reason'][0]
123 124
         reset.timestamp = datetime.now()
124 125
         reset.save()
125
-        # check whether it's valid
126
+        emails = [u[0] for u in Counter.objects.all().values_list('email') if u[0] != 'null@localhost']
127
+        #Now send emails to everyone
128
+        send_mail( counter.name, data['reason'][0]+'''
129
+
130
+--
131
+SeumBook™
132
+Pour ne plus recevoir ces messages, envoie un mail à denis.merigoux@gmail.com''',
133
+        'SeumMan <seum@merigoux.ovh>', emails)
134
+
126 135
     return HttpResponseRedirect(data['redirect'][0])
127 136
 
128 137
 def counter(request, id_counter):

+ 9 - 0
seum/settings.py

@@ -123,3 +123,12 @@ USE_TZ = True
123 123
 # https://docs.djangoproject.com/en/1.9/howto/static-files/
124 124
 
125 125
 STATIC_URL = '/static/'
126
+
127
+#Emailing
128
+EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
129
+EMAIL_HOST = 'localhost'
130
+EMAIL_PORT = 25
131
+EMAIL_HOST_USER = ''
132
+EMAIL_HOST_PASSWORD = ''
133
+EMAIL_USE_TLS = False
134
+DEFAULT_FROM_EMAIL = 'SeumMan <seum@merigoux.ovh>'