~widelands-dev/widelands-website/trunk

« back to all changes in this revision

Viewing changes to mainpage/views.py

  • Committer: Holger Rapp
  • Date: 2010-01-01 20:08:18 UTC
  • mto: (173.3.2 widelands)
  • mto: This revision was merged to the branch mainline in revision 176.
  • Revision ID: rapp@mrt.uka.de-20100101200818-znihhmyhlx0o33gp
Added diff_match_patch from google, because they do not provide a setup.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from django.shortcuts import render_to_response
2
2
from django.template import RequestContext
3
3
from settings import WIDELANDS_SVN_DIR
4
 
from templatetags.wl_markdown import do_wl_markdown
5
 
 
6
 
import sys
7
 
import re
8
4
 
9
5
def mainpage(request):
10
 
    return render_to_response('mainpage.html',
11
 
                context_instance=RequestContext(request))
12
 
 
13
 
 
 
6
    return render_to_response('mainpage.html', context_instance=RequestContext(request))
 
7
    
 
8
    
14
9
from forms import RegistrationWithCaptchaForm
15
10
from django.http import HttpResponseRedirect
16
11
from django.core.urlresolvers import reverse
17
12
 
18
 
from registration.backends.default import DefaultBackend
19
 
 
20
13
def register(request):
21
14
    """
22
15
    Overwritten view from registration to include a captcha.
25
18
    """
26
19
    remote_ip = request.META['REMOTE_ADDR']
27
20
    if request.method == 'POST':
28
 
        form = RegistrationWithCaptchaForm(remote_ip,data=request.POST,
29
 
                            files=request.FILES)
 
21
        form = RegistrationWithCaptchaForm(remote_ip,data=request.POST, files=request.FILES)
30
22
        if form.is_valid():
31
 
            new_user = DefaultBackend().register(request, **form.cleaned_data)
 
23
            new_user = form.save()
32
24
            return HttpResponseRedirect(reverse('registration_complete'))
33
25
    else:
34
26
        form = RegistrationWithCaptchaForm(remote_ip)
35
 
 
 
27
    
36
28
    context = RequestContext(request)
37
29
    return render_to_response("registration/registration_form.html",
38
30
                              { 'registration_form': form },
39
31
                              context_instance=context)
40
32
 
41
 
def developers(request):
42
 
    """
43
 
    This reads out the authors file in the SVN directory, and returns it
44
 
    as a wl_markdown_object. This replaces the wiki developers list
45
 
    """
46
 
    data = open(WIDELANDS_SVN_DIR + "txts/developers", "r").readlines()[4:]
47
 
    newdata = []
48
 
    for line in data:
49
 
        line = line.strip('"_ \n\r').rstrip('" _ \n\r')
50
 
        newdata.append(line)
51
 
 
52
 
    txt = ''.join(newdata)
53
 
    txt,_ = re.subn(r'<\/?rt.*?>', "", txt)
54
 
    txt,_ = re.subn(r'<br.*?>', "", txt)
55
 
    b = { "24": "\n\n## ",
56
 
          "18": "\n\n### ",
57
 
          "14": "\n\n#### ",
58
 
          "12": "- ",
59
 
        }
60
 
    e = { "24": "\n\n",
61
 
          "18": "\n",
62
 
          "14": "\n",
63
 
          "12": "\n",
64
 
        }
65
 
    txt,_ = re.subn(r'<p * font-size=(\d+).*?>(.*?)</p>',
66
 
            lambda m: "%s%s%s" %
67
 
                    (b[m.group(1)], m.group(2), e[m.group(1)]), txt)
68
 
    txt,_ = re.subn(r'<p.*?>(.*?)</p>',
69
 
            lambda m: ("- %s\n" % m.group(1) if len(m.group(1).strip()) else "")
70
 
                    , txt)
71
 
 
72
 
    txt = do_wl_markdown(txt.decode('utf-8'),custom=False)
73
 
 
74
 
 
75
 
    return render_to_response("mainpage/developers.html",
76
 
                              {"developers": txt},
77
 
                              context_instance=RequestContext(request)
78
 
    )
79
 
 
80
 
 
81
33
 
82
34
def changelog(request):
83
35
    """
84
 
    This reads out the changelog in the SVN directory, and returns it
 
36
    This reads out the changelog in the SVN directory, and returns it 
85
37
    as a wl_markdown_object. This replaces the wiki changelog
86
38
    """
87
39
    data = open(WIDELANDS_SVN_DIR + "ChangeLog", "r").read()
88
 
    return render_to_response("mainpage/changelog.html",
89
 
                              {"changelog": data},
90
 
                              context_instance=RequestContext(request)
 
40
    return render_to_response("mainpage/changelog.html", 
 
41
                              {"changelog": data}, 
 
42
                              context_instance=RequestContext(request) 
91
43
    )
92
44