~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to privacy_policy/views.py

  • Committer: franku
  • Date: 2018-10-03 09:01:09 UTC
  • mto: This revision was merged to the branch mainline in revision 502.
  • Revision ID: somal@arcor.de-20181003090109-so4zn8x9vujarq6n
removed IPAddressField from pybb

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
from __future__ import unicode_literals
3
 
 
4
 
from django.shortcuts import render
5
 
from django.core.exceptions import ObjectDoesNotExist
6
 
 
7
 
from privacy_policy.models import PrivacyPolicy
8
 
 
9
 
 
10
 
def _format_text(language, text):
11
 
    return '[TOC]\n\n#{}\n{}'.format(language, text)
12
 
 
13
 
 
14
 
def privacy_policy(request, *args, **kwargs):
15
 
    """Creates the text of a policy and prepare it for markdown.
16
 
 
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.
19
 
    """
20
 
 
21
 
    # Default is 'english'
22
 
    slug = kwargs.pop('slug', 'english')
23
 
    policies = PrivacyPolicy.objects.all()
24
 
 
25
 
    if policies.count():
26
 
        try:
27
 
            policy = policies.get(slug=slug)
28
 
        except ObjectDoesNotExist:
29
 
            policy = policies.all()[0]
30
 
            slug = policy.slug
31
 
 
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
35
 
    else:
36
 
        text = 'No Policy created yet!'
37
 
        languages = ''
38
 
        current_lang = ''
39
 
 
40
 
    context = {
41
 
        'text': text,
42
 
        'languages': languages,
43
 
        'cur_lang': current_lang,
44
 
    }
45
 
 
46
 
    return render(request, 'privacy_policy.html', context)