Merge lp:~widelands-dev/widelands-website/privacy_policy into lp:widelands-website

Proposed by kaputtnik
Status: Merged
Merged at revision: 503
Proposed branch: lp:~widelands-dev/widelands-website/privacy_policy
Merge into: lp:widelands-website
Diff against target: 229 lines (+159/-0)
10 files modified
privacy_policy/admin.py (+13/-0)
privacy_policy/apps.py (+8/-0)
privacy_policy/migrations/0001_initial.py (+28/-0)
privacy_policy/models.py (+24/-0)
privacy_policy/urls.py (+7/-0)
privacy_policy/views.py (+45/-0)
settings.py (+1/-0)
templates/footer.html (+2/-0)
templates/privacy_policy.html (+30/-0)
urls.py (+1/-0)
To merge this branch: bzr merge lp:~widelands-dev/widelands-website/privacy_policy
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+356282@code.launchpad.net

Commit message

Add app for Privacy policies

Description of the change

This branch adds a Database entry for storing privacy policies. This makes it possible to have policies for different languages.

Each language will be shown in its own page, rendered through markdown. If more than one language is available there will be a sentence shown on op of the site, saying: "This site is also available in: language1, language2 and language3".

Calling the url /privacy will try to load 'english' at first time. If this isn't available, the first entry stored in the Database is shown. If no privacy can be found the String "No policy created yet!" is shown.

To post a comment you must log in.
505. By kaputtnik

corrected english

Revision history for this message
GunChleoc (gunchleoc) wrote :

LGTM - just 1 comment for a potential bug

review: Approve
506. By kaputtnik

fixed url; thanks Gun

Revision history for this message
kaputtnik (franku) wrote :

Good catch!

^ means the string has to be at the beginning. Without it is also possible to call the url '/fooprivacy/' which is not what is wanted.

Thanks a lot for the review :-)

Revision history for this message
kaputtnik (franku) wrote :

Merged and deployed.

Gave GunChleoc rights to add/change/delete privacy policies.

