Commit 8a803caf3e1cff330c8342fb95a5cbc7a741ce31

  • avatar
  • admin
  • Wed Oct 05 21:04:35 IST 2011
Adding filter capabilites to backend
  
1111def start_page() :
1212 d = {}
1313 d['foruri'] = request.args['foruri']
14 myhandler = urllib2.ProxyHandler({'http':'http://proxy.iiit.ac.in:8080/'})
15 opener = urllib2.build_opener(myhandler)
16 urllib2.install_opener(opener)
17 a = urllib2.urlopen(d['foruri'])
14 myhandler1 = urllib2.Request(d['foruri'],headers={'User-Agent':"Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11"}) #A fix to send user-agents, so that sites render properly.
15 a = urllib2.urlopen(myhandler1)
1816 page = a.read()
1917 a.close()
2018 root = lxml.html.parse(StringIO.StringIO(page)).getroot()
21 if request.args.has_key('lang') == False:
19 if request.args.has_key('lang') == False and request.args.has_key('blog') == False:
2220 root.make_links_absolute(d['foruri'], resolve_base_href = True)
2321 script_test = root.makeelement('script')
2422 root[0].append(script_test)
25 script_test.set("src", "http://x.a11y.in/alipi/ajay/alipi/test.js")
23 script_test.set("src", "http://dev.a11y.in/alipi/ui.js")
2624 script_test.set("type", "text/javascript")
2725
2826 script_jq_mini = root.makeelement('script')
3232 root[0].append(style)
3333 style.set("rel","stylesheet")
3434 style.set("type", "text/css")
35 style.set("href", "http://x.a11y.in/alipi/ajay/alipi/stylesheet.css")
35 style.set("href", "http://dev.a11y.in/alipi/stylesheet.css")
3636
3737 connection = pymongo.Connection('localhost',27017)
3838 db = connection['alipi']
7575 btn.set("value", "EDIT")
7676 return lxml.html.tostring(root)
7777
78 else:
78 elif request.args.has_key('lang') == True and request.args.has_key('blog') == False:
7979 d['lang'] = request.args['lang']
8080 script_test = root.makeelement('script')
8181 root[0].append(script_test)
82 script_test.set("src", "http://x.a11y.in/alipi/ajay/alipi/test.js")
82 script_test.set("src", "http://dev.a11y.in/alipi/ui.js")
8383 script_test.set("type", "text/javascript")
8484 root.body.set("onload","a11ypi.ren()");
85 # connection = pymongo.Connection('localhost',27017)
86 # db = connection['alipi']
87 # collection = db['post']
88 # query = collection.group(
89 # key = Code('function(doc){return {"xpath" : doc.xpath, "url": doc.url}}'),
90 # condition={"url" : request.args['foruri'], "lang" : request.args['lang']},
91 # initial={'narration': []},
92 # reduce=Code('function(doc,out){out.narration.push(doc);}')
93 # )
94 # if len(query)==0:
95 # return 'empty'
96 # else:
97 # for key in query:
98 # post = key['narration'][len(key['narration'])-1] #for now, we only take the first re-narations, after we'll pick regarding filters.
99
100 # el = root.xpath('.//*[' + post['xpath'].split('/',2)[2].split('[',1)[1].lower())
101 # el[0].text = post['data']
85 root.make_links_absolute(d['foruri'], resolve_base_href = True)
86 return lxml.html.tostring(root)
10287
88 elif request.args.has_key('interactive') == True and request.args.has_key('blog') == True:
89 script_test = root.makeelement('script')
90 root[0].append(script_test)
91 script_test.set("src", "http://dev.a11y.in/alipi/ui.js")
92 script_test.set("type", "text/javascript")
93 root.body.set("onload","a11ypi.filter()");
10394 root.make_links_absolute(d['foruri'], resolve_base_href = True)
10495 return lxml.html.tostring(root)
10596
97 elif request.args.has_key('interactive') == False and request.args.has_key('blog') == True:
98 script_test = root.makeelement('script')
99 root[0].append(script_test)
100 script_test.set("src", "http://dev.a11y.in/alipi/ui.js")
101 script_test.set("type", "text/javascript")
102
103 script_jq_mini = root.makeelement('script')
104 root[0].append(script_jq_mini)
105 script_jq_mini.set("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js")
106 script_jq_mini.set("type", "text/javascript")
107
108 style = root.makeelement('link')
109 root[0].append(style)
110 style.set("rel","stylesheet")
111 style.set("type", "text/css")
112 style.set("href", "http://dev.a11y.in/alipi/stylesheet.css")
113
114 connection = pymongo.Connection('localhost',27017)
115 db = connection['alipi']
116 collection = db['post']
117 if collection.find_one({"url" : request.args['foruri']}) is not None:
118 ren_overlay = root.makeelement('div')
119 root[0].append(ren_overlay)
120 ren_overlay.set("id", "ren_overlay")
121 ren_overlay.text = "Narration(s) available"
122
123 close = root.makeelement('input')
124 ren_overlay.append(close)
125 close.set("id", "close-button")
126 close.set("type", "submit")
127 close.set("onClick", "a11ypi.close();")
128 close.set("value", "Close")
129
130 overlay1 = root.makeelement('div')
131 root[0].append(overlay1)
132 overlay1.set("id", "overlay1")
133
134 opt = root.makeelement('option')
135 opt.text = "Choose a narration"
136
137 rpl = root.makeelement('select')
138 overlay1.append(rpl)
139 rpl.append(opt)
140 rpl.set("id", "menu-button")
141 rpl.set("onclick", "a11ypi.ajax1();")
142
143 overlay2 = root.makeelement('div')
144 root[0].append(overlay2)
145 overlay2.set("id", "overlay2")
146
147 btn = root.makeelement('input')
148 overlay2.append(btn)
149 btn.set("id", "edit-button")
150 btn.set("type", "submit")
151 btn.set("onClick", "a11ypi.testContext();")
152 btn.set("value", "EDIT")
153 # script_test1 = root.makeelement('script')
154 # root[0].append(script_test1)
155 # script_test1.set("src", "http://192.168.100.56:82/server/ui.js")
156 # script_test1.set("type", "text/javascript")
157 # root.body.set("onload","a11ypi.filter()");
158 root.make_links_absolute(d['foruri'], resolve_base_href = True)
159 return lxml.html.tostring(root)
160
106161import logging
107162from logging import FileHandler
108163
109fil = FileHandler('/var/www/ajay/alipi/logme',mode='a')
164fil = FileHandler('/var/www/dev/alipi/logme',mode='a')
110165fil.setLevel(logging.ERROR)
111166app.logger.addHandler(fil)
112167
server/ui.js
(122 / 21)
  
