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
|
from django.shortcuts import render_to_response
from django.template import RequestContext
from settings import WIDELANDS_SVN_DIR
from templatetags.wl_markdown import do_wl_markdown
import sys
import re
def mainpage(request):
return render_to_response('mainpage.html',
context_instance=RequestContext(request))
from forms import RegistrationWithCaptchaForm
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from registration.backends.default import DefaultBackend
def register(request):
"""
Overwritten view from registration to include a captcha.
We only need this because the remote IP addr must be passed
to the form; the registration doesn't do this
"""
remote_ip = request.META['REMOTE_ADDR']
if request.method == 'POST':
form = RegistrationWithCaptchaForm(remote_ip,data=request.POST,
files=request.FILES)
if form.is_valid():
new_user = DefaultBackend().register(request, **form.cleaned_data)
return HttpResponseRedirect(reverse('registration_complete'))
else:
form = RegistrationWithCaptchaForm(remote_ip)
context = RequestContext(request)
return render_to_response("registration/registration_form.html",
{ 'registration_form': form },
context_instance=context)
def developers(request):
"""
This reads out the authors file in the SVN directory, and returns it
as a wl_markdown_object. This replaces the wiki developers list
"""
data = open(WIDELANDS_SVN_DIR + "txts/developers", "r").readlines()[4:]
newdata = []
for line in data:
line = line.strip('"_ \n\r').rstrip('" _ \n\r')
newdata.append(line)
txt = ''.join(newdata)
txt,_ = re.subn(r'<\/?rt.*?>', "", txt)
txt,_ = re.subn(r'<br.*?>', "", txt)
b = { "24": "\n\n## ",
"18": "\n\n### ",
"14": "\n\n#### ",
"12": "- ",
}
e = { "24": "\n\n",
"18": "\n",
"14": "\n",
"12": "\n",
}
txt,_ = re.subn(r'<p * font-size=(\d+).*?>(.*?)</p>',
lambda m: "%s%s%s" %
(b[m.group(1)], m.group(2), e[m.group(1)]), txt)
txt,_ = re.subn(r'<p.*?>(.*?)</p>',
lambda m: ("- %s\n" % m.group(1) if len(m.group(1).strip()) else "")
, txt)
txt = do_wl_markdown(txt.decode('utf-8'),custom=False)
return render_to_response("mainpage/developers.html",
{"developers": txt},
context_instance=RequestContext(request)
)
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 = open(WIDELANDS_SVN_DIR + "ChangeLog", "r").read()
return render_to_response("mainpage/changelog.html",
{"changelog": data},
context_instance=RequestContext(request)
)
|