1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
from django.conf import settings
from .templatetags.wl_markdown import do_wl_markdown
from operator import itemgetter
from django.core.mail import send_mail
from mainpage.forms import ContactForm
from django.shortcuts import render
from django.http import HttpResponseRedirect, HttpResponse
import sys
import json
import os
import os.path
import locale
import codecs
def mainpage(request):
return render(request, 'mainpage/mainpage.html',)
def legal_notice(request):
"""The legal notice page to fullfill law."""
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
name = form.cleaned_data['forename'] + \
' ' + form.cleaned_data['surname']
subject = 'An inquiry over the webpage'
message = '\n'.join(['From: ' + name,
'EMail: ' + form.cleaned_data['email'],
'Inquiry:',
form.cleaned_data['inquiry']])
sender = 'legal_note@widelands.org'
# get email addresses which are in form of ('name','email'),
recipients = []
for recipient in settings.INQUIRY_RECIPIENTS:
recipients.append(recipient[1])
send_mail(subject, message, sender,
recipients, fail_silently=False)
# Redirect after POST
return HttpResponseRedirect('/legal_notice_thanks/')
else:
form = ContactForm() # An unbound form
return render(request, 'mainpage/legal_notice.html', {
'form': form,
'inquiry_recipients': settings.INQUIRY_RECIPIENTS,
})
def legal_notice_thanks(request):
return render(request, 'mainpage/legal_notice_thanks.html')
def developers(request):
"""This reads out some json files in the SVN directory, and returns it as a
wl_markdown_object.
This replaces the wiki developers list
"""
# Get locale and translator names from each .json file and
# store them in one list.
txt = '[TOC]\n\n'
transl_files = []
transl_list = []
path = os.path.normpath(settings.WIDELANDS_SVN_DIR + 'data/i18n/locales/')
try:
transl_files = os.listdir(path)
if transl_files:
for fname in transl_files:
if fname.endswith('.json'):
with open(path + '/' + fname, 'r') as f:
json_data = json.load(f)
try:
if json_data['translator-list'] != 'translator-credits':
if not 'your-language-name-in-english' in json_data:
transl_list = ['KeyError']
break
transl_list.append(json_data)
except KeyError:
transl_list = ['KeyError']
break
# No KeyError -> Sort the list
if 'KeyError' in transl_list:
txt = 'Some Translator key is wrong, please contact the Developers.\n'
else:
transl_list.sort(key=itemgetter(
'your-language-name-in-english'))
else:
txt = 'No files for translators found!\n'
except OSError:
txt = txt + "Couldn't find translators directory!\n"
# Get other developers, put in the translators list
# at given position and prepare all for wl_markdown
try:
with open(settings.WIDELANDS_SVN_DIR + 'data/txts/developers.json', 'r') as f:
json_data = json.load(f)['developers']
for head in json_data:
if 'heading' in head:
# Add first header
txt = txt + '##' + head['heading'] + '\n'
# Inserting Translators if there was no error
if head['heading'] == 'Translators' and 'KeyError' not in transl_list:
for values in (transl_list):
# Add subheader for locale
txt = txt + '### ' + \
values['your-language-name-in-english'] + '\n'
# Prepaire the names for wl_markdown
txt = txt + '* ' + \
values['translator-list'].replace('\n', '\n* ') + '\n'
# Add a subheader or/and the member(s)
for entry in head['entries']:
if 'subheading' in list(entry.keys()):
txt = txt + '###' + entry['subheading'] + '\n'
if 'members' in list(entry.keys()):
for name in entry['members']:
txt = txt + '* ' + name + '\n'
if 'translate' in list(entry.keys()):
for transl in entry['translate']:
txt = txt + '* ' + transl + '\n'
except IOError:
txt = txt + "Couldn't find developer file!"
txt = do_wl_markdown(txt, beautify=False)
return render(request, 'mainpage/developers.html',
{'developers': txt}
)
def changelog(request):
"""This reads out the changelog in the SVN directory, and returns it as a
wl_markdown_object.
This replaces the wiki changelog
"""
data = codecs.open(settings.WIDELANDS_SVN_DIR + 'ChangeLog', encoding='utf-8', mode='r').read()
return render(request, 'mainpage/changelog.html',
{'changelog': data},
)
def custom_http_500(request):
"""A custom http 500 error page to not lose css styling."""
return render(request, '500.html', status=500)
def view_locale(request):
loc_info = 'getlocale: ' + str(locale.getlocale()) + \
'<br/>getdefaultlocale(): ' + str(locale.getdefaultlocale()) + \
'<br/>fs_encoding: ' + str(sys.getfilesystemencoding()) + \
'<br/>sys default encoding: ' + str(sys.getdefaultencoding()) + \
'<br><br> Environment variables:' + \
'<br>DISPLAY: ' + os.environ.get('DISPLAY', 'Not set')
return HttpResponse(loc_info)
|