Added a German privacy policy.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'privacy_policy'
2=== added file 'privacy_policy/__init__.py'
3=== added file 'privacy_policy/admin.py'
4--- privacy_policy/admin.py 1970-01-01 00:00:00 +0000
5+++ privacy_policy/admin.py 2018-10-10 17:05:17 +0000
6@@ -0,0 +1,13 @@
7+# -*- coding: utf-8 -*-
8+from __future__ import unicode_literals
9+
10+from django.contrib import admin
11+from privacy_policy.models import PrivacyPolicy
12+
13+
14+class PrivacyPolicyAdmin(admin.ModelAdmin):
15+ prepopulated_fields = {"slug": ("language",)}
16+ list_display = ('language',)
17+
18+
19+admin.site.register(PrivacyPolicy, PrivacyPolicyAdmin)
20
21=== added file 'privacy_policy/apps.py'
22--- privacy_policy/apps.py 1970-01-01 00:00:00 +0000
23+++ privacy_policy/apps.py 2018-10-10 17:05:17 +0000
24@@ -0,0 +1,8 @@
25+# -*- coding: utf-8 -*-
26+from __future__ import unicode_literals
27+
28+from django.apps import AppConfig
29+
30+
31+class PrivacyPolicyConfig(AppConfig):
32+ name = 'privacy_policy'
33
34=== added directory 'privacy_policy/migrations'
35=== added file 'privacy_policy/migrations/0001_initial.py'
36--- privacy_policy/migrations/0001_initial.py 1970-01-01 00:00:00 +0000
37+++ privacy_policy/migrations/0001_initial.py 2018-10-10 17:05:17 +0000
38@@ -0,0 +1,28 @@
39+# -*- coding: utf-8 -*-
40+# Generated by Django 1.11.12 on 2018-10-08 18:23
41+from __future__ import unicode_literals
42+
43+from django.db import migrations, models
44+
45+
46+class Migration(migrations.Migration):
47+
48+ initial = True
49+
50+ dependencies = [
51+ ]
52+
53+ operations = [
54+ migrations.CreateModel(
55+ name='PrivacyPolicy',
56+ fields=[
57+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
58+ ('language', models.CharField(default='English', help_text='Will be displayed as a level 1 header', max_length=30, unique=True)),
59+ ('policy_text', models.TextField(help_text='Text will be rendered using markdown syntax')),
60+ ('slug', models.SlugField(unique=True)),
61+ ],
62+ options={
63+ 'ordering': ['language'],
64+ },
65+ ),
66+ ]
67
68=== added file 'privacy_policy/migrations/__init__.py'
69=== added file 'privacy_policy/models.py'
70--- privacy_policy/models.py 1970-01-01 00:00:00 +0000
71+++ privacy_policy/models.py 2018-10-10 17:05:17 +0000
72@@ -0,0 +1,24 @@
73+# -*- coding: utf-8 -*-
74+from __future__ import unicode_literals
75+
76+from django.db import models
77+from django.urls import reverse
78+
79+
80+class PrivacyPolicy(models.Model):
81+
82+ language = models.CharField(default='English', max_length=30,
83+ help_text='Will be displayed as a level 1 header',
84+ unique=True)
85+ policy_text = models.TextField(
86+ help_text='Text will be rendered using markdown syntax')
87+ slug = models.SlugField(unique=True)
88+
89+ class Meta:
90+ ordering = ['language']
91+
92+ def __unicode__(self):
93+ return self.language
94+
95+ def get_absolute_url(self):
96+ return reverse('policy_translated', kwargs={'lang': self.language})
97\ No newline at end of file
98
99=== added file 'privacy_policy/urls.py'
100--- privacy_policy/urls.py 1970-01-01 00:00:00 +0000
101+++ privacy_policy/urls.py 2018-10-10 17:05:17 +0000
102@@ -0,0 +1,7 @@
103+from django.conf.urls import *
104+from privacy_policy import views
105+
106+urlpatterns = [
107+ url(r'^$', views.privacy_policy, name='privacy_policy'),
108+ url(r'^(?P<slug>[-\w]+)/', views.privacy_policy, name='policy_translated'),
109+]
110
111=== added file 'privacy_policy/views.py'
112--- privacy_policy/views.py 1970-01-01 00:00:00 +0000
113+++ privacy_policy/views.py 2018-10-10 17:05:17 +0000
114@@ -0,0 +1,45 @@
115+# -*- coding: utf-8 -*-
116+from __future__ import unicode_literals
117+
118+from django.shortcuts import render
119+from django.core.exceptions import ObjectDoesNotExist
120+
121+from privacy_policy.models import PrivacyPolicy
122+
123+
124+def _format_text(language, text):
125+ return '[TOC]\n\n#{}\n{}'.format(language, text)
126+
127+
128+def privacy_policy(request, *args, **kwargs):
129+ """Creates the text of a policy and prepare it for markdown.
130+
131+ We handle here also a link with no slug (/privacy). In this case try
132+ to load english, else load the first entry in the DB.
133+ """
134+
135+ # Default is 'english'
136+ slug = kwargs.pop('slug', 'english')
137+ policies = PrivacyPolicy.objects.all()
138+
139+ if policies.count():
140+ try:
141+ policy = policies.get(slug=slug)
142+ except ObjectDoesNotExist:
143+ policy = policies.all()[0]
144+ slug = policy.slug
145+
146+ text = _format_text(policy.language, policy.policy_text)
147+ languages = [(x.language, x.slug) for x in policies.exclude(slug=slug)]
148+ current_lang = policy.language
149+ else:
150+ text = 'No Policy created yet!'
151+ languages = ''
152+ current_lang = ''
153+
154+ context = {
155+ 'text': text,
156+ 'languages': languages,
157+ 'cur_lang': current_lang,
158+ }
159+ return render(request, 'privacy_policy.html', context)
160
161=== modified file 'settings.py'
162--- settings.py 2018-10-01 16:41:29 +0000
163+++ settings.py 2018-10-10 17:05:17 +0000
164@@ -95,6 +95,7 @@
165 'wlscheduling',
166 'check_input.apps.CheckInput',
167 'documentation',
168+ 'privacy_policy.apps.PrivacyPolicyConfig',
169 'haystack', # search engine; see option HAYSTACK_CONNECTIONS
170
171 # Modified 3rd party apps
172
173=== modified file 'templates/footer.html'
174--- templates/footer.html 2018-02-11 14:48:26 +0000
175+++ templates/footer.html 2018-10-10 17:05:17 +0000
176@@ -9,4 +9,6 @@
177 <div id="footer">
178 Copyright &copy; 2009 - {% current_year %} By the Widelands Development Team<br />
179 <a class="small" href="{% url 'legal_notice' %}">Legal notice (contact)</a>
180+ <span class="small"> &#9679; </span>
181+ <a class="small" href="{% url 'privacy_policy'%}">Privacy Policy</a>
182 </div>
183
184=== added file 'templates/privacy_policy.html'
185--- templates/privacy_policy.html 1970-01-01 00:00:00 +0000
186+++ templates/privacy_policy.html 2018-10-10 17:05:17 +0000
187@@ -0,0 +1,30 @@
188+{% extends "base.html" %}
189+{% load wl_markdown %}
190+
191+{% block title %}Privacy policy {{ cur_lang }} {{ block.super }}{% endblock %}
192+
193+{% block extra_head %}
194+{{ block.super}}
195+<link rel="stylesheet" type="text/css" media="all" href="{{ MEDIA_URL }}css/wiki.css" />
196+{% endblock %}
197+
198+{% block content %}
199+<h1>Privacy Policy</h1>
200+
201+<div class="blogEntry">
202+ {% with languages|length as count %}
203+ {% if count > 0 %}
204+ <p>
205+ This page is also available as:
206+ {% for lang, slug in languages %}
207+ {# The if statement has to be directly after the link, otherwise we have unwanted spaces #}
208+ <a href="{% url 'policy_translated' slug %}">{{ lang }}</a>{% if count > 1 and forloop.revcounter0 == 1 %} and
209+ {% elif count > 1 and forloop.revcounter0 != 0 %}, {% endif %}
210+ {% endfor %}
211+ </p>
212+ {% endif %}
213+ {% endwith %}
214+
215+ {{ text|wl_markdown }}
216+</div>
217+{% endblock %}
218
219=== modified file 'urls.py'
220--- urls.py 2018-09-12 07:45:35 +0000
221+++ urls.py 2018-10-10 17:05:17 +0000
222@@ -58,6 +58,7 @@
223 url(r'^ggz/', include('wlggz.urls')),
224 url(r'^moderated/', include('check_input.urls')),
225 url(r'^scheduling/', include('wlscheduling.urls')),
226+ url(r'^privacy/', include('privacy_policy.urls')),
227 ]
228
229 try:

Subscribers

People subscribed via source and target branches