1616 var a = content.document.createElement("script");
1717 for (j=0; j<v.length; j++) {
1818 c = v[0].appendChild(a);
19 c.setAttribute("src","http://x.a11y.in/alipi/ajay/alipi/wsgi/page_edit.js");
19 c.setAttribute("src","http://dev.a11y.in/alipi/wsgi/page_edit.js");
2020
2121 c.setAttribute("type","text/javascript");
2222 }
5858 }
5959 }
6060 }
61 xhr.open("POST","http://x.a11y.in/alipi/menu",true);
61 xhr.open("POST","http://dev.a11y.in/menu",true);
6262 xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
63 xhr.send(String(window.location.search.split('=')[1]));
63 d = window.location.search.split('?')[1];
64 var a =[];
65 for (var i = 0;i<d.split('&').length;i++){
66 a[d.split('&')[i].split('=')[0]] = d.split('&')[i].split('=')[1];
67 }
68 var url = a['foruri'];
69 xhr.send('url='+url);
6470 }
6571 },
72 ajax1: function() {
73 if(a11ypi.flag == '0')
74 {
75 a11ypi.flag = 1;
76 var xhr = new XMLHttpRequest();
77 xhr.onreadystatechange = function()
78 {
79 if(xhr.readyState == 4)
80 {
81 if(xhr.responseText == "empty")
82 {
83 a11ypi.clearMenu();
84 }
85 else
86 {
87 a11ypi.createMenuFilter(JSON.parse(xhr.responseText));
88 }
89 }
90 }
91 xhr.open("POST","http://dev.a11y.in/menu",true);
92 xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
93 d = window.location.search.split('?')[1];
94 var a =[];
95 for (var i = 0;i<d.split('&').length;i++){
96 a[d.split('&')[i].split('=')[0]] = d.split('&')[i].split('=')[1];
97 }
98 var url = a['foruri'];
99 var option = a['blog'];
100 data = 'url='+url+'&option='+option;
101 xhr.send(data) ;
102 }
103 },
104
66105 getURL: function(e) {
67106 window.location = window.location.href + "&lang=" + e.value;
68107 window.reload();
139139 }
140140 }
141141 }
142 var url = window.location.search.split('?')[1].split('=')[1].split('&')[0];
143 var lang= window.location.search.split('&')[1].split('=')[1];
142 d = window.location.search.split('?')[1];
143 var a =[];
144 for (var i = 0;i<d.split('&').length;i++){
145 a[d.split('&')[i].split('=')[0]] = d.split('&')[i].split('=')[1];
146 }
147 var url = a['foruri'];
148 var lang= a['lang'];
144149 var data="url="+encodeURIComponent(url)+"&lang="+encodeURIComponent(lang);
145150
146 xhr.open("POST","http://x.a11y.in/alipi/replace",true);
151 xhr.open("POST","http://dev.a11y.in/replace",true);
147152 xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
148153 xhr.send(data);//
149154 },
150155 evaluate: function()
151156 {
152 var nodes = content.document.evaluate(path, content.document, null, XPathResult.ANY_TYPE,null);
153
157 path = path.slice(0, path.lastIndexOf('SPAN')-1); //A hack to fix xpath after adding span. This must be corrected from the server side. #TODO
158 var nodes = document.evaluate(path, document, null, XPathResult.ANY_TYPE,null);
154159 try{
155160
156161 var result = nodes.iterateNext();
157
158162 while (result)
159163
160164 {
196196 close: function() {
197197 document.getElementById('ren_overlay').style.display = 'none';
198198 },
199
200 };
201
202 $(document).ready(function ($) {
203 $("a").click(function () {
204 var a = $(this),
205 href = a.attr('href'),
206 content = a.parent().next();
207 // content.load(href + " #content");
208 return false;
209 });
210});
199 filter: function()
200 {
201 var xhr = new XMLHttpRequest();
202 xhr.onreadystatechange = function()
203 {
204 if(xhr.readyState == 4)
205 {
206 if(xhr.responseText =='empty')
207 {
208 a11ypi.clearMenu();
209 alert("An internal server error occured, please try later.");
210 }
211 else
212 {
213
214 d ={};
215 var response=xhr.responseText.substring(3).split('###');
216 for (var j= 0; j< response.length ; j++){
217 chunk = response[j].substring(1).split('&');
218
219 for (var i= 0; i< chunk.length ; i++){
220 pair =chunk[i].split("::");
221 key = pair[0];
222 value = pair[1];
223 d[key] = value;
224 }
225 path = d['xpath'];
226 newContent = d['data'];
227 a11ypi.evaluate(path,newContent);
228 }
229 }
230 }
231 }
232 d = window.location.search.split('?')[1];
233 var a =[];
234 for (var i = 0;i<d.split('&').length;i++){
235 a[d.split('&')[i].split('=')[0]] = d.split('&')[i].split('=')[1];
236 }
237 var url = a['foruri'];
238 var lang= a['lang'];
239 var blog= a['blog'];
240 var data="url="+encodeURIComponent(url)+"&lang="+encodeURIComponent(lang)+"&blog="+encodeURIComponent(blog);
241
242 xhr.open("POST","http://dev.a11y.in/filter",true);
243 xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
244 xhr.send(data);//
245 },
246 createMenuFilter: function(menu_list) {
247 var xyz = document.getElementById("menu-button");
248 for(var i in menu_list)
249 {
250 var newel = document.createElement("option");
251 newel.textContent = menu_list[i];
252 newel.setAttribute("value",menu_list[i]);
253 newel.setAttribute("onclick","a11ypi.getURLFilter(event.target);");
254 xyz.appendChild(newel);
255 }
256 },
257 clearMenuFilter: function() {
258 var xyz = document.getElementById("menu-button");
259 while(null!= xyz.firstChild)
260 {
261 xyz.removeChild(xyz.firstChild);
262 }
263 },
264 getURLFilter: function(e) {
265 window.location = window.location.href + "&lang=" + e.value+"&interactive=1";
266 window.reload();
267 },
268};