Commit 20b3ab707e105206de150a5e4baec5a4715ecb6e
- Diff rendering mode:
- inline
- side by side
server/alipi.py
(95 / 10)
  | |||
34 | 34 | page = a.read() | |
35 | 35 | a.close() | |
36 | 36 | except ValueError: | |
37 | return "The link is malformed, click <a href='http://dev.a11y.in/web?foruri={0}&lang={1}&interactive=1'>here</a> to be redirected.".format(quote_plus(unquote_plus(d['foruri'])),request.args['lang']) | ||
37 | return "The link is malformed, click <a href='http://dev.a11y.in/web?foruri={0}&lang={1}&interactive=1'>here</a> to be redirected.".format(quote_plus(unquote_plus(d['foruri'].encode('utf-8'))),request.args['lang']) | ||
38 | 38 | except urllib2.URLError: | |
39 | 39 | return render_template('error.html') | |
40 | 40 | try: | |
41 | 41 | page = unicode(page,'utf-8') #Hack to fix improperly displayed chars on wikipedia. | |
42 | 42 | except UnicodeDecodeError: | |
43 | 43 | pass #Some pages may not need be utf-8'ed | |
44 | g.root = lxml.html.parse(StringIO.StringIO(page)).getroot() | ||
44 | try: | ||
45 | g.root = lxml.html.parse(StringIO.StringIO(page)).getroot() | ||
46 | except ValueError: | ||
47 | g.root = lxml.html.parse(d['foruri']).getroot() #Sometimes creators of the page lie about the encoding, thus leading to this execption. http://lxml.de/parsing.html#python-unicode-strings | ||
45 | 48 | if request.args.has_key('lang') == False and request.args.has_key('blog') == False: | |
46 | 49 | g.root.make_links_absolute(d['foruri'], resolve_base_href = True) | |
47 | 50 | for i in g.root.iterlinks(): | |
48 | 51 | if i[1] == 'href' and i[0].tag != 'link': | |
49 | i[0].attrib['href'] = 'http://{0}?foruri={1}'.format(conf.DEPLOYURL[0],quote_plus(i[0].attrib['href'])) | ||
52 | try: | ||
53 | i[0].attrib['href'] = 'http://{0}?foruri={1}'.format(conf.DEPLOYURL[0],quote_plus(i[0].attrib['href'])) | ||
54 | except KeyError: | ||
55 | i[0].attrib['href'] = '{0}?foruri={1}'.format(conf.DEPLOYURL[0],quote_plus(i[0].attrib['href'].encode('utf-8'))) | ||
50 | 56 | setScripts() | |
51 | 57 | g.root.body.set("onload","a11ypi.loadOverlay();") | |
52 | 58 | return lxml.html.tostring(g.root) | |
… | … | ||
61 | 61 | setScripts() | |
62 | 62 | setSocialScript() | |
63 | 63 | g.root.body.set("onload","a11ypi.ren();a11ypi.tweet(); a11ypi.facebook(); a11ypi.loadOverlay();") | |
64 | g.root.make_links_absolute(d['foruri'], resolve_base_href = True) | ||
64 | 65 | return lxml.html.tostring(g.root) | |
65 | 66 | ||
66 | 67 | elif request.args.has_key('lang') == True and request.args.has_key('blog') == False: | |
67 | script_jq_mini = root.makeelement('script') | ||
68 | root.body.append(script_jq_mini) | ||
68 | script_jq_mini = g.root.makeelement('script') | ||
69 | g.root.body.append(script_jq_mini) | ||
69 | 70 | script_jq_mini.set("src", conf.JQUERYURL[0] + "/jquery-1.7.min.js") | |
70 | 71 | script_jq_mini.set("type", "text/javascript") | |
71 | 72 | d['lang'] = request.args['lang'] | |
72 | script_test = root.makeelement('script') | ||
73 | root.body.append(script_test) | ||
73 | script_test = g.root.makeelement('script') | ||
74 | g.root.body.append(script_test) | ||
74 | 75 | script_test.set("src", conf.APPURL[0] + "/server/ui.js") | |
75 | 76 | script_test.set("type", "text/javascript") | |
76 | root.body.set("onload","a11ypi.ren()"); | ||
77 | root.make_links_absolute(d['foruri'], resolve_base_href = True) | ||
78 | return lxml.html.tostring(root) | ||
77 | g.root.body.set("onload","a11ypi.ren()"); | ||
78 | return lxml.html.tostring(g.root) | ||
79 | 79 | ||
80 | 80 | elif request.args.has_key('interactive') == True and request.args.has_key('blog') == True and request.args.has_key('lang') == True: | |
81 | 81 | setScripts() | |
… | … | ||
237 | 237 | response = jsonify(d) | |
238 | 238 | response.headers['Access-Control-Allow-Origin'] = '*' | |
239 | 239 | return response | |
240 | @app.route("/replace", methods=['GET']) | ||
241 | def replace(): | ||
242 | collection = g.db['post'] | ||
243 | lang = request.args['lang'] | ||
244 | url = request.args['url'] | ||
245 | query = collection.group( | ||
246 | key = Code('function(doc){return {"xpath" : doc.xpath, "about": doc.url}}'), | ||
247 | condition={"about" : url, "lang" : lang,"elementtype":"text"}, | ||
248 | initial={'narration': []}, | ||
249 | reduce=Code('function(doc,out){out.narration.push(doc);}') | ||
250 | ) | ||
251 | |||
252 | audio_query =collection.group( | ||
253 | key = Code('function(doc){return {"xpath" : doc.xpath, "about": doc.url}}'), | ||
254 | condition={"about" : url, "lang" : lang, 'elementtype':"audio/ogg"}, | ||
255 | initial={'narration': []}, | ||
256 | reduce=Code('function(doc,out){out.narration.push(doc);}') | ||
257 | ) | ||
258 | |||
259 | image_query =collection.group( | ||
260 | key = Code('function(doc){return {"xpath" : doc.xpath, "about": doc.url}}'), | ||
261 | condition={"about" : url, "lang" : lang, 'elementtype':"image"}, | ||
262 | initial={'narration': []}, | ||
263 | reduce=Code('function(doc,out){out.narration.push(doc);}') | ||
264 | ) | ||
265 | try: | ||
266 | for i in audio_query: | ||
267 | query.append(i) | ||
268 | except IndexError: | ||
269 | pass | ||
270 | try: | ||
271 | for i in image_query: | ||
272 | query.append(i) | ||
273 | except IndexError: | ||
274 | pass | ||
275 | |||
276 | for i in query: | ||
277 | for y in i['narration']: | ||
278 | del(y['_id']) | ||
279 | d = {} | ||
280 | d['r'] = query | ||
281 | response = jsonify(d) | ||
282 | response.headers['Access-Control-Allow-Origin'] = '*' | ||
283 | return response | ||
284 | |||
285 | # string='' | ||
286 | # if len(query)==0: | ||
287 | # print >> environ['wsgi.errors'], 'empty' | ||
288 | # return 'empty' | ||
289 | # else: | ||
290 | # for key in query: | ||
291 | # # print >> environ['wsgi.errors'], query | ||
292 | # post = key['narration'][len(key['narration'])-1] #Fetching the last done re-narration | ||
293 | |||
294 | # try: | ||
295 | # string+="###" | ||
296 | |||
297 | # for key in post: | ||
298 | # if type(post[key]) is not float: | ||
299 | # if key != '_id': | ||
300 | # try: | ||
301 | # if type(post[key]) is unicode: | ||
302 | # string+="&"+str(key)+"::"+ post[key].encode('utf-8') | ||
303 | # else: | ||
304 | # string+="&"+str(key)+"::"+ post[key] | ||
305 | # except TypeError: | ||
306 | # print >> environ['wsgi.errors'], key | ||
307 | # else: | ||
308 | # try: | ||
309 | # string+="&"+str(key)+"::"+ str(post[key]) | ||
310 | # except TypeError: | ||
311 | # print >> environ['wsgi.errors'], key | ||
312 | # except UnicodeEncodeError: | ||
313 | # print >> environ['wsgi.errors'], key | ||
314 | # print >> environ['wsgi.errors'], 'Error Encoding request string' | ||
315 | # return 'empty' | ||
316 | |||
317 | # return string | ||
318 | |||
240 | 319 | import logging,os | |
241 | 320 | from logging import FileHandler | |
242 | 321 |
server/ui.js
(26 / 47)
  | |||
131 | 131 | }, | |
132 | 132 | ren: function() | |
133 | 133 | { | |
134 | var xhr = new XMLHttpRequest(); | ||
135 | xhr.onreadystatechange = function() | ||
136 | { | ||
137 | if(xhr.readyState == 4) | ||
138 | { | ||
139 | if(xhr.responseText =='empty') | ||
140 | { | ||
141 | a11ypi.clearMenu(); | ||
142 | alert("An internal server error occured, please try later."); | ||
143 | } | ||
144 | else | ||
145 | { | ||
146 | var info_template = '<div id="infoDiv"></div>'; | ||
147 | $('#renarrated_overlay').append(info_template); | ||
148 | d ={}; | ||
149 | //a11ypi.response = xhr.responseText; | ||
150 | var response=xhr.responseText.substring(3).split('###'); | ||
151 | for (var j= 0; j< response.length ; j++){ | ||
152 | chunk = response[j].substring(1).split('&'); | ||
153 | |||
154 | for (var i= 0; i< chunk.length ; i++){ | ||
155 | pair =chunk[i].split("::"); | ||
156 | key = pair[0]; | ||
157 | value = pair[1]; | ||
158 | d[key] = value; | ||
159 | } | ||
160 | path = d['xpath']; | ||
161 | newContent = d['data']; | ||
162 | elementType = d['elementtype']; | ||
163 | a11ypi.evaluate(path,newContent,elementType); | ||
164 | } | ||
165 | } | ||
166 | } | ||
167 | } | ||
168 | 134 | ||
169 | 135 | d = window.location.search.split('?')[1]; | |
170 | 136 | var a =[]; | |
171 | 137 | for (var i = 0;i<d.split('&').length;i++){ | |
172 | 138 | a[d.split('&')[i].split('=')[0]] = d.split('&')[i].split('=')[1]; | |
173 | 139 | } | |
174 | var url = a['foruri']; | ||
140 | var url = decodeURIComponent(a['foruri']); | ||
175 | 141 | var lang = a['lang']; | |
176 | var data="url="+url+"&lang="+encodeURIComponent(lang); | ||
177 | xhr.open("POST","http://dev.a11y.in/replace",true); | ||
178 | xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); | ||
179 | xhr.send(data); | ||
142 | $.getJSON("http://dev.a11y.in/web/replace?",{"url":url,"lang":lang},function(data) | ||
143 | { | ||
144 | for(var i=0;i<data['r'].length;i++) | ||
145 | { | ||
146 | for(var x in data['r'][i]['narration']) | ||
147 | { | ||
148 | path = data['r'][i]['narration'][x]['xpath']; | ||
149 | newContent = data['r'][i]['narration'][x]['data']; | ||
150 | elementType = data['r'][i]['narration'][x]['elementtype']; | ||
151 | a11ypi.evaluate(path,newContent,elementType); | ||
152 | } | ||
153 | } | ||
154 | }); | ||
180 | 155 | }, | |
181 | 156 | evaluate: function() | |
182 | 157 | { | |
… | … | ||
263 | 263 | var para = document.createElement("p"); | |
264 | 264 | var newel = document.createElement("a"); | |
265 | 265 | newel.textContent = menu_list[i]; | |
266 | $(newel).attr("href","http://127.0.0.1:5000/?foruri="+page+"&blog="+blog+"&lang="+menu_list[i]+"&interactive=1"); | ||
266 | $(newel).attr("href","http://dev.a11y.in/web/?foruri="+page+"&blog="+blog+"&lang="+menu_list[i]+"&interactive=1"); | ||
267 | 267 | para.appendChild(newel); | |
268 | 268 | xyz.appendChild(para); | |
269 | 269 | } | |
… | … | ||
282 | 282 | a[d.split('&')[i].split('=')[0]] = d.split('&')[i].split('=')[1]; | |
283 | 283 | } | |
284 | 284 | ||
285 | window.location = "http://127.0.0.1:5000/?foruri="+a['foruri']+"&blog="+a['blog'] + "&lang=" + e.value+"&interactive=1"; | ||
285 | window.location = "http://dev.a11y.in/web/?foruri="+a['foruri']+"&blog="+a['blog'] + "&lang=" + e.value+"&interactive=1"; | ||
286 | 286 | window.reload(); | |
287 | 287 | }, | |
288 | 288 | showOriginal: function(){ | |
… | … | ||
487 | 487 | source: function(req, add){ | |
488 | 488 | ||
489 | 489 | //pass request to server | |
490 | $.getJSON("http://127.0.0.1:5000//getLoc?", req, function(data) { | ||
490 | $.getJSON("http://dev.a11y.in/web//getLoc?", req, function(data) { | ||
491 | 491 | $('#loc-img').hide(); | |
492 | 492 | ||
493 | 493 | //create array for response objects | |
… | … | ||
510 | 510 | source: function(req, add){ | |
511 | 511 | ||
512 | 512 | //pass request to server | |
513 | $.getJSON("http://127.0.0.1:5000//getLang?", req, function(data) { | ||
513 | $.getJSON("http://dev.a11y.in/web//getLang?", req, function(data) { | ||
514 | 514 | $('#lang-img').hide(); | |
515 | 515 | ||
516 | 516 | //create array for response objects | |
… | … | ||
666 | 666 | var para = document.createElement("p"); | |
667 | 667 | var newel = document.createElement("a"); | |
668 | 668 | newel.textContent = menu_list[i]; | |
669 | newel.setAttribute("href", "http://127.0.0.1:5000/?foruri="+encodeURIComponent(menu_list[i])); | ||
669 | newel.setAttribute("href", "http://dev.a11y.in/web/?foruri="+encodeURIComponent(menu_list[i])); | ||
670 | 670 | newel.setAttribute("class","alipiShowLink"); | |
671 | 671 | para.appendChild(newel); | |
672 | 672 | xyz.append(para); | |
… | … | ||
746 | 746 | if ($("#blog-filter").val() == null) | |
747 | 747 | { } | |
748 | 748 | else { | |
749 | window.open("http://127.0.0.1:5000/?foruri=" + a['foruri'] + "&blog=" + $("#blog-filter").val()); | ||
749 | window.open("http://dev.a11y.in/web/?foruri=" + a['foruri'] + "&blog=" + $("#blog-filter").val()); | ||
750 | 750 | } | |
751 | 751 | }, | |
752 | 752 | share: function() { | |
… | … | ||
766 | 766 | $('#icon-down').show(); | |
767 | 767 | // $('#element_edit_overlay').addClass('barOnTop'); | |
768 | 768 | $('#renarrated_overlay').hide(); | |
769 | |||
769 | // $(window).click(function(event){ | ||
770 | // console.log(event); | ||
771 | // event.stopPropagation(); | ||
772 | // event.preventDefault(); | ||
773 | // }); | ||
770 | 774 | $('body *').contents().filter(function(){ | |
771 | 775 | { | |
772 | 776 | try{ | |
… | … | ||
796 | 796 | } | |
797 | 797 | } | |
798 | 798 | }).click(pageEditor.noEdit); | |
799 | |||
799 | |||
800 | 800 | $(document).mouseover(a11ypi.highlightOnHover); | |
801 | 801 | $(document).mouseout(a11ypi.unhighlightOnMouseOut); | |
802 | 802 | }, |
wsgi/alipiUtils.py
(1 / 3)
  | |||
66 | 66 | temp['about'] = element.attrib['about'] | |
67 | 67 | temp['xpath'] = element.attrib['xpath'] | |
68 | 68 | data ='' | |
69 | # for i in element.iterdescendants(): | ||
70 | # data += etree.tostring(i) | ||
71 | 69 | ret = pat.search(lxml.html.tostring(element)) | |
72 | 70 | data = lxml.html.tostring(element).partition(ret.group())[2] | |
73 | 71 | data = data.rpartition('</p>')[0] | |
74 | temp['data'] = element.text_content() | ||
72 | temp['data'] = data | ||
75 | 73 | temp['blog'] = url | |
76 | 74 | temp['bxpath'] = makePath(element) | |
77 | 75 | temp['ren_id'] = ren_id |