1
from settings import WIDELANDS_SVN_DIR, INQUIRY_RECIPIENTS
2
from templatetags.wl_markdown import do_wl_markdown
3
from operator import itemgetter
4
from django.core.mail import send_mail
5
from mainpage.forms import ContactForm
6
from django.shortcuts import render
7
from django.http import HttpResponseRedirect, HttpResponse
1
from django.shortcuts import render_to_response
2
from django.template import RequestContext
16
4
def mainpage(request):
17
return render(request, 'mainpage.html',)
20
def legal_notice(request):
21
"""The legal notice page to fullfill law."""
22
if request.method == 'POST':
23
form = ContactForm(request.POST)
25
name = form.cleaned_data['forename'] + \
26
' ' + form.cleaned_data['surname']
27
subject = 'An inquiry over the webpage'
28
message = '\n'.join(['From: ' + name,
29
'EMail: ' + form.cleaned_data['email'],
31
form.cleaned_data['inquiry']])
32
sender = 'legal_note@widelands.org'
34
# get email addresses which are in form of ('name','email'),
36
for recipient in INQUIRY_RECIPIENTS:
37
recipients.append(recipient[1])
39
send_mail(subject, message, sender,
40
recipients, fail_silently=False)
42
return HttpResponseRedirect('/legal_notice_thanks/')
45
form = ContactForm() # An unbound form
47
return render(request, 'mainpage/legal_notice.html', {
49
'inquiry_recipients': INQUIRY_RECIPIENTS,
53
def legal_notice_thanks(request):
54
return render(request, 'mainpage/legal_notice_thanks.html')
57
def developers(request):
58
"""This reads out some json files in the SVN directory, and returns it as a
61
This replaces the wiki developers list
65
# Get locale and translator names from each .json file and
66
# store them in one list.
70
path = os.path.normpath(WIDELANDS_SVN_DIR + 'data/i18n/locales/')
72
transl_files = os.listdir(path)
74
for fname in transl_files:
75
if fname.endswith('.json'):
76
with open(path + '/' + fname, 'r') as f:
77
json_data = json.load(f)
79
if json_data['translator-list'] != 'translator-credits':
80
if not 'your-language-name-in-english' in json_data:
81
transl_list = ['KeyError']
83
transl_list.append(json_data)
85
transl_list = ['KeyError']
88
# No KeyError -> Sort the list
89
if 'KeyError' in transl_list:
90
txt = 'Some Translator key is wrong, please contact the Developers.\n'
92
transl_list.sort(key=itemgetter(
93
'your-language-name-in-english'))
96
txt = 'No files for translators found!\n'
98
txt = txt + "Couldn't find translators directory!\n"
100
# Get other developers, put in the translators list
101
# at given position and prepare all for wl_markdown
103
with open(WIDELANDS_SVN_DIR + 'data/txts/developers.json', 'r') as f:
104
json_data = json.load(f)['developers']
106
for head in json_data:
108
txt = txt + '##' + head['heading'] + '\n'
109
# Inserting Translators if there was no error
110
if head['heading'] == 'Translators' and 'KeyError' not in transl_list:
111
for values in (transl_list):
112
# Add subheader for locale
113
txt = txt + '### ' + \
114
values['your-language-name-in-english'] + '\n'
115
# Prepaire the names for wl_markdown
117
values['translator-list'].replace('\n', '\n* ') + '\n'
119
# Add a subheader or/and the member(s)
120
for entry in head['entries']:
121
if 'subheading' in entry.keys():
122
txt = txt + '###' + entry['subheading'] + '\n'
123
if 'members' in entry.keys():
124
for name in entry['members']:
125
txt = txt + '* ' + name + '\n'
127
txt = txt + "Couldn't find developer file!"
129
txt = do_wl_markdown(txt, beautify=False)
131
return render(request, 'mainpage/developers.html',
136
def changelog(request):
137
"""This reads out the changelog in the SVN directory, and returns it as a
140
This replaces the wiki changelog
143
data = codecs.open(WIDELANDS_SVN_DIR + 'ChangeLog', encoding='utf-8', mode='r').read()
144
return render(request, 'mainpage/changelog.html',
149
def custom_http_500(request):
150
"""A custom http 500 error page to not lose css styling."""
151
return render(request, '500.html', status=500)
154
def view_locale(request):
155
loc_info = 'getlocale: ' + str(locale.getlocale()) + \
156
'<br/>getdefaultlocale(): ' + str(locale.getdefaultlocale()) + \
157
'<br/>fs_encoding: ' + str(sys.getfilesystemencoding()) + \
158
'<br/>sys default encoding: ' + str(sys.getdefaultencoding())
159
return HttpResponse(loc_info)
5
return render_to_response('mainpage.html', context_instance=RequestContext(request))