kelvan avatar kelvan committed 05afcb9

moved newexpert notification mail to template

Comments (0)

Files changed (2)

freieit/templates/newexpert.txt

+Name: {{ expert.name }}
+
+Email: {{ expert.user.email }}
+
+Services:
+{{ expert.services }}
+
+Description:
+{{ expert.description }}
+
+View and accept (set available to True)
+http://test.freie.it/admin/freieit/expertprofile/{{ expert.id }}
+
+Yours sincerely,
+freie.it Notification Service

freieit/views/newexpert.py

 from django.http import HttpResponseRedirect
 from django.core.mail import EmailMessage
 from django.contrib.auth.models import User
+from django.template.loader import get_template
+from django.template import Context
 
 from freieit.forms.expert import ExpertProfileForm
 from freieit import settings
             expert.available = False
             expert.user = u
             expert.save()
-            
-            email_msg = """
-            Name:
-            %(name)s
 
-            Services:
-            %(services)s
-
-            View and accept (set available to True)
-            http://test.freie.it/admin/freieit/expertprofile/%(id)s
-            """ % expert.__dict__
+            tpl = get_template('newexpert.txt')
+            email_msg = tpl.render(Context({'expert': expert}))
 
             subject = "[New expert] %s" % expert.name
-            email_from = email
+            email_from = settings.DEFAULT_FROM_EMAIL
             email_to = settings.DEFAULT_FROM_EMAIL
 
             email = EmailMessage(subject, email_msg, email_from, [email_to])
             #if 'image' in request.FILES:
             #    img = request.FILES['image']
             #    email.attach(img.name, img.read(), img.content_type)
-                
+            
             email.send(fail_silently=False)
 
             return render(request, 'newexpert.html', {'expert': expert})
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.