530.1.1
by kaputtnik
mv main files into mainpage directory; apply needed changes |
1 |
from django.conf import settings |
199
by Holger Rapp
Added automatic synchronization between SVN developers file and the homepage |
2 |
from templatetags.wl_markdown import do_wl_markdown |
396.1.1
by franku
devs_and_locales_list |
3 |
from operator import itemgetter |
397.2.1
by franku
A legal notice page |
4 |
from django.core.mail import send_mail |
5 |
from mainpage.forms import ContactForm |
|
6 |
from django.shortcuts import render |
|
440.1.1
by franku
save upload of maps |
7 |
from django.http import HttpResponseRedirect, HttpResponse |
173.2.3
by Holger Rapp
Made the site compatible to django 1.1 and all the various packages |
8 |
import sys |
389.1.1
by franku
bug 1424072, developers list from json |
9 |
import json |
10 |
import os |
|
11 |
import os.path |
|
440.1.1
by franku
save upload of maps |
12 |
import locale |
472.4.1
by franku
use utf8 when readin changelog; add a TOC to the list of developers |
13 |
import codecs |
173.2.3
by Holger Rapp
Made the site compatible to django 1.1 and all the various packages |
14 |
|
396.1.4
by franku
Code after Pyformat |
15 |
|
1
by Holger Rapp
Initial commit of new widelands homepage |
16 |
def mainpage(request): |
513.1.3
by franku
moved base templates again and made appropriate changes |
17 |
return render(request, 'mainpage/mainpage.html',) |
173.2.3
by Holger Rapp
Made the site compatible to django 1.1 and all the various packages |
18 |
|
413.1.1
by franku
reworked http500 error page; redirect /docs to docs/wl |
19 |
|
397.2.1
by franku
A legal notice page |
20 |
def legal_notice(request): |
397.2.2
by franku
recipients as name/adress |
21 |
"""The legal notice page to fullfill law."""
|
401
by Holger Rapp
Merge the legal notice branch. |
22 |
if request.method == 'POST': |
23 |
form = ContactForm(request.POST) |
|
397.2.1
by franku
A legal notice page |
24 |
if form.is_valid(): |
413.1.1
by franku
reworked http500 error page; redirect /docs to docs/wl |
25 |
name = form.cleaned_data['forename'] + \ |
26 |
' ' + form.cleaned_data['surname'] |
|
27 |
subject = 'An inquiry over the webpage' |
|
397.2.2
by franku
recipients as name/adress |
28 |
message = '\n'.join(['From: ' + name, |
413.1.1
by franku
reworked http500 error page; redirect /docs to docs/wl |
29 |
'EMail: ' + form.cleaned_data['email'], |
30 |
'Inquiry:', |
|
31 |
form.cleaned_data['inquiry']]) |
|
397.2.1
by franku
A legal notice page |
32 |
sender = 'legal_note@widelands.org' |
401
by Holger Rapp
Merge the legal notice branch. |
33 |
|
413.1.1
by franku
reworked http500 error page; redirect /docs to docs/wl |
34 |
# get email addresses which are in form of ('name','email'),
|
397.2.2
by franku
recipients as name/adress |
35 |
recipients = [] |
530.1.1
by kaputtnik
mv main files into mainpage directory; apply needed changes |
36 |
for recipient in settings.INQUIRY_RECIPIENTS: |
397.2.2
by franku
recipients as name/adress |
37 |
recipients.append(recipient[1]) |
401
by Holger Rapp
Merge the legal notice branch. |
38 |
|
397.2.1
by franku
A legal notice page |
39 |
send_mail(subject, message, sender, |
413.1.1
by franku
reworked http500 error page; redirect /docs to docs/wl |
40 |
recipients, fail_silently=False) |
41 |
# Redirect after POST
|
|
42 |
return HttpResponseRedirect('/legal_notice_thanks/') |
|
173.2.3
by Holger Rapp
Made the site compatible to django 1.1 and all the various packages |
43 |
|
397.2.1
by franku
A legal notice page |
44 |
else: |
413.1.1
by franku
reworked http500 error page; redirect /docs to docs/wl |
45 |
form = ContactForm() # An unbound form |
46 |
||
397.2.1
by franku
A legal notice page |
47 |
return render(request, 'mainpage/legal_notice.html', { |
48 |
'form': form, |
|
530.1.1
by kaputtnik
mv main files into mainpage directory; apply needed changes |
49 |
'inquiry_recipients': settings.INQUIRY_RECIPIENTS, |
413.1.1
by franku
reworked http500 error page; redirect /docs to docs/wl |
50 |
})
|
51 |
||
401
by Holger Rapp
Merge the legal notice branch. |
52 |
|
397.2.1
by franku
A legal notice page |
53 |
def legal_notice_thanks(request): |
54 |
return render(request, 'mainpage/legal_notice_thanks.html') |
|
401
by Holger Rapp
Merge the legal notice branch. |
55 |
|
413.1.1
by franku
reworked http500 error page; redirect /docs to docs/wl |
56 |
|
199
by Holger Rapp
Added automatic synchronization between SVN developers file and the homepage |
57 |
def developers(request): |
396.1.4
by franku
Code after Pyformat |
58 |
"""This reads out some json files in the SVN directory, and returns it as a
|
59 |
wl_markdown_object.
|
|
60 |
||
61 |
This replaces the wiki developers list
|
|
62 |
||
63 |
"""
|
|
64 |
||
65 |
# Get locale and translator names from each .json file and
|
|
389.1.1
by franku
bug 1424072, developers list from json |
66 |
# store them in one list.
|
472.4.1
by franku
use utf8 when readin changelog; add a TOC to the list of developers |
67 |
txt = '[TOC]\n\n' |
389.1.2
by franku
added exceptions |
68 |
transl_files = [] |
389.1.1
by franku
bug 1424072, developers list from json |
69 |
transl_list = [] |
530.1.1
by kaputtnik
mv main files into mainpage directory; apply needed changes |
70 |
path = os.path.normpath(settings.WIDELANDS_SVN_DIR + 'data/i18n/locales/') |
389.1.2
by franku
added exceptions |
71 |
try: |
72 |
transl_files = os.listdir(path) |
|
73 |
if transl_files: |
|
74 |
for fname in transl_files: |
|
396.1.4
by franku
Code after Pyformat |
75 |
if fname.endswith('.json'): |
76 |
with open(path + '/' + fname, 'r') as f: |
|
396.1.1
by franku
devs_and_locales_list |
77 |
json_data = json.load(f) |
78 |
try: |
|
396.1.4
by franku
Code after Pyformat |
79 |
if json_data['translator-list'] != 'translator-credits': |
396.1.3
by franku
code optimizing |
80 |
if not 'your-language-name-in-english' in json_data: |
396.1.4
by franku
Code after Pyformat |
81 |
transl_list = ['KeyError'] |
396.1.3
by franku
code optimizing |
82 |
break
|
389.1.2
by franku
added exceptions |
83 |
transl_list.append(json_data) |
396.1.1
by franku
devs_and_locales_list |
84 |
except KeyError: |
396.1.4
by franku
Code after Pyformat |
85 |
transl_list = ['KeyError'] |
396.1.3
by franku
code optimizing |
86 |
break
|
396.1.4
by franku
Code after Pyformat |
87 |
|
396.1.1
by franku
devs_and_locales_list |
88 |
# No KeyError -> Sort the list
|
396.1.3
by franku
code optimizing |
89 |
if 'KeyError' in transl_list: |
396.1.4
by franku
Code after Pyformat |
90 |
txt = 'Some Translator key is wrong, please contact the Developers.\n' |
396.1.1
by franku
devs_and_locales_list |
91 |
else: |
396.1.4
by franku
Code after Pyformat |
92 |
transl_list.sort(key=itemgetter( |
93 |
'your-language-name-in-english')) |
|
396.1.1
by franku
devs_and_locales_list |
94 |
|
389.1.2
by franku
added exceptions |
95 |
else: |
396.1.4
by franku
Code after Pyformat |
96 |
txt = 'No files for translators found!\n' |
389.1.2
by franku
added exceptions |
97 |
except OSError: |
396.1.1
by franku
devs_and_locales_list |
98 |
txt = txt + "Couldn't find translators directory!\n" |
389.1.2
by franku
added exceptions |
99 |
|
389.1.1
by franku
bug 1424072, developers list from json |
100 |
# Get other developers, put in the translators list
|
396.1.2
by franku
formatting fixes |
101 |
# at given position and prepare all for wl_markdown
|
389.1.2
by franku
added exceptions |
102 |
try: |
530.1.1
by kaputtnik
mv main files into mainpage directory; apply needed changes |
103 |
with open(settings.WIDELANDS_SVN_DIR + 'data/txts/developers.json', 'r') as f: |
396.1.3
by franku
code optimizing |
104 |
json_data = json.load(f)['developers'] |
396.1.1
by franku
devs_and_locales_list |
105 |
|
389.1.2
by franku
added exceptions |
106 |
for head in json_data: |
512.2.1
by franku
adjusted to fit with changes in developers.lua |
107 |
if 'heading' in head: |
108 |
# Add first header
|
|
109 |
txt = txt + '##' + head['heading'] + '\n' |
|
110 |
# Inserting Translators if there was no error
|
|
111 |
if head['heading'] == 'Translators' and 'KeyError' not in transl_list: |
|
112 |
for values in (transl_list): |
|
113 |
# Add subheader for locale
|
|
114 |
txt = txt + '### ' + \ |
|
115 |
values['your-language-name-in-english'] + '\n' |
|
116 |
# Prepaire the names for wl_markdown
|
|
117 |
txt = txt + '* ' + \ |
|
118 |
values['translator-list'].replace('\n', '\n* ') + '\n' |
|
119 |
||
120 |
# Add a subheader or/and the member(s)
|
|
121 |
for entry in head['entries']: |
|
122 |
if 'subheading' in entry.keys(): |
|
123 |
txt = txt + '###' + entry['subheading'] + '\n' |
|
124 |
if 'members' in entry.keys(): |
|
125 |
for name in entry['members']: |
|
126 |
txt = txt + '* ' + name + '\n' |
|
512.2.2
by franku
added translation key |
127 |
if 'translate' in entry.keys(): |
128 |
for transl in entry['translate']: |
|
512.2.3
by franku
minor fix |
129 |
txt = txt + '* ' + transl + '\n' |
512.2.1
by franku
adjusted to fit with changes in developers.lua |
130 |
|
389.1.2
by franku
added exceptions |
131 |
except IOError: |
132 |
txt = txt + "Couldn't find developer file!" |
|
396.1.4
by franku
Code after Pyformat |
133 |
|
504.3.12
by franku
fixed classify_links |
134 |
txt = do_wl_markdown(txt, beautify=False) |
396.1.4
by franku
Code after Pyformat |
135 |
|
479.1.1
by franku
fetch current copyright year automatically; some cleanups |
136 |
return render(request, 'mainpage/developers.html', |
137 |
{'developers': txt} |
|
138 |
)
|
|
199
by Holger Rapp
Added automatic synchronization between SVN developers file and the homepage |
139 |
|
110
by Holger Rapp
Added new tag for markdown svn:r3222 will be translated into a clickable link to a revision |
140 |
|
141 |
def changelog(request): |
|
396.1.4
by franku
Code after Pyformat |
142 |
"""This reads out the changelog in the SVN directory, and returns it as a
|
143 |
wl_markdown_object.
|
|
144 |
||
145 |
This replaces the wiki changelog
|
|
146 |
||
147 |
"""
|
|
530.1.1
by kaputtnik
mv main files into mainpage directory; apply needed changes |
148 |
data = codecs.open(settings.WIDELANDS_SVN_DIR + 'ChangeLog', encoding='utf-8', mode='r').read() |
479.1.1
by franku
fetch current copyright year automatically; some cleanups |
149 |
return render(request, 'mainpage/changelog.html', |
150 |
{'changelog': data}, |
|
151 |
)
|
|
413.1.1
by franku
reworked http500 error page; redirect /docs to docs/wl |
152 |
|
153 |
||
154 |
def custom_http_500(request): |
|
413.1.3
by franku
string changes |
155 |
"""A custom http 500 error page to not lose css styling."""
|
413.1.1
by franku
reworked http500 error page; redirect /docs to docs/wl |
156 |
return render(request, '500.html', status=500) |
440.1.1
by franku
save upload of maps |
157 |
|
158 |
||
159 |
def view_locale(request): |
|
438.1.6
by franku
run the script |
160 |
loc_info = 'getlocale: ' + str(locale.getlocale()) + \ |
161 |
'<br/>getdefaultlocale(): ' + str(locale.getdefaultlocale()) + \ |
|
162 |
'<br/>fs_encoding: ' + str(sys.getfilesystemencoding()) + \ |
|
163 |
'<br/>sys default encoding: ' + str(sys.getdefaultencoding()) |
|
440.1.1
by franku
save upload of maps |
164 |
return HttpResponse(loc_info) |