1
# -*- coding: utf-8 -*-
2
from __future__ import unicode_literals
4
from django.shortcuts import render
5
from django.core.exceptions import ObjectDoesNotExist
7
from privacy_policy.models import PrivacyPolicy
10
def _format_text(language, text):
11
return '[TOC]\n\n#{}\n{}'.format(language, text)
14
def privacy_policy(request, *args, **kwargs):
15
"""Creates the text of a policy and prepare it for markdown.
17
We handle here also a link with no slug (/privacy). In this case try
18
to load english, else load the first entry in the DB.
21
# Default is 'english'
22
slug = kwargs.pop('slug', 'english')
23
policies = PrivacyPolicy.objects.all()
27
policy = policies.get(slug=slug)
28
except ObjectDoesNotExist:
29
policy = policies.all()[0]
32
text = _format_text(policy.language, policy.policy_text)
33
languages = [(x.language, x.slug) for x in policies.exclude(slug=slug)]
34
current_lang = policy.language
36
text = 'No Policy created yet!'
42
'languages': languages,
43
'cur_lang': current_lang,
46
return render(request, 'privacy_policy.html', context)