Example #1
0
def render_email(template, context):
    """Renders a template in the currently set locale."""
    req = RequestFactory()
    req.META = {}
    req.locale = translation.get_language()

    return jingo.render_to_string(req, template, context)
Example #2
0
    def render(self, name, value, attrs=None):
        topics_and_subtopics = Topic.objects.all()
        topics = [t for t in topics_and_subtopics if t.parent_id is None]

        for topic in topics:
            self.process_topic(value, topic)

            topic.my_subtopics = [t for t in topics_and_subtopics
                                  if t.parent_id == topic.id]

            for subtopic in topic.my_subtopics:
                self.process_topic(value, subtopic)

        # Create a fake request to make jingo happy.
        req = RequestFactory()
        req.META = {}
        req.locale = settings.WIKI_DEFAULT_LANGUAGE

        return jingo.render_to_string(
            req,
            'wiki/includes/topics_widget.html',
            {
                'topics': topics,
                'name': name,
            })
Example #3
0
    def _render(locale):
        """Render an email in the given locale.

        Because of safe_translation decorator, if this fails,
        the function will be run again in English.
        """
        req = RequestFactory()
        req.META = {}
        req.locale = locale

        return jingo.render_to_string(req, template, context)