notification for new organizations
authorJan Szejko <janek37@gmail.com>
Thu, 19 Jan 2017 12:35:07 +0000 (13:35 +0100)
committerJan Szejko <janek37@gmail.com>
Thu, 19 Jan 2017 12:35:07 +0000 (13:35 +0100)
apps/organizations/forms.py

index 6398448..298da48 100644 (file)
@@ -4,6 +4,10 @@
 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
 #
 from django import forms
+from constance import config
+from django.contrib.sites.models import Site
+from django.core.mail import send_mail
+
 from .models import Organization, UserCard, countries
 
 
@@ -14,6 +18,18 @@ class OrganizationForm(forms.ModelForm):
         model = Organization
         exclude = ['_html']
 
+    def save(self, commit=True):
+        organization = super(OrganizationForm, self).save(commit=commit)
+        site = Site.objects.get_current()
+        send_mail(
+            'New organization in MIL/PEER',
+            '''New organization in MIL/PEER: %s. View their profile: https://%s%s.
+
+--
+MIL/PEER team.''' % (organization.name, site.domain, organization.get_absolute_url()),
+            'milpeer@mdrn.pl', [config.NOTIFY_EMAIL])
+        return organization
+
 
 class UserCardForm(forms.ModelForm):
     cts = countries