From 32dd8b4e33b27d786b51e1dc749124c5fbaf59e3 Mon Sep 17 00:00:00 2001 From: Arvind Date: Thu, 19 Jul 2012 08:42:51 +0530 Subject: [PATCH] Feeds are now read and made as comment/renarration, adding 'type' field to db, moved /menu to Flask --- server/alipi.py | 118 +++++++++++++++++++++-------- server/templates/feeds.html | 25 ++++-- server/ui.js | 176 ++++++++++++++++++++++++++----------------- 3 files changed, 213 insertions(+), 106 deletions(-) diff --git a/server/alipi.py b/server/alipi.py index 3314478..d042a67 100755 --- a/server/alipi.py +++ b/server/alipi.py @@ -2,6 +2,7 @@ from flask import Flask, request, render_template, g, redirect, jsonify, make_response from bson import Code from urllib import quote_plus, unquote_plus +from lxml.html import html5parser import urllib2, StringIO, lxml.html, pymongo, conf, oursql app = Flask(__name__) @app.before_request @@ -49,8 +50,11 @@ def start_page() : elif request.args.has_key('lang') == True and request.args.has_key('interactive') == True and request.args.has_key('blog') == False: setScripts() - setSocialScript() - g.root.body.set("onload","a11ypi.ren();a11ypi.tweet(); a11ypi.facebook(); a11ypi.loadOverlay();") + if request.args['interactive'] == '1': + setSocialScript() + g.root.body.set("onload","a11ypi.ren();a11ypi.tweet(); a11ypi.facebook(); a11ypi.loadOverlay();") + else: + g.root.body.set("onload","a11ypi.ren();") g.root.make_links_absolute(d['foruri'], resolve_base_href = True) return lxml.html.tostring(g.root) @@ -237,37 +241,46 @@ def replace(): collection = g.db['post'] lang = request.args['lang'] url = request.args['url'] - query = collection.group( - key = Code('function(doc){return {"xpath" : doc.xpath, "about": doc.url}}'), - condition={"about" : url, "lang" : lang,"elementtype":"text"}, - initial={'narration': []}, - reduce=Code('function(doc,out){out.narration.push(doc);}') - ) + if request.args['type'] == 'renarration': + query = collection.group( + key = Code('function(doc){return {"xpath" : doc.xpath, "about": doc.url}}'), + condition={"about" : url, "lang" : lang,"elementtype":"text","type":"renarration"}, + initial={'narration': []}, + reduce=Code('function(doc,out){out.narration.push(doc);}') + ) - audio_query =collection.group( - key = Code('function(doc){return {"xpath" : doc.xpath, "about": doc.url}}'), - condition={"about" : url, "lang" : lang, 'elementtype':"audio/ogg"}, - initial={'narration': []}, - reduce=Code('function(doc,out){out.narration.push(doc);}') - ) + audio_query =collection.group( + key = Code('function(doc){return {"xpath" : doc.xpath, "about": doc.url}}'), + condition={"about" : url, "lang" : lang, 'elementtype':"audio/ogg","type":"renarration"}, + initial={'narration': []}, + reduce=Code('function(doc,out){out.narration.push(doc);}') + ) - image_query =collection.group( - key = Code('function(doc){return {"xpath" : doc.xpath, "about": doc.url}}'), - condition={"about" : url, "lang" : lang, 'elementtype':"image"}, - initial={'narration': []}, - reduce=Code('function(doc,out){out.narration.push(doc);}') - ) - try: - for i in audio_query: - query.append(i) - except IndexError: - pass - try: - for i in image_query: - query.append(i) - except IndexError: - pass + image_query =collection.group( + key = Code('function(doc){return {"xpath" : doc.xpath, "about": doc.url}}'), + condition={"about" : url, "lang" : lang, 'elementtype':"image", "type":"renarration"}, + initial={'narration': []}, + reduce=Code('function(doc,out){out.narration.push(doc);}') + ) + try: + for i in audio_query: + query.append(i) + except IndexError: + pass + try: + for i in image_query: + query.append(i) + except IndexError: + pass + elif request.args['type'] == 'comment': + query = [] + query = collection.group( + key = Code('function(doc){return {"xpath" : doc.xpath, "about": doc.url}}'), + condition={"about" : url, "lang" : lang,"type":"comment"}, + initial={'narration': []}, + reduce=Code('function(doc,out){out.narration.push(doc);}') + ) for i in query: for y in i['narration']: del(y['_id']) @@ -304,12 +317,57 @@ def save_feed(): d['bxpath'] = request.form['bxpath'] d['xpath'] = request.form['xpath'] d['author'] = request.form['author'] + d['type'] = request.form['type'] + d['lang'] = request.form['lang'] + d['location'] = request.form['location'] coll.insert(d) + if d['type'] == 'comment': + collection = g.db['post'] + root = html5parser.parse(d['blog']).getroot() + tree = root.getroottree() + if tree.docinfo.doctype == '': + lxml.html.xhtml_to_html(root) + d['data'] = lxml.html.tostring(root.xpath(d['bxpath'])[0]) #TODO implement a function like lxml.html.make_links_absolute + collection.insert(d) response = make_response() response.data = repr(request.form['blog']) response.headers['Access-Control-Allow-Origin'] = '*' return response +@app.route("/menu",methods=['GET']) +def menuForDialog(): + if request.args.has_key('option') == False: + collection = g.db['post'] + c = {} + cntr = 0 + for i in collection.find({"about":request.args['url']}).distinct('lang'): + for j in collection.find({"about":request.args['url'],'lang':i}).distinct('type'): + d = {} + d['lang'] = i + d['type'] = j + c[cntr] = d + cntr += 1 + return jsonify(c) + else: + collection = g.db['post'] + #get the ren languages for the received url + langForUrl = collection.group( + key = Code('function(doc){return {"about" : doc.about}}'), + condition={"about" : d['url'],"blog":{'$regex':'/'+d['option']+'.*/'}}, + initial={'lang': []}, + reduce=Code('function(doc, out){if (out.lang.indexOf(doc.lang) == -1) out.lang.push(doc.lang)}') #here xpath for test + ) + + #send the response + if (langForUrl): + connection.disconnect() + return json.dumps(langForUrl[0]['lang']) + + else: + connection.disconnect() + return "empty" + + import logging,os from logging import FileHandler diff --git a/server/templates/feeds.html b/server/templates/feeds.html index 9ae7a03..31a47cb 100644 --- a/server/templates/feeds.html +++ b/server/templates/feeds.html @@ -18,24 +18,33 @@ - @ says is related to + @ says has at in targetting
diff --git a/server/ui.js b/server/ui.js index 8c2671f..d4d1d7e 100644 --- a/server/ui.js +++ b/server/ui.js @@ -1,3 +1,4 @@ +//-*-coding: utf-8 -*- var a11ypi = { auth : " ", loc:" ", @@ -33,18 +34,25 @@ var a11ypi = { } }, - createMenu: function(menu_list) { - var xyz = document.getElementById("show-box"); + createMenu: function(type) { + var xyz = ''; + if(type == 'renarration') + xyz = document.getElementById("show-box"); + else + xyz = document.getElementById("show-comment"); xyz.innerHTML = ''; a = a11ypi.getParams(); - for(var i=0;i'; + $(result).before(audio); result.setAttribute('class','blink'); } - else - $(result).hide(); - } - else if(elementType == 'audio/ogg') - { - newContent = decodeURIComponent(newContent); - audio = ''; - $(result).before(audio); - result.setAttribute('class','blink'); + else{ + result.innerHTML = a['data']; + result.setAttribute('class','blink'); + } + result=nodes.iterateNext(); } - else{ - result.innerHTML = newContent; - result.setAttribute('class','blink'); - } - result=nodes.iterateNext(); } - } catch (e) { // dump( 'error: Document tree modified during iteration ' + e ); } + } + else if(a['type']=='comment') + { + + try{ + var result = nodes.iterateNext(); + while (result) + { + result.innerHTML = a['data']; + result=nodes.iterateNext(); + } + } + catch (e) + { + //dump( 'error: Document tree modified during iteration ' + e ); + } + } }, filter: function() { @@ -285,11 +299,14 @@ var a11ypi = { ' '+ ''+ + ''+ ''+ ''+ ''+ '
'+ + '
'+ ' '+ '
'; @@ -328,6 +345,7 @@ var a11ypi = { $("#outter-up-button").button({icons:{primary:"ui-icon-circle-arrow-s"},text:false}); $('#outter-up-button').children().addClass('alipi'); $("#edit-current").button({icons:{primary:"ui-icon-pencil"}}); $('#edit-current').children().addClass('alipi'); $("#see-narration").button({icons:{primary:"ui-icon-document-b"}}); $('#see-narration').children().addClass('alipi'); + $("#see-comment").button({icons:{primary:"ui-icon-document-b"}}); $('#see-comment').children().addClass('alipi'); $("#see-links").button({icons:{primary:"ui-icon-link"}}); $('#see-links').children().addClass('alipi'); /*$("#blog-filter").button({icons:{secondary:"ui-icon-triangle-1-s"}}); */ $('#blog-filter').children().addClass('alipi'); $("#go").button({icons:{primary:"ui-icon-arrowthick-1-e"},text:false}); $('#go').children().addClass('alipi'); @@ -555,8 +573,14 @@ var a11ypi = { }); } }, + + hideAll: function() { + var boxes = '#show-links, #show-box, #show-comment'; + $(boxes).dialog('close'); + }, showBox: function() { + this.hideAll(); $(document).unbind('mouseover'); // Unbind the css on mouseover $(document).unbind('mouseout'); // Unbind the css on mouseout @@ -570,18 +594,32 @@ var a11ypi = { }); }); d = window.location.search.split('?')[1]; - var a =[]; - for (var i = 0;i