~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to mainpage/views.py

  • Committer: Holger Rapp
  • Date: 2009-02-21 18:24:02 UTC
  • Revision ID: sirver@kallisto.local-20090221182402-k3tuf5c4gjwslbjf
Main Page contains now the same informations as before

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
8
 
import sys
9
 
import json
10
 
import os
11
 
import os.path
12
 
import locale
13
 
import codecs
14
 
 
 
1
from django.shortcuts import render_to_response
 
2
from django.template import RequestContext
15
3
 
16
4
def mainpage(request):
17
 
    return render(request, 'mainpage.html',)
18
 
 
19
 
 
20
 
def legal_notice(request):
21
 
    """The legal notice page to fullfill law."""
22
 
    if request.method == 'POST':
23
 
        form = ContactForm(request.POST)
24
 
        if form.is_valid():
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'],
30
 
                                 'Inquiry:',
31
 
                                 form.cleaned_data['inquiry']])
32
 
            sender = 'legal_note@widelands.org'
33
 
 
34
 
            # get email addresses which are in form of ('name','email'),
35
 
            recipients = []
36
 
            for recipient in INQUIRY_RECIPIENTS:
37
 
                recipients.append(recipient[1])
38
 
 
39
 
            send_mail(subject, message, sender,
40
 
                      recipients, fail_silently=False)
41
 
            # Redirect after POST
42
 
            return HttpResponseRedirect('/legal_notice_thanks/')
43
 
 
44
 
    else:
45
 
        form = ContactForm()  # An unbound form
46
 
 
47
 
    return render(request, 'mainpage/legal_notice.html', {
48
 
        'form': form,
49
 
        'inquiry_recipients': INQUIRY_RECIPIENTS,
50
 
    })
51
 
 
52
 
 
53
 
def legal_notice_thanks(request):
54
 
    return render(request, 'mainpage/legal_notice_thanks.html')
55
 
 
56
 
 
57
 
def developers(request):
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
66
 
    # store them in one list.
67
 
    txt = '[TOC]\n\n'
68
 
    transl_files = []
69
 
    transl_list = []
70
 
    path = os.path.normpath(WIDELANDS_SVN_DIR + 'data/i18n/locales/')
71
 
    try:
72
 
        transl_files = os.listdir(path)
73
 
        if transl_files:
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)
78
 
                    try:
79
 
                        if json_data['translator-list'] != 'translator-credits':
80
 
                            if not 'your-language-name-in-english' in json_data:
81
 
                                transl_list = ['KeyError']
82
 
                                break
83
 
                            transl_list.append(json_data)
84
 
                    except KeyError:
85
 
                        transl_list = ['KeyError']
86
 
                        break
87
 
 
88
 
            # No KeyError -> Sort the list
89
 
            if 'KeyError' in transl_list:
90
 
                txt = 'Some Translator key is wrong, please contact the Developers.\n'
91
 
            else:
92
 
                transl_list.sort(key=itemgetter(
93
 
                    'your-language-name-in-english'))
94
 
 
95
 
        else:
96
 
            txt = 'No files for translators found!\n'
97
 
    except OSError:
98
 
        txt = txt + "Couldn't find translators directory!\n"
99
 
 
100
 
    # Get other developers, put in the translators list
101
 
    # at given position and prepare all for wl_markdown
102
 
    try:
103
 
        with open(WIDELANDS_SVN_DIR + 'data/txts/developers.json', 'r') as f:
104
 
            json_data = json.load(f)['developers']
105
 
 
106
 
        for head in json_data:
107
 
            # Add first header
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
116
 
                    txt = txt + '* ' + \
117
 
                        values['translator-list'].replace('\n', '\n* ') + '\n'
118
 
 
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'
126
 
    except IOError:
127
 
        txt = txt + "Couldn't find developer file!"
128
 
 
129
 
    txt = do_wl_markdown(txt, beautify=False)
130
 
 
131
 
    return render(request, 'mainpage/developers.html',
132
 
                  {'developers': txt}
133
 
                  )
134
 
 
135
 
 
136
 
def changelog(request):
137
 
    """This reads out the changelog in the SVN directory, and returns it as a
138
 
    wl_markdown_object.
139
 
 
140
 
    This replaces the wiki changelog
141
 
 
142
 
    """
143
 
    data = codecs.open(WIDELANDS_SVN_DIR + 'ChangeLog', encoding='utf-8', mode='r').read()
144
 
    return render(request, 'mainpage/changelog.html',
145
 
                  {'changelog': data},
146
 
                  )
147
 
 
148
 
 
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)
152
 
 
153
 
 
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))
 
6