├── templated_emails ├── __init__.py ├── models.py ├── templates │ └── templated_emails │ │ ├── test_templates │ │ ├── base.html │ │ └── top.html │ │ ├── index.html │ │ ├── directory.html │ │ └── view.html ├── urls.py ├── templatetags │ └── templated_email_tags.py ├── backends │ └── templated_email.py ├── views.py ├── tests.py ├── parse_util.py └── utils.py ├── .gitignore ├── MANIFEST.in ├── docs ├── index.rst ├── Makefile ├── make.bat └── conf.py ├── LICENSE.txt ├── setup.py └── README.rst /templated_emails/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /templated_emails/models.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /templated_emails/templates/templated_emails/test_templates/base.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /templated_emails/templates/templated_emails/test_templates/top.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | dist 3 | templated_emails.egg-info 4 | *.pyc 5 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.rst 2 | include templated_emails/templates/templated_emails/*.html -------------------------------------------------------------------------------- /templated_emails/urls.py: -------------------------------------------------------------------------------- 1 | from django.conf.urls.defaults import * 2 | from .views import * 3 | 4 | urlpatterns = patterns('', 5 | url(r'^$', index, name="templated_emails_index"), 6 | url(r'^view(?P[\w.+-_/]+)$', view, name="templated_email_view"), 7 | ) 8 | -------------------------------------------------------------------------------- /templated_emails/templates/templated_emails/index.html: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | <!-- Insert your title here --> 7 | 8 | 9 | {% include "templated_emails/directory.html" with path="" %} 10 | 11 | 12 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. templated-emails documentation master file, created by 2 | sphinx-quickstart on Sun Dec 18 21:23:53 2011. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to templated-emails's documentation! 7 | ============================================ 8 | 9 | Contents: 10 | 11 | .. toctree:: 12 | :maxdepth: 2 13 | 14 | Indices and tables 15 | ================== 16 | 17 | * :ref:`genindex` 18 | * :ref:`modindex` 19 | * :ref:`search` 20 | 21 | -------------------------------------------------------------------------------- /templated_emails/templates/templated_emails/directory.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /templated_emails/templatetags/templated_email_tags.py: -------------------------------------------------------------------------------- 1 | from django.template.base import Library 2 | import textwrap 3 | 4 | register = Library() 5 | 6 | 7 | @register.filter(is_safe=True) 8 | def dedent(text): 9 | """ 10 | Removes indentation of text. Useful in text emails that otherwise can't be 11 | indented. 12 | 13 | Example usage:: 14 | 15 | {% filter dedent %} 16 | My text 17 | {% if something %} 18 | another text 19 | {% endif %} 20 | {% endfilter %} 21 | 22 | This example would return this HTML:: 23 | 24 | My text 25 | 26 | another text 27 | """ 28 | return textwrap.dedent(text) 29 | -------------------------------------------------------------------------------- /templated_emails/backends/templated_email.py: -------------------------------------------------------------------------------- 1 | from notification import backends 2 | from templated_emails.utils import send_templated_email 3 | 4 | 5 | class TemplatedEmailBackend(backends.BaseBackend): 6 | """ 7 | At attempt to wire django-notifications to 8 | https://github.com/philippWassibauer/templated-emails 9 | not to 10 | https://github.com/bradwhittington/django-templated-email 11 | though that might be a good idea 12 | """ 13 | spam_sensitivity = 0 14 | 15 | def deliver(self, recipient, sender, notice_type, extra_context): 16 | if recipient == sender: 17 | return False 18 | 19 | context = self.default_context().update({"sender": sender}) 20 | context.update(extra_context) 21 | send_templated_email([recipient], "emails/%s" % notice_type, context) 22 | return True 23 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Philipp Wassibauer 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from setuptools import setup 3 | import os 4 | 5 | long_description = open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'README.rst')).read() 6 | 7 | setup( 8 | name = 'templated-emails', 9 | version = "0.6.7", 10 | url = 'https://github.com/philippWassibauer/templated-emails', 11 | author = "Philipp Wassibauer", 12 | author_email = "phil@gidsy.com", 13 | license = 'MIT License', 14 | packages = ['templated_emails'], 15 | package_data={ 16 | 'templated_emails': [ 17 | 'templates/templated_emails/*.html', 18 | ] 19 | }, 20 | description = 'Like django-notifications, but just for sending plain emails. Written because it is annoying to fork other apps just to make an email into an HTML email', 21 | long_description=long_description, 22 | classifiers = ['Development Status :: 4 - Beta', 23 | 'Environment :: Web Environment', 24 | 'Framework :: Django', 25 | 'Intended Audience :: Developers', 26 | 'License :: OSI Approved :: MIT License', 27 | 'Topic :: Internet :: WWW/HTTP :: Dynamic Content'], 28 | install_requires=[ 29 | 'pynliner', 30 | 'cssutils', 31 | ], 32 | ) 33 | -------------------------------------------------------------------------------- /templated_emails/templates/templated_emails/view.html: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 53 | template 54 | 55 | 56 |
57 | back 58 | 59 |
Title:
60 |
61 |

{{ rendered_subject }}

62 |
63 | 64 |
HTML:
65 |
66 | {{ rendered_html|safe }} 67 |
68 | 69 |
Text:
70 |
71 |
72 |                 {{ rendered_text }}
73 |             
74 |
75 |
76 | 77 | 78 | -------------------------------------------------------------------------------- /templated_emails/views.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | from django.contrib.auth.models import User 4 | from django.http import HttpResponseRedirect, Http404, HttpResponse 5 | from django.shortcuts import render_to_response, get_object_or_404 6 | from django.template import RequestContext 7 | from django.conf import settings 8 | from django.template.loader import get_template 9 | from django.template.base import Template 10 | 11 | from .utils import get_email_directories 12 | from .parse_util import recursive_block_replace 13 | 14 | logger = logging.getLogger('templated_emails') 15 | 16 | def index(request, template_name="templated_emails/index.html"): 17 | if not request.user.is_superuser: 18 | raise Http404 19 | else: 20 | directory_tree = get_email_directories(settings.EMAIL_TEMPLATES_DIRECTORY) 21 | return render_to_response(template_name, { 22 | "directory_tree": directory_tree, 23 | }, context_instance=RequestContext(request)) 24 | 25 | 26 | def view(request, path, template_name="templated_emails/view.html"): 27 | if not request.user.is_superuser: 28 | raise Http404 29 | else: 30 | # get extends node 31 | # get all block nodes 32 | # do this recursive until no more extends 33 | # then place html in blocks 34 | rendered_subject = "" 35 | rendered_html = "" 36 | rendered_text = "" 37 | 38 | try: 39 | template = get_template("emails%s/email.html"%path) 40 | rendered_html = recursive_block_replace(template, {}) 41 | except: 42 | logger.exception("Error rendering templated email email.html") 43 | 44 | try: 45 | template = get_template("emails%s/email.txt"%path) 46 | rendered_text = recursive_block_replace(template, {}) 47 | except: 48 | logger.exception("Error rendering templated email email.txt") 49 | 50 | try: 51 | template = get_template("emails%s/short.txt"%path) 52 | rendered_subject = recursive_block_replace(template, {}) 53 | except: 54 | logger.exception("Error rendering templated email short.txt") 55 | 56 | return render_to_response(template_name, { 57 | "rendered_subject": rendered_subject, 58 | "rendered_html": rendered_html, 59 | "rendered_text": rendered_text, 60 | }, context_instance=RequestContext(request)) 61 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ================ 2 | templated-emails 3 | ================ 4 | 5 | This app abstracts the sending of emails in a way so that it is possible to 6 | switch from plain text emails to html emails, even if you are using third party apps. 7 | It does this by using a very similar mechanism as django-notifications. 8 | 9 | Each email gets a folder. In this folder one can put: 10 | 11 | * short.txt (for the subject) 12 | * email.txt (for the plain text email) 13 | * email.html (optional, if an HTML email should also be sent) 14 | 15 | A good practice is to put all emails in an emails/ folder within your templates folder, 16 | so it is easy to see what emails are being sent by your system. 17 | 18 | Recipients can either be an array of emails (as strings) or users. 19 | If you pass users it will also try to find the users stored language 20 | (accounts.Account.language in pinax) and send it using it. 21 | 22 | Sending an emails works like this:: 23 | 24 | from templated_emails.utils import send_templated_email 25 | send_templated_email(["philipp@gidsy.com"], "emails/invite_friends", {"my_variable":"blafoo"}) 26 | 27 | or 28 | 29 | :: 30 | 31 | user = User.objects.get(pk=1) 32 | # this will try to switch to the correct language of the user 33 | send_templated_email([user], "emails/invite_friends", {"my_variable":"blafoo"}) 34 | 35 | The system will add current_site (the Site object of the Django Project) 36 | and STATIC_URL (for linking in static content) to the context of your templates. 37 | 38 | 39 | Language 40 | ======== 41 | Similar to django-notification the system will try to look for the language the 42 | user has set in his Account (but can be configured to other Models using settings.NOTIFICATION_LANGUAGE_MODULE) 43 | to server the right language to each user. 44 | 45 | 46 | Inline CSS Rules 47 | ================ 48 | 49 | Inline CSS Rules are annoying and tedious, but a neccessity if you want to support all email clients. 50 | Since 0.3 pynliner is included that will take the CSS from the HEAD and put it into each element that matches the rule 51 | 52 | There is a toggle you can set in settings.py to turn this feature on or off: 53 | TEMPLATEDEMAILS_USE_PYNLINER = False is the default value. 54 | 55 | 56 | Celery 57 | ====== 58 | 59 | Pynliner can be quite slow when inlining CSS. You can move all the execution 60 | to Celery with this setting (default is False):: 61 | 62 | TEMPLATEDEMAILS_USE_CELERY = True 63 | 64 | Please note that the given context is passed to Celery unchanged. 65 | 66 | 67 | Install 68 | ======= 69 | 70 | :: 71 | 72 | pip install -e http://github.com/philippWassibauer/templated-emails.git#egg=templated-emails 73 | 74 | or 75 | 76 | :: 77 | 78 | pip install templated-emails 79 | 80 | 81 | Dependencies 82 | ============ 83 | * pynliner 84 | * cssutils 85 | 86 | Follow Me 87 | ========= 88 | 89 | * http://github.com/philippWassibauer 90 | * http://twitter.com/__philw__ 91 | * http://philippw.tumblr.com 92 | * https://bitbucket.org/philippwassibauer 93 | -------------------------------------------------------------------------------- /templated_emails/tests.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from django.utils import unittest 3 | from django.test import TestCase 4 | from .parse_util import parse_string_blocks, replace_blocks, replace_string_blocks 5 | 6 | 7 | test_extraction_string = """{% block test %}tr 8 | st 9 | 10 | sdf{% endblock %}""" 11 | 12 | test_extraction_string2 = """{% block test123 %}tr s123t sdf{% endblock %}""" 13 | 14 | test_extraction_string3 = """{% block test123 %} 15 | tr s123t sdf 16 | {% endblock %} 17 | 18 | {% block test %}test{% endblock %} 19 | """ 20 | 21 | test_extraction_string4 = """{% extends "emails/email.html" %}\n{% load gidsy_tags %}\n{% load profile_tags %}\n{% load account_tags %}\n{% load currency_tags %}\n{% block title %}\n {% trans "All the best," %}\n{% endblock %}{% block message_title %}{% trans "Sorry! Not enough people booked" %} "{{ activity }}."{% endblock %}\n{% block email_notification %}{% trans "Your activity will not be taking place" %}{% endblock %}\n{% block email_title %}{% random_greeting %} {{ user.first_name }},{% endblock %}\n{% block email_subtitle %}\n

\n {% blocktrans with slot=booking.slot min_participants=slot.get_min_participants start_date=slot.start_time|date:"l, F j" start_time=slot.start_time|date:"P" %}\n We\'re sorry! Not enough people booked "{{ activity }}" on {{ start_date }} at {{ start_time }} for it to happen.\n {% endblocktrans %}\n

\n{% endblock %}\n{% block email_message %}\n

\n {% blocktrans with confirmed_bookings=slot.booked_spots %}\n To avoid disappointment in future, make sure to check before booking an activity how far it is from getting its minimum number of participants. \n {% endblocktrans %}\n

\n {% if other_activities %}\n

\n You may also be interested in these other [link: activities] that already have enough people attending: (list 3 activities here)\n

\n {% endif %}\n{% endblock %}\n\n{% block signature %}\n {% trans "All the best," %}\n{% endblock %}""" 22 | test_replace_string = """{% block test123 %}{% endblock %}""" 23 | 24 | 25 | class BlockExtraction(TestCase): 26 | def test_extraction(self): 27 | self.assertEquals("""tr 28 | st 29 | 30 | sdf""", parse_string_blocks(test_extraction_string, {})["test"]) 31 | 32 | self.assertEquals("tr s123t sdf", parse_string_blocks(test_extraction_string2, {})["test123"]) 33 | data = parse_string_blocks(test_extraction_string3, {}) 34 | self.assertEquals(""" 35 | tr s123t sdf 36 | """,data["test123"]) 37 | self.assertEquals("""test""",data["test"]) 38 | 39 | def test_full_extraction(self): 40 | data = parse_string_blocks(test_extraction_string4, {}) 41 | print data 42 | self.assertTrue(data.get("message_title", False)) 43 | self.assertTrue(data.get("email_notification", False)) 44 | self.assertTrue(data.get("email_title", False)) 45 | self.assertTrue(data.get("email_subtitle", False)) 46 | self.assertTrue(data.get("signature", False)) 47 | self.assertTrue(data.get("title", False)) 48 | 49 | def test_replace_blocks(self): 50 | self.assertEqual("test", replace_string_blocks(test_replace_string, {"test123": "test"})) -------------------------------------------------------------------------------- /templated_emails/parse_util.py: -------------------------------------------------------------------------------- 1 | from django.template.loader_tags import ExtendsNode 2 | from django.conf import settings 3 | import re 4 | 5 | def recursive_block_replace(template, data=None, replace_static_url=True, replace_trans=True, 6 | replace_with=True, replace_if=True): 7 | #check the extends 8 | # first try to replace with current data 9 | if isinstance(template.nodelist[0], ExtendsNode): 10 | # load more data using the current blocks 11 | data = parse_blocks(template, data) 12 | data = fill_blocks(template, data) 13 | return recursive_block_replace(template.nodelist[0].get_parent(""), data) 14 | else: 15 | final_string = replace_blocks(template, data) 16 | if replace_static_url: 17 | final_string = final_string.replace("{{ STATIC_URL }}", settings.STATIC_URL) 18 | if replace_trans: 19 | p = re.compile('(\{% blocktrans .* %\})', re.IGNORECASE) 20 | final_string = p.sub('', final_string) 21 | 22 | p = re.compile('(\{% blocktrans %\})', re.IGNORECASE) 23 | final_string = p.sub('', final_string) 24 | 25 | p = re.compile('(\{% endblocktrans %\})', re.IGNORECASE) 26 | final_string = p.sub('', final_string) 27 | 28 | final_string = re.sub(r"\{% trans (.+) %\}", lambda x: x.group(1)[1:-1], final_string) 29 | if replace_with: 30 | p = re.compile('(\{% with .+ %\})', re.MULTILINE|re.IGNORECASE) 31 | final_string = p.sub('', final_string) 32 | 33 | p = re.compile('(\{% endwith %\})', re.MULTILINE|re.IGNORECASE) 34 | final_string = p.sub('', final_string) 35 | 36 | if replace_if: 37 | p = re.compile('(\{% if .+ %\})', re.MULTILINE|re.IGNORECASE) 38 | final_string = p.sub(lambda x: "
%s
"%x.group(1), final_string) 39 | 40 | p = re.compile('(\{% endif %\})', re.MULTILINE|re.IGNORECASE) 41 | final_string = p.sub(lambda x: "
%s
"%x.group(1), final_string) 42 | 43 | return final_string 44 | 45 | 46 | def replace_blocks(template, data): 47 | template_string = read_file(template.nodelist[0].source[0].name) 48 | return replace_string_blocks(template_string, data) 49 | 50 | 51 | def replace_string_blocks(string, data): 52 | for key in data: 53 | regex_string = '\{% block '+key+' %\}([\s\S\n\r\w]*?)\{% endblock %\}' 54 | p = re.compile(regex_string, re.MULTILINE|re.IGNORECASE) 55 | string = p.sub(data[key], string) 56 | 57 | # replace the last blocks 58 | p2 = re.compile('(\{% block [a-zA-Z0-9_]+ %\})', re.MULTILINE|re.IGNORECASE) 59 | string = p2.sub('', string) 60 | 61 | p2 = re.compile('(\{% endblock %\})', re.MULTILINE|re.IGNORECASE) 62 | string = p2.sub('', string) 63 | 64 | return string 65 | 66 | 67 | def fill_blocks(template, data): 68 | return data 69 | 70 | 71 | def parse_blocks(template, data): 72 | data = parse_string_blocks(read_file(template.nodelist[0].source[0].name), 73 | data) 74 | return data 75 | 76 | 77 | def parse_string_blocks(string, data): 78 | # find all blocks 79 | regex = re.compile("\{% block ([a-zA-Z0-9_]+) %\}([\s\S\n\r\w]*?)\{% endblock %\}", 80 | re.DOTALL|re.MULTILINE|re.IGNORECASE) 81 | m = regex.findall(string) 82 | for item in m: 83 | print item[0] 84 | data[item[0]] = item[1] 85 | return data 86 | 87 | 88 | def read_file(path): 89 | file = open(path, "r") 90 | return file.read() 91 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # Internal variables. 11 | PAPEROPT_a4 = -D latex_paper_size=a4 12 | PAPEROPT_letter = -D latex_paper_size=letter 13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 14 | 15 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest 16 | 17 | help: 18 | @echo "Please use \`make ' where is one of" 19 | @echo " html to make standalone HTML files" 20 | @echo " dirhtml to make HTML files named index.html in directories" 21 | @echo " singlehtml to make a single large HTML file" 22 | @echo " pickle to make pickle files" 23 | @echo " json to make JSON files" 24 | @echo " htmlhelp to make HTML files and a HTML help project" 25 | @echo " qthelp to make HTML files and a qthelp project" 26 | @echo " devhelp to make HTML files and a Devhelp project" 27 | @echo " epub to make an epub" 28 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 29 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 30 | @echo " text to make text files" 31 | @echo " man to make manual pages" 32 | @echo " changes to make an overview of all changed/added/deprecated items" 33 | @echo " linkcheck to check all external links for integrity" 34 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 35 | 36 | clean: 37 | -rm -rf $(BUILDDIR)/* 38 | 39 | html: 40 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 41 | @echo 42 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 43 | 44 | dirhtml: 45 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 46 | @echo 47 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 48 | 49 | singlehtml: 50 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 51 | @echo 52 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 53 | 54 | pickle: 55 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 56 | @echo 57 | @echo "Build finished; now you can process the pickle files." 58 | 59 | json: 60 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 61 | @echo 62 | @echo "Build finished; now you can process the JSON files." 63 | 64 | htmlhelp: 65 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 66 | @echo 67 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 68 | ".hhp project file in $(BUILDDIR)/htmlhelp." 69 | 70 | qthelp: 71 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 72 | @echo 73 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 74 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 75 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/templated-emails.qhcp" 76 | @echo "To view the help file:" 77 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/templated-emails.qhc" 78 | 79 | devhelp: 80 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 81 | @echo 82 | @echo "Build finished." 83 | @echo "To view the help file:" 84 | @echo "# mkdir -p $$HOME/.local/share/devhelp/templated-emails" 85 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/templated-emails" 86 | @echo "# devhelp" 87 | 88 | epub: 89 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 90 | @echo 91 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 92 | 93 | latex: 94 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 95 | @echo 96 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 97 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 98 | "(use \`make latexpdf' here to do that automatically)." 99 | 100 | latexpdf: 101 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 102 | @echo "Running LaTeX files through pdflatex..." 103 | make -C $(BUILDDIR)/latex all-pdf 104 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 105 | 106 | text: 107 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 108 | @echo 109 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 110 | 111 | man: 112 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 113 | @echo 114 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 115 | 116 | changes: 117 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 118 | @echo 119 | @echo "The overview file is in $(BUILDDIR)/changes." 120 | 121 | linkcheck: 122 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 123 | @echo 124 | @echo "Link check complete; look for any errors in the above output " \ 125 | "or in $(BUILDDIR)/linkcheck/output.txt." 126 | 127 | doctest: 128 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 129 | @echo "Testing of doctests in the sources finished, look at the " \ 130 | "results in $(BUILDDIR)/doctest/output.txt." 131 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | if NOT "%PAPER%" == "" ( 11 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 12 | ) 13 | 14 | if "%1" == "" goto help 15 | 16 | if "%1" == "help" ( 17 | :help 18 | echo.Please use `make ^` where ^ is one of 19 | echo. html to make standalone HTML files 20 | echo. dirhtml to make HTML files named index.html in directories 21 | echo. singlehtml to make a single large HTML file 22 | echo. pickle to make pickle files 23 | echo. json to make JSON files 24 | echo. htmlhelp to make HTML files and a HTML help project 25 | echo. qthelp to make HTML files and a qthelp project 26 | echo. devhelp to make HTML files and a Devhelp project 27 | echo. epub to make an epub 28 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 29 | echo. text to make text files 30 | echo. man to make manual pages 31 | echo. changes to make an overview over all changed/added/deprecated items 32 | echo. linkcheck to check all external links for integrity 33 | echo. doctest to run all doctests embedded in the documentation if enabled 34 | goto end 35 | ) 36 | 37 | if "%1" == "clean" ( 38 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 39 | del /q /s %BUILDDIR%\* 40 | goto end 41 | ) 42 | 43 | if "%1" == "html" ( 44 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 45 | if errorlevel 1 exit /b 1 46 | echo. 47 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 48 | goto end 49 | ) 50 | 51 | if "%1" == "dirhtml" ( 52 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 53 | if errorlevel 1 exit /b 1 54 | echo. 55 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 56 | goto end 57 | ) 58 | 59 | if "%1" == "singlehtml" ( 60 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 61 | if errorlevel 1 exit /b 1 62 | echo. 63 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 64 | goto end 65 | ) 66 | 67 | if "%1" == "pickle" ( 68 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 69 | if errorlevel 1 exit /b 1 70 | echo. 71 | echo.Build finished; now you can process the pickle files. 72 | goto end 73 | ) 74 | 75 | if "%1" == "json" ( 76 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 77 | if errorlevel 1 exit /b 1 78 | echo. 79 | echo.Build finished; now you can process the JSON files. 80 | goto end 81 | ) 82 | 83 | if "%1" == "htmlhelp" ( 84 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 85 | if errorlevel 1 exit /b 1 86 | echo. 87 | echo.Build finished; now you can run HTML Help Workshop with the ^ 88 | .hhp project file in %BUILDDIR%/htmlhelp. 89 | goto end 90 | ) 91 | 92 | if "%1" == "qthelp" ( 93 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 94 | if errorlevel 1 exit /b 1 95 | echo. 96 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 97 | .qhcp project file in %BUILDDIR%/qthelp, like this: 98 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\templated-emails.qhcp 99 | echo.To view the help file: 100 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\templated-emails.ghc 101 | goto end 102 | ) 103 | 104 | if "%1" == "devhelp" ( 105 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 106 | if errorlevel 1 exit /b 1 107 | echo. 108 | echo.Build finished. 109 | goto end 110 | ) 111 | 112 | if "%1" == "epub" ( 113 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 114 | if errorlevel 1 exit /b 1 115 | echo. 116 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 117 | goto end 118 | ) 119 | 120 | if "%1" == "latex" ( 121 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 122 | if errorlevel 1 exit /b 1 123 | echo. 124 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 125 | goto end 126 | ) 127 | 128 | if "%1" == "text" ( 129 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 130 | if errorlevel 1 exit /b 1 131 | echo. 132 | echo.Build finished. The text files are in %BUILDDIR%/text. 133 | goto end 134 | ) 135 | 136 | if "%1" == "man" ( 137 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 138 | if errorlevel 1 exit /b 1 139 | echo. 140 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 141 | goto end 142 | ) 143 | 144 | if "%1" == "changes" ( 145 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 146 | if errorlevel 1 exit /b 1 147 | echo. 148 | echo.The overview file is in %BUILDDIR%/changes. 149 | goto end 150 | ) 151 | 152 | if "%1" == "linkcheck" ( 153 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 154 | if errorlevel 1 exit /b 1 155 | echo. 156 | echo.Link check complete; look for any errors in the above output ^ 157 | or in %BUILDDIR%/linkcheck/output.txt. 158 | goto end 159 | ) 160 | 161 | if "%1" == "doctest" ( 162 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 163 | if errorlevel 1 exit /b 1 164 | echo. 165 | echo.Testing of doctests in the sources finished, look at the ^ 166 | results in %BUILDDIR%/doctest/output.txt. 167 | goto end 168 | ) 169 | 170 | :end 171 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # templated-emails documentation build configuration file, created by 4 | # sphinx-quickstart on Sun Dec 18 21:23:53 2011. 5 | # 6 | # This file is execfile()d with the current directory set to its containing dir. 7 | # 8 | # Note that not all possible configuration values are present in this 9 | # autogenerated file. 10 | # 11 | # All configuration values have a default; values that are commented out 12 | # serve to show the default. 13 | 14 | import sys, os 15 | 16 | # If extensions (or modules to document with autodoc) are in another directory, 17 | # add these directories to sys.path here. If the directory is relative to the 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. 19 | #sys.path.insert(0, os.path.abspath('.')) 20 | 21 | # -- General configuration ----------------------------------------------------- 22 | 23 | # If your documentation needs a minimal Sphinx version, state it here. 24 | #needs_sphinx = '1.0' 25 | 26 | # Add any Sphinx extension module names here, as strings. They can be extensions 27 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. 28 | extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx'] 29 | 30 | # Add any paths that contain templates here, relative to this directory. 31 | templates_path = ['_templates'] 32 | 33 | # The suffix of source filenames. 34 | source_suffix = '.rst' 35 | 36 | # The encoding of source files. 37 | #source_encoding = 'utf-8-sig' 38 | 39 | # The master toctree document. 40 | master_doc = 'index' 41 | 42 | # General information about the project. 43 | project = u'templated-emails' 44 | copyright = u'2011, Philipp Wassibauer' 45 | 46 | # The version info for the project you're documenting, acts as replacement for 47 | # |version| and |release|, also used in various other places throughout the 48 | # built documents. 49 | # 50 | # The short X.Y version. 51 | version = '0.6.1' 52 | # The full version, including alpha/beta/rc tags. 53 | release = '0.6.1' 54 | 55 | # The language for content autogenerated by Sphinx. Refer to documentation 56 | # for a list of supported languages. 57 | #language = None 58 | 59 | # There are two options for replacing |today|: either, you set today to some 60 | # non-false value, then it is used: 61 | #today = '' 62 | # Else, today_fmt is used as the format for a strftime call. 63 | #today_fmt = '%B %d, %Y' 64 | 65 | # List of patterns, relative to source directory, that match files and 66 | # directories to ignore when looking for source files. 67 | exclude_patterns = ['_build'] 68 | 69 | # The reST default role (used for this markup: `text`) to use for all documents. 70 | #default_role = None 71 | 72 | # If true, '()' will be appended to :func: etc. cross-reference text. 73 | #add_function_parentheses = True 74 | 75 | # If true, the current module name will be prepended to all description 76 | # unit titles (such as .. function::). 77 | #add_module_names = True 78 | 79 | # If true, sectionauthor and moduleauthor directives will be shown in the 80 | # output. They are ignored by default. 81 | #show_authors = False 82 | 83 | # The name of the Pygments (syntax highlighting) style to use. 84 | pygments_style = 'sphinx' 85 | 86 | # A list of ignored prefixes for module index sorting. 87 | #modindex_common_prefix = [] 88 | 89 | 90 | # -- Options for HTML output --------------------------------------------------- 91 | 92 | # The theme to use for HTML and HTML Help pages. See the documentation for 93 | # a list of builtin themes. 94 | html_theme = 'default' 95 | 96 | # Theme options are theme-specific and customize the look and feel of a theme 97 | # further. For a list of options available for each theme, see the 98 | # documentation. 99 | #html_theme_options = {} 100 | 101 | # Add any paths that contain custom themes here, relative to this directory. 102 | #html_theme_path = [] 103 | 104 | # The name for this set of Sphinx documents. If None, it defaults to 105 | # " v documentation". 106 | #html_title = None 107 | 108 | # A shorter title for the navigation bar. Default is the same as html_title. 109 | #html_short_title = None 110 | 111 | # The name of an image file (relative to this directory) to place at the top 112 | # of the sidebar. 113 | #html_logo = None 114 | 115 | # The name of an image file (within the static path) to use as favicon of the 116 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 117 | # pixels large. 118 | #html_favicon = None 119 | 120 | # Add any paths that contain custom static files (such as style sheets) here, 121 | # relative to this directory. They are copied after the builtin static files, 122 | # so a file named "default.css" will overwrite the builtin "default.css". 123 | html_static_path = ['_static'] 124 | 125 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 126 | # using the given strftime format. 127 | #html_last_updated_fmt = '%b %d, %Y' 128 | 129 | # If true, SmartyPants will be used to convert quotes and dashes to 130 | # typographically correct entities. 131 | #html_use_smartypants = True 132 | 133 | # Custom sidebar templates, maps document names to template names. 134 | #html_sidebars = {} 135 | 136 | # Additional templates that should be rendered to pages, maps page names to 137 | # template names. 138 | #html_additional_pages = {} 139 | 140 | # If false, no module index is generated. 141 | #html_domain_indices = True 142 | 143 | # If false, no index is generated. 144 | #html_use_index = True 145 | 146 | # If true, the index is split into individual pages for each letter. 147 | #html_split_index = False 148 | 149 | # If true, links to the reST sources are added to the pages. 150 | #html_show_sourcelink = True 151 | 152 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 153 | #html_show_sphinx = True 154 | 155 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 156 | #html_show_copyright = True 157 | 158 | # If true, an OpenSearch description file will be output, and all pages will 159 | # contain a tag referring to it. The value of this option must be the 160 | # base URL from which the finished HTML is served. 161 | #html_use_opensearch = '' 162 | 163 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 164 | #html_file_suffix = None 165 | 166 | # Output file base name for HTML help builder. 167 | htmlhelp_basename = 'templated-emailsdoc' 168 | 169 | 170 | # -- Options for LaTeX output -------------------------------------------------- 171 | 172 | # The paper size ('letter' or 'a4'). 173 | #latex_paper_size = 'letter' 174 | 175 | # The font size ('10pt', '11pt' or '12pt'). 176 | #latex_font_size = '10pt' 177 | 178 | # Grouping the document tree into LaTeX files. List of tuples 179 | # (source start file, target name, title, author, documentclass [howto/manual]). 180 | latex_documents = [ 181 | ('index', 'templated-emails.tex', u'templated-emails Documentation', 182 | u'Philipp Wassibauer', 'manual'), 183 | ] 184 | 185 | # The name of an image file (relative to this directory) to place at the top of 186 | # the title page. 187 | #latex_logo = None 188 | 189 | # For "manual" documents, if this is true, then toplevel headings are parts, 190 | # not chapters. 191 | #latex_use_parts = False 192 | 193 | # If true, show page references after internal links. 194 | #latex_show_pagerefs = False 195 | 196 | # If true, show URL addresses after external links. 197 | #latex_show_urls = False 198 | 199 | # Additional stuff for the LaTeX preamble. 200 | #latex_preamble = '' 201 | 202 | # Documents to append as an appendix to all manuals. 203 | #latex_appendices = [] 204 | 205 | # If false, no module index is generated. 206 | #latex_domain_indices = True 207 | 208 | 209 | # -- Options for manual page output -------------------------------------------- 210 | 211 | # One entry per manual page. List of tuples 212 | # (source start file, name, description, authors, manual section). 213 | man_pages = [ 214 | ('index', 'templated-emails', u'templated-emails Documentation', 215 | [u'Philipp Wassibauer'], 1) 216 | ] 217 | 218 | 219 | # Example configuration for intersphinx: refer to the Python standard library. 220 | intersphinx_mapping = {'http://docs.python.org/': None} 221 | -------------------------------------------------------------------------------- /templated_emails/utils.py: -------------------------------------------------------------------------------- 1 | import logging 2 | import os 3 | import threading 4 | 5 | from django.core.mail import EmailMultiAlternatives 6 | from django.conf import settings 7 | from django.template import Context, TemplateDoesNotExist 8 | from django.contrib.sites.models import Site 9 | from django.template.loader import render_to_string 10 | from django.utils.translation import get_language, activate 11 | from django.db import models 12 | from django.core.exceptions import ImproperlyConfigured 13 | from django.contrib.auth import get_user_model 14 | 15 | 16 | try: 17 | from celery.task import task 18 | except ImportError: 19 | task = lambda f: f 20 | 21 | use_pynliner = getattr(settings, 'TEMPLATEDEMAILS_USE_PYNLINER', False) 22 | use_celery = getattr(settings, 'TEMPLATEDEMAILS_USE_CELERY', False) 23 | use_threading = not use_celery 24 | 25 | pynliner = None 26 | if use_pynliner: 27 | try: 28 | import pynliner 29 | except ImportError: 30 | pass 31 | 32 | 33 | class LanguageStoreNotAvailable(Exception): 34 | pass 35 | 36 | 37 | def get_email_directories(dir): 38 | directory_tree = False 39 | for name in os.listdir(dir): 40 | if os.path.isdir(os.path.join(dir, name)): 41 | if directory_tree == False: 42 | directory_tree = {} 43 | directory_tree[name] = get_email_directories(os.path.join(dir, name)) 44 | return directory_tree 45 | 46 | 47 | def send_templated_email(recipients, template_path, context=None, 48 | from_email=settings.DEFAULT_FROM_EMAIL, 49 | fail_silently=False, extra_headers=None): 50 | """ 51 | recipients can be either a list of emails or a list of users, 52 | if it is users the system will change to the language that the 53 | user has set as theyr mother toungue 54 | """ 55 | recipient_pks = [r.pk for r in recipients if isinstance(r, get_user_model())] 56 | recipient_emails = [e for e in recipients if not isinstance(e, get_user_model())] 57 | send = _send_task.delay if use_celery else _send 58 | msg = send(recipient_pks, recipient_emails, template_path, context, from_email, 59 | fail_silently, extra_headers=extra_headers) 60 | 61 | return msg 62 | 63 | 64 | class SendThread(threading.Thread): 65 | def __init__(self, recipient, current_language, current_site, default_context, 66 | subject_path, text_path, html_path, from_email=settings.DEFAULT_FROM_EMAIL, 67 | fail_silently=False): 68 | self.recipient = recipient 69 | self.current_language = current_language 70 | self.current_site = current_site 71 | self.default_context = default_context 72 | self.subject_path = subject_path 73 | self.text_path = text_path 74 | self.html_path = html_path 75 | self.from_email = from_email 76 | self.fail_silently = fail_silently 77 | super(SendThread, self).__init__() 78 | 79 | def run(self): 80 | recipient = self.recipient 81 | if isinstance(recipient, get_user_model()): 82 | email = recipient.email 83 | try: 84 | language = get_users_language(recipient) 85 | except LanguageStoreNotAvailable: 86 | language = None 87 | 88 | if language is not None: 89 | activate(language) 90 | else: 91 | email = recipient 92 | 93 | # populate per-recipient context 94 | context = Context(self.default_context) 95 | context['recipient'] = recipient 96 | context['email'] = email 97 | 98 | # load email subject, strip and remove line breaks 99 | subject = render_to_string(self.subject_path, context).strip() 100 | subject = "".join(subject.splitlines()) # this must be a single line 101 | text = render_to_string(self.text_path, context) 102 | 103 | msg = EmailMultiAlternatives(subject, text, self.from_email, [email]) 104 | 105 | # try to attach the html variant 106 | try: 107 | body = render_to_string(self.html_path, context) 108 | if pynliner: 109 | body = pynliner.fromString(body) 110 | msg.attach_alternative(body, "text/html") 111 | except TemplateDoesNotExist: 112 | logging.info("Email sent without HTML, since %s not found" % self.html_path) 113 | 114 | msg.send(fail_silently=self.fail_silently) 115 | 116 | # reset environment to original language 117 | if isinstance(recipient, get_user_model()): 118 | activate(self.current_language) 119 | 120 | 121 | def _send(recipient_pks, recipient_emails, template_path, context, from_email, 122 | fail_silently, extra_headers=None): 123 | recipients = list(get_user_model().objects.filter(pk__in=recipient_pks)) 124 | recipients += recipient_emails 125 | 126 | current_language = get_language() 127 | current_site = Site.objects.get(id=settings.SITE_ID) 128 | 129 | default_context = context or {} 130 | default_context["current_site"] = current_site 131 | default_context["STATIC_URL"] = settings.STATIC_URL 132 | 133 | subject_path = "%s/short.txt" % template_path 134 | text_path = "%s/email.txt" % template_path 135 | html_path = "%s/email.html" % template_path 136 | 137 | for recipient in recipients: 138 | if use_threading: 139 | SendThread(recipient, current_language, current_site, default_context, subject_path, 140 | text_path, html_path, from_email, fail_silently).start() 141 | return 142 | # if it is user, get the email and switch the language 143 | if isinstance(recipient, get_user_model()): 144 | email = recipient.email 145 | try: 146 | language = get_users_language(recipient) 147 | except LanguageStoreNotAvailable: 148 | language = None 149 | 150 | if language is not None: 151 | # activate the user's language 152 | activate(language) 153 | else: 154 | email = recipient 155 | 156 | # populate per-recipient context 157 | context = Context(default_context) 158 | context['recipient'] = recipient 159 | context['email'] = email 160 | 161 | # load email subject, strip and remove line breaks 162 | subject = render_to_string(subject_path, context).strip() 163 | subject = "".join(subject.splitlines()) # this must be a single line 164 | text = render_to_string(text_path, context) 165 | 166 | msg = EmailMultiAlternatives(subject, text, from_email, [email], 167 | headers=extra_headers) 168 | 169 | # try to attach the html variant 170 | try: 171 | body = render_to_string(html_path, context) 172 | if pynliner: 173 | body = pynliner.fromString(body) 174 | msg.attach_alternative(body, "text/html") 175 | except TemplateDoesNotExist: 176 | logging.info("Email sent without HTML, since %s not found" % html_path) 177 | 178 | msg.send(fail_silently=fail_silently) 179 | 180 | # reset environment to original language 181 | if isinstance(recipient, get_user_model()): 182 | activate(current_language) 183 | 184 | return msg 185 | if use_celery: 186 | _send_task = task(_send) 187 | 188 | 189 | def get_users_language(user): 190 | """ 191 | Returns site-specific language for this user. Raises 192 | LanguageStoreNotAvailable if this site does not use translated 193 | notifications. 194 | """ 195 | if getattr(settings, 'NOTIFICATION_LANGUAGE_MODULE', False): 196 | try: 197 | app_label, model_name = settings.NOTIFICATION_LANGUAGE_MODULE.split('.') 198 | model = models.get_model(app_label, model_name) 199 | language_model = model._default_manager.get(user__id__exact=user.id) 200 | if hasattr(language_model, 'language'): 201 | return language_model.language 202 | except (ImportError, ImproperlyConfigured, model.DoesNotExist): 203 | raise LanguageStoreNotAvailable 204 | raise LanguageStoreNotAvailable 205 | --------------------------------------------------------------------------------