Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Use templates to render the content of generated emails

Roland Geider1e69107b1c1c
diff --git a/wger/exercises/models.py b/wger/exercises/models.py
index 06b59c7fd..05e164db7 100644
--- a/wger/exercises/models.py
+++ b/wger/exercises/models.py
@@ -18,10 +18,10 @@
import logging
from django.db import models
+from django.template.loader import render_to_string
from django.template.defaultfilters import slugify # django.utils.text.slugify in django 1.5!
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
-from django.utils.translation import ugettext
from django.utils import translation
from django.core.urlresolvers import reverse
from django.core import mail
@@ -317,13 +317,11 @@ class Exercise(AbstractLicenseModel, models.Model):
translation.activate(user.userprofile.notification_language.short_name)
url = request.build_absolute_uri(self.get_absolute_url())
subject = _('Exercise was successfully added to the general database')
- message = (ugettext("Your exercise '{0}' was successfully added to the general"
- "database.\n\n"
- "It is now available on the exercise and muscle overview and can be\n"
- "added to workouts. You can access it on this address:\n"
- "{1}\n\n").format(self.name, url) +
- ugettext("Thank you for contributing and making this site better!\n"
- " the wger.de team"))
+ context = {
+ 'exercise': self.name,
+ 'url': url
+ }
+ message = render_to_string('exercise/email_new.html', context)
mail.send_mail(subject,
message,
EMAIL_FROM,
diff --git a/wger/exercises/templates/exercise/email_new.html b/wger/exercises/templates/exercise/email_new.html
new file mode 100644
index 000000000..b25c88466
--- /dev/null
+++ b/wger/exercises/templates/exercise/email_new.html
@@ -0,0 +1,9 @@
+{% load i18n %}{% blocktrans %}Your exercise '{{exercise}}' was successfully added to the general
+database.{% endblocktrans %}
+
+{% blocktrans %}It is now available on the exercise and muscle overview and can be
+added to workouts. You can access it on this address:{% endblocktrans %}
+{{url}}
+
+{% blocktrans %}Thank you for contributing and making this site better!{% endblocktrans %}
+ — {% blocktrans %}the wger.de team{% endblocktrans %}
\ No newline at end of file
diff --git a/wger/nutrition/models.py b/wger/nutrition/models.py
index 52f7e3f3a..e4db9340f 100644
--- a/wger/nutrition/models.py
+++ b/wger/nutrition/models.py
@@ -19,6 +19,7 @@ from decimal import Decimal
from django.db import models
+from django.template.loader import render_to_string
from django.template.defaultfilters import slugify # django.utils.text.slugify in django 1.5!
from django.core.validators import MaxValueValidator
from django.core.validators import MinValueValidator
@@ -28,7 +29,6 @@ from django.core import mail
from django.core.cache import cache
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
-from django.utils.translation import ugettext
from django.utils import translation
from wger.core.models import Language
@@ -401,13 +401,11 @@ class Ingredient(AbstractLicenseModel, models.Model):
translation.activate(self.user.userprofile.notification_language.short_name)
url = request.build_absolute_uri(self.get_absolute_url())
subject = _('Ingredient was successfully added to the general database')
- message = (ugettext("Your ingredient '{0}' was successfully added to the general "
- "database.\n\n"
- "It is now available on the ingredient overview and can be\n"
- "added to nutrition plans. You can access it on this address:\n"
- "{1}\n\n").format(self.name, url) +
- ugettext("Thank you for contributing and making this site better!\n"
- " the wger.de team"))
+ context = {
+ 'ingredient': self.name,
+ 'url': url
+ }
+ message = render_to_string('ingredient/email_new.html', context)
mail.send_mail(subject,
message,
EMAIL_FROM,
diff --git a/wger/nutrition/templates/ingredient/email_new.html b/wger/nutrition/templates/ingredient/email_new.html
new file mode 100644
index 000000000..7e4856bf8
--- /dev/null
+++ b/wger/nutrition/templates/ingredient/email_new.html
@@ -0,0 +1,9 @@
+{% load i18n %}{% blocktrans %}Your ingredient '{{ingredient}}' was successfully added to the general
+database.{% endblocktrans %}
+
+{% blocktrans %}It is now available on the ingredient overview and can be
+added to nutrition plans. You can access it on this address:{% endblocktrans %}
+{{url}}
+
+{% blocktrans %}Thank you for contributing and making this site better!{% endblocktrans %}
+ — {% blocktrans %}the wger.de team{% endblocktrans %}
\ No newline at end of file