Merge lp:~franku/widelands-website/developers_list into lp:widelands-website

Proposed by kaputtnik
Status: Merged
Merged at revision: 391
Proposed branch: lp:~franku/widelands-website/developers_list
Merge into: lp:widelands-website
Diff against target: 104 lines (+56/-29)
1 file modified
mainpage/views.py (+56/-29)
To merge this branch: bzr merge lp:~franku/widelands-website/developers_list
Reviewer Review Type Date Requested Status
SirVer Approve
Review via email: mp+259041@code.launchpad.net

Description of the change

To post a comment you must log in.
Revision history for this message
kaputtnik (franku) wrote :

Oh sorry, this branch has to be merged only together with https://code.launchpad.net/~widelands-dev/widelands/authors (if it is ready :-D )

391. By kaputtnik

added exceptions

Revision history for this message
SirVer (sirver) wrote :

Looks good, gonna merge.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'mainpage/views.py'
2--- mainpage/views.py 2015-03-15 20:23:34 +0000
3+++ mainpage/views.py 2015-05-19 07:15:17 +0000
4@@ -5,6 +5,9 @@
5
6 import sys
7 import re
8+import json
9+import os
10+import os.path
11
12 def mainpage(request):
13 return render_to_response('mainpage.html',
14@@ -39,37 +42,61 @@
15
16 def developers(request):
17 """
18- This reads out the authors file in the SVN directory, and returns it
19+ This reads out some json files in the SVN directory, and returns it
20 as a wl_markdown_object. This replaces the wiki developers list
21 """
22- data = open(WIDELANDS_SVN_DIR + "txts/developers", "r").readlines()[4:]
23- newdata = []
24- for line in data:
25- line = line.strip('"_ \n\r').rstrip('" _ \n\r')
26- newdata.append(line)
27-
28- txt = ''.join(newdata)
29- txt,_ = re.subn(r'<\/?rt.*?>', "", txt)
30- txt,_ = re.subn(r'<br.*?>', "", txt)
31- b = { "24": "\n\n## ",
32- "18": "\n\n### ",
33- "14": "\n\n#### ",
34- "12": "- ",
35- }
36- e = { "24": "\n\n",
37- "18": "\n",
38- "14": "\n",
39- "12": "\n",
40- }
41- txt,_ = re.subn(r'<p * font-size=(\d+).*?>(.*?)</p>',
42- lambda m: "%s%s%s" %
43- (b[m.group(1)], m.group(2), e[m.group(1)]), txt)
44- txt,_ = re.subn(r'<p.*?>(.*?)</p>',
45- lambda m: ("- %s\n" % m.group(1) if len(m.group(1).strip()) else "")
46- , txt)
47-
48- txt = do_wl_markdown(txt.decode('utf-8'),custom=False)
49-
50+
51+ # Get locale and translator names from each .json file and
52+ # store them in one list.
53+ txt = ""
54+ transl_files = []
55+ transl_list = []
56+ path = os.path.normpath(WIDELANDS_SVN_DIR + "txts/translators/")
57+ try:
58+ transl_files = os.listdir(path)
59+ if transl_files:
60+ for fname in transl_files:
61+ if fname.endswith(".json"):
62+ with open(path + "/" + fname,"r") as f:
63+ json_data = json.load(f)["locale-translators"]
64+
65+ if json_data["translator-list"] != "translator-credits":
66+ transl_list.append(json_data)
67+ else:
68+ txt = "No files for translators found!"
69+ except OSError:
70+ txt = txt + "Couldn't find translators directory!"
71+
72+
73+ # Get other developers, put in the translators list
74+ # at given position and prepaire all for wl_markdown
75+ try:
76+ f = open(WIDELANDS_SVN_DIR + "txts/developers.json", "r")
77+ json_data = json.load(f)["developers"]
78+ f.close()
79+
80+ for head in json_data:
81+ # Add first header
82+ txt = txt + "##" + head["heading"] + "\n"
83+ # Inserting Translators
84+ if head["heading"] == "Translators":
85+ for values in (transl_list):
86+ # Add subheader for locale
87+ txt = txt + "### " + values["your-language-name"] + "\n"
88+ # Prepaire the names for wl_markdown
89+ txt = txt + "* " + values["translator-list"].replace('\n', '\n* ') + "\n"
90+
91+ # Add a subheader or/and the member(s)
92+ for entry in head["entries"]:
93+ if "subheading" in entry.keys():
94+ txt = txt + "###" + entry["subheading"] + "\n"
95+ if "members" in entry.keys():
96+ for name in entry["members"]:
97+ txt = txt + "* " + name + "\n"
98+ except IOError:
99+ txt = txt + "Couldn't find developer file!"
100+
101+ txt = do_wl_markdown(txt,custom=False)
102
103 return render_to_response("mainpage/developers.html",
104 {"developers": txt},

Subscribers

People subscribed via source and target branches