Commit 58129222fd0a63b5810f3b987d248bfcf06406bc

  • avatar
  • Arvind <arvinkhadri @gm…l.com>
  • Mon Jun 24 19:28:01 IST 2013
Adding features
  - Alipi authenticates a user with sweet store
	- Alipi blog points to sweet store from a config variable
	- Adding a dependent module sweetmaker.py, ideally this should be pip installed.
  
1717import requests
1818from flask import jsonify
1919import json
20from flask import url_for
2021
21
2222app = Flask(__name__)
2323@app.before_request
2424def first():
2525 g.connection = pymongo.MongoClient('localhost',27017) #Create the object once and use it.
2626 g.db = g.connection[conf.MONGODB[0]]
27
28# @app.after_request
29# def set_secret(response):
30# response.set_cookie("key", conf.SWEET_SECRET_KEY[0])
31
32
2733@app.teardown_request
2834def close(exception):
2935 g.connection.disconnect()
36
37
3038@app.route('/')
3139def start_page() :
3240 d = {}
6969 i[0].attrib['href'] = '{0}?foruri={1}'.format(conf.DEPLOYURL[0],quote_plus(i[0].attrib['href'].encode('utf-8')))
7070 setScripts()
7171 g.root.body.set("onload","a11ypi.loadOverlay();")
72 return lxml.html.tostring(g.root)
72 response = make_response()
73 response.set_cookie("key", conf.SWEET_SECRET_KEY[0])
74 response.data = lxml.html.tostring(g.root)
75 return response
7376
7477 elif request.args.has_key('lang') == True and request.args.has_key('interactive') == True and request.args.has_key('blog') == False:
7578 setScripts()
7679 setSocialScript()
7780 g.root.body.set("onload","a11ypi.ren();a11ypi.tweet(); a11ypi.facebook(); a11ypi.loadOverlay();")
7881 g.root.make_links_absolute(d['foruri'], resolve_base_href = True)
79 return lxml.html.tostring(g.root)
82 response = make_response()
83 response.set_cookie("key", conf.SWEET_SECRET_KEY[0])
84 response.data = lxml.html.tostring(g.root)
85 return response
8086
87
8188 elif request.args.has_key('lang') == True and request.args.has_key('blog') == False:
8289 script_jq_mini = g.root.makeelement('script')
8390 g.root.body.append(script_jq_mini)
9696 script_test.set("src", conf.APPURL[0] + "/alipi/ui.js")
9797 script_test.set("type", "text/javascript")
9898 g.root.body.set("onload","a11ypi.ren()");
99 return lxml.html.tostring(g.root)
99 response = make_response()
100 response.set_cookie("key", conf.SWEET_SECRET_KEY[0])
101 response.data = lxml.html.tostring(g.root)
102 return response
100103
104
101105 elif request.args.has_key('interactive') == True and request.args.has_key('blog') == True and request.args.has_key('lang') == True:
102106 setScripts()
103107 setSocialScript()
104108 g.root.body.set("onload","a11ypi.filter(); a11ypi.tweet(); a11ypi.facebook(); a11ypi.loadOverlay();");
105109 g.root.make_links_absolute(d['foruri'], resolve_base_href = True)
106 return lxml.html.tostring(g.root)
110 response = make_response()
111 response.set_cookie("key", conf.SWEET_SECRET_KEY[0])
112 response.data = lxml.html.tostring(g.root)
113 return response
107114
108115 elif request.args.has_key('interactive') == False and request.args.has_key('blog') == True:
109116 setScripts()
110117 g.root.make_links_absolute(d['foruri'], resolve_base_href = True)
111118 g.root.body.set('onload', 'a11ypi.loadOverlay();')
112 return lxml.html.tostring(g.root)
119 response = make_response()
120 response.set_cookie("key", conf.SWEET_SECRET_KEY[0])
121 response.data = lxml.html.tostring(g.root)
122 return response
113123
124
114125def setScripts():
115126 script_test = g.root.makeelement('script')
116127 script_edit = g.root.makeelement('script')
128 script_auth = g.root.makeelement('script')
129 script_cookie_reader = g.root.makeelement('script')
117130 g.root.body.append(script_test)
118131 g.root.body.append(script_edit)
132 g.root.body.append(script_auth)
133 g.root.body.append(script_cookie_reader)
119134 script_test.set("src", conf.APPURL[0] + "/alipi/ui.js")
120135 script_test.set("type", "text/javascript")
121136 script_edit.set("src", conf.APPURL[0] + "/alipi/wsgi/pageEditor.js")
139139 g.root.body.append(script_config)
140140 script_config.set("src", conf.APPURL[0] + "/alipi/config.js")
141141 script_config.set("type", "text/javascript")
142 script_auth.set("src", conf.SWEETURL[0] + "/authenticate")
143 script_auth.set("type","text/javascript")
144 script_cookie_reader.set("src", url_for("static", filename="cookieReader.js"))
145 script_cookie_reader.set("type","text/javascript")
142146
143
144147 script_jq_mini = g.root.makeelement('script')
145148 g.root.body.append(script_jq_mini)
146149 script_jq_mini.set("src", conf.JQUERYURL[0] + "/jquery.min.js")
407407 """ A function to sweet the data that is inserted. Accepts a <list of dicts>. """
408408 for i in data:
409409 del(i['_id'])
410 sweet = sweetmaker.make(i['type'], i['author'], i['about']+i['xpath'], i['data'])
411 sweetmaker.send(sweet)
410 sweetmaker.sweet(conf.SWEET_STORE_ADD[0], i['type'], i['author'], i['about']+i['xpath'], i['data'])
412411 return True
413412 # data = json.dumps(data)
414413 # req = requests.api.post(conf.SWEETURL[0]+"/add",{'data':data})
476476 response = jsonify(d)
477477 response.headers['Access-Control-Allow-Origin'] = '*'
478478 return response
479
480@app.route('/secret')
481def serve_secret():
482 return jsonify({"key":conf.SWEET_SECRET_KEY[0]})
479483
480484
481485import logging,os
  
55#edit-current { font-size:17px; font-weight:400; font-style:italic; text-align:justify; display:none; }
66#see-narration { font-size:17px; font-weight:400; font-style:italic; text-align:justify; display:none; }
77#see-links { font-size:17px; font-weight:400; font-style:italic; text-align:justify; display:none; }
8#blog-filter { right:-3px; min-width:225px; max-width:225px; font-size:17px; font-weight:400; font-style:italic;
9 -moz-border-radius-bottomright:0px; -webkit-border-bottom-right-radius:0px; border-bottom-right-radius:0px;
10 -moz-border-radius-topright:0px; -webkit-border-top-right-radius:0px; border-top-right-radius:0px; -moz-margin-start:7px;
8#blog-filter { right:-3px; min-width:225px; max-width:225px; font-size:17px; font-weight:400; font-style:italic;
9 -moz-border-radius-bottomright:0px; -webkit-border-bottom-right-radius:0px; border-bottom-right-radius:0px;
10 -moz-border-radius-topright:0px; -webkit-border-top-right-radius:0px; border-top-right-radius:0px; -moz-margin-start:7px;
1111 text-align:center; display:none; }
1212@-moz-document domain(127.0.0.1), domain(dev.a11y.in), domain(y.a11y.in) {
1313 #go { top:11px !important; }
1414}
1515#go { top:6px; height:25px; text-align:justify; display:none;
16 -moz-border-radius-bottomleft:0px; -webkit-border-bottom-left-radius:0px; border-bottom-left-radius:0px;
16 -moz-border-radius-bottomleft:0px; -webkit-border-bottom-left-radius:0px; border-bottom-left-radius:0px;
1717 -moz-border-radius-topleft:0px; -webkit-border-top-left-radius:0px; -khtml-border-top-left-radius:0px; border-top-left-radius:0px; }
1818
1919#share { font-size:17px; font-weight:400; font-style:italic; text-align:justify; display:none; }
3131#exit-mode { font-size:17px; font-weight:400; font-style:italic; text-align:justify; }
3232#help-window { font-size:17px; font-weight:400; font-style:italic; text-align:justify; }
3333#undo-button { font-size:17px; font-weight:400; font-style:italic; text-align:justify; }
34#publish-button { font-size:17px; font-weight:400; font-style:italic; text-align:justify; }
34#publish-button { font-size:17px; font-weight:400; font-style:italic; text-align:justify; }
3535
36#element_edit_overlay { position:fixed; text-align:center; z-index:2147483645; display:none; }
36#element_edit_overlay { position:fixed; text-align:center; z-index:2147483645; display:none; }
3737
3838#edit-text { font-size:17px; font-weight:400; font-style:italic; text-align:justify; display:none; }
3939#add-audio { font-size:17px; font-weight:400; font-style:italic; text-align:justify; display:none; }
4545#editoroverlay { min-width:90%; text-align:justify; display: none; }
4646#editoroverlay a { color:#1C94C4; }
4747
48#adv-reference { position: absolute; top:15%; left:2%; min-width:48%; max-width:48%; border:solid 3px; padding:10px; font-size:16px;
48#adv-reference { position: absolute; top:15%; left:2%; min-width:48%; max-width:48%; border:solid 3px; padding:10px; font-size:16px;
4949 font-weight:400; font-style:normal; color:#aaa; overflow:show; background:none; text-align:justify; display:none; }
5050
51#reference { position: absolute; top: 15%; left:2%; min-width:46%; max-width:46%; min-height:10%; border:solid 3px; padding:10px; font-size:17px;
51#reference { position: absolute; top: 15%; left:2%; min-width:46%; max-width:46%; min-height:10%; border:solid 3px; padding:10px; font-size:17px;
5252 font-weight:400; font-style:normal; text-align:justify; color:#aaa; overflow:show; background:none; text-align:justify; }
5353
5454#editor { position:absolute; top:15%; left:52%; min-width:45%; max-width:45%; min-height:10%; border:3px solid #aaa; padding:10px; font-size:17px;
7979#tar-lab4 { position:absolute; top:50%; left:125px; font-size:17px; font-weight:400; font-style:italic; color:#aaa; text-align:justify; }
8080#tar-lab5 { position:absolute; top:65%; left:125px; font-size:17px; font-weight:400; font-style:italic; color:#aaa; text-align:justify; }
8181#tar-lab6 { position:relative; font-size:17px; font-weight:400; font-style:italic; color:#aaa; text-align:justify; }
82#tar-pass { position:absolute; top:77%; left:210px; width:256px; font-size:17px; font-weight:400; font-style:italic; color:#000; text-align:justify; }
8283#tar-lab7 { position:relative; font-size:17px; font-weight:400; font-style:italic; color:#aaa; text-align:justify; }
83#tar-p { position:absolute; top:90%; left:210px; font-size:17px; font-weight:400; font-style:italic; text-align:justify; }
84#blogset { position:absolute; top:80%; right:100px; left:125px; font-size:17px; font-weight:400; font-style:italic; color:#aaa; text-align:justify; }
84#tar-p { position:absolute; top:95%; left:210px; font-size:17px; font-weight:400; font-style:italic; text-align:justify; }
85#blogset { position:absolute; top:85%; right:100px; left:125px; font-size:17px; font-weight:400; font-style:italic; color:#aaa; text-align:justify; }
8586
8687
8788#loc-select { position:absolute; top:25%; left:210px; width:256px; font-size:17px; font-weight:400; font-style:italic; color:#000; text-align:justify; }
88#loc-img { position:absolute; top:25.5%; left:440px; height:20px; width:25px; font-size:17px; font-weight:400; font-style:italic;
89#loc-img { position:absolute; top:25.5%; left:440px; height:20px; width:25px; font-size:17px; font-weight:400; font-style:italic;
8990 color:#000; text-align:justify; display:none; }
9091#lang-select { position:absolute; top:40%; left:210px; width:256px; font-size:17px; font-weight:400; font-style:italic; color:#000; text-align:justify; }
91#lang-img { position:absolute; top:41%; left:440px; height:18px; width:25px; font-size:17px; font-weight:400; font-style:italic;
92#lang-img { position:absolute; top:41%; left:440px; height:18px; width:25px; font-size:17px; font-weight:400; font-style:italic;
9293 color:#000; text-align:justify; display:none; }
9394#style-select { position:absolute; top:55%; left:210px; width:256px; font-size:17px; font-weight:400; font-style:italic; color:#000; text-align:justify; }
9495#auth-select { position:absolute; top:70%; left:210px; width:256px; font-size:17px; font-weight:400; font-style:italic; color:#000; text-align:justify; }
109109#see-narration { font-size:14px; font-weight:200; font-style:italic; text-align:justify; display:none; }
110110#see-links { font-size:14px; font-weight:200; font-style:italic; text-align:justify; display:none; }
111111#blog-filter { right:-3px; min-width:150px; max-width:150px; font-weight:200; font-style:italic; text-align:justify; display:none;
112 -moz-border-radius-bottomright:0px; -webkit-border-bottom-right-radius:0px; border-bottom-right-radius:0px;
112 -moz-border-radius-bottomright:0px; -webkit-border-bottom-right-radius:0px; border-bottom-right-radius:0px;
113113 -moz-border-radius-topright:0px; -webkit-border-top-right-radius:0px; border-top-right-radius:0px; }
114#go { top:5px; height:18px; -moz-border-radius-bottomleft:0px; -webkit-border-bottom-left-radius:0px; -khtml-border-bottom-left-radius:0px;
115 border-bottom-left-radius:0px; -moz-border-radius-topleft:0px; -webkit-border-top-left-radius:0px; -khtml-border-top-left-radius:0px;
114#go { top:5px; height:18px; -moz-border-radius-bottomleft:0px; -webkit-border-bottom-left-radius:0px; -khtml-border-bottom-left-radius:0px;
115 border-bottom-left-radius:0px; -moz-border-radius-topleft:0px; -webkit-border-top-left-radius:0px; -khtml-border-top-left-radius:0px;
116116 border-top-left-radius:0px; font-size:14px; font-weight:200; font-style:italic; text-align:justify; display:none; }
117117@-moz-document domain(127.0.0.1), domain(dev.a11y.in), domain(y.a11y.in) {
118118 #go { height:23px !important; top:4px !important; }
125125#outter-up-button { font-size:14px; font-weight:200; font-style:italic; text-align:justify; display:none; }
126126
127127
128#pub_overlay { position:fixed; left:3%; width:96%; text-align:center; z-index:2147483645; font-size:14px; font-weight:200; font-style:italic;
128#pub_overlay { position:fixed; left:3%; width:96%; text-align:center; z-index:2147483645; font-size:14px; font-weight:200; font-style:italic;
129129 display:none; }
130130#pub_overlay .ui-button { margin-left:10px; }
131131#icon-down { font-size:14px; font-weight:200; font-style:italic; text-align:justify; display:none; }
133133#exit-mode { font-size:14px; font-weight:200; font-style:italic; text-align:justify; }
134134#help-window { font-size:14px; font-weight:200; font-style:italic; text-align:justify; }
135135#undo-button { font-size:14px; font-weight:200; font-style:italic; text-align:justify; }
136#publish-button { font-size:14px; font-weight:200; font-style:italic; text-align:justify; }
136#publish-button { font-size:14px; font-weight:200; font-style:italic; text-align:justify; }
137137
138#element_edit_overlay { position:fixed; text-align:center; z-index:2147483645; font-size:14px; font-weight:200; font-style:italic;
138#element_edit_overlay { position:fixed; text-align:center; z-index:2147483645; font-size:14px; font-weight:200; font-style:italic;
139139 text-align:justify; display:none; }
140140#element_edit_overlay .ui-button { text-align:justify; font-size:14px; font-weight:200; font-style:italic; }
141141
154154#reference { position: absolute; top: 24%; left:2%; min-width:46%; max-width:46%; min-height:10%; border:solid 2px; padding:10px; font-size:14px;
155155 text-align:justify; color:#aaa; font-weight:normal; overflow:show; background:none; }
156156
157#editor { position:absolute; top:15%; left:52%; min-width:45%; max-width:45%; min-height:10%; border:2px solid; padding:10px; color:#000;
157#editor { position:absolute; top:15%; left:52%; min-width:45%; max-width:45%; min-height:10%; border:2px solid; padding:10px; color:#000;
158158 background-color:#ffe; font-size:14px; font-weight:200; font-style:normal; text-align:justify; }
159159
160160#ref-lab { position:absolute; top:5%; font-size:14px; font-weight:200; font-style:italic; text-align:justify; color:#aaa; }
187187#blogset { position:absolute; top:80%; left:125px; right:80px; color:#aaa; font-size:14px; font-weight:200; font-style:italic; text-align:justify; }
188188
189189#loc-select { position:absolute; top:25%; left:210px; width:256px; color:#000; font-size:14px; font-weight:200; font-style:italic; text-align:justify; }
190#loc-img { position:absolute; top:25.5%; left:440px; height:20px; width:25px; color:#000; font-size:14px; font-weight:200; font-style:italic;
190#loc-img { position:absolute; top:25.5%; left:440px; height:20px; width:25px; color:#000; font-size:14px; font-weight:200; font-style:italic;
191191 text-align:justify; display:none; }
192192#lang-select { position:absolute; top:40%; left:210px; width:256px; color:#000; font-size:14px; font-weight:200; font-style:italic; text-align:justify; }
193#lang-img { position:absolute; top:41%; left:440px; height:18px; width:25px; color:#000; font-size:14px; font-weight:200; font-style:italic;
193#lang-img { position:absolute; top:41%; left:440px; height:18px; width:25px; color:#000; font-size:14px; font-weight:200; font-style:italic;
194194 text-align:justify; display:none; }
195195#style-select { position:absolute; top:55%; left:210px; width:256px; color:#000; font-size:14px; font-weight:200; font-style:italic; text-align:justify; }
196196#auth-select { position:absolute; top:70%; left:210px; width:256px; color:#000; font-size:14px; font-weight:200; font-style:italic; text-align:justify; }
210210#narrations-div { position:fixed; top:5%; bottom:2%; right:0.1%; width:30%; height:93%; overflow:show; background-color: rgba(0,0,0,0.5);
211211 z-index:999999999; }
212212/*TOOLTIPS*/
213.tip { color: #fff; width: 140px; background-color: rgba(0,0,0,1); border:1px solid #ccc; -moz-box-shadow:#555 2px 2px 8px;
213.tip { color: #fff; width: 140px; background-color: rgba(0,0,0,1); border:1px solid #ccc; -moz-box-shadow:#555 2px 2px 8px;
214214 -webkit-box-shadow:#555 2px 2px 8px; -o-box-shadow:#555 2px 2px 8px; box-shadow:#555 2px 2px 8px; opacity:1; font-size:12px;
215215 font-family:Verdana, Geneva, Arial, Helvetica, sans-serif; padding:7px; }
  
11import requests
22import json
3import conf
4def make(what, who, where, how):
3
4def sweet(sweet_url, what, who, where, how):
55 sweet = {}
66 sweet['what'] = what
77 sweet['who'] = who
88 sweet['where'] = where
99 sweet['how'] = how
10 print sweet
1110 sweet_list = []
1211 sweet_list.append(sweet)
13 return sweet_list
14
15
16def send(sweet):
17 request = requests.api.post(conf.SWEET_STORE_ADD[0],{'data':json.dumps(sweet)})
12 request = requests.api.post(sweet_url, {'data':json.dumps(sweet_list)})
1813 if request.status_code == 200:
1914 return True
2015 else:
alipi/ui.js
(14 / 5)
  
7272 $("#go").show();
7373 });
7474
75 req = {"about":decodeURIComponent(a['foruri']), "lang":a['lang']};
75 if(a['lang'])
76 {req = {"about":decodeURIComponent(a['foruri']), "lang":a['lang']};
7677 $.getJSON(config.deploy+'/info?', req, function(data)
7778 {
7879 a11ypi.responseJSON = data;
7980 });
81 }
8082 }
8183 },
8284 ajax1: function() {
116116 ren: function()
117117 {
118118 a = a11ypi.getParams();
119 var url = decodeURIComponent(a['foruri']);
119 var url = a['foruri'];
120 // var url = decodeURIComponent(a['foruri']);
120121 var type;
121122 if(a['type'])
122123 type = a['type'];
554554 '<option>Correction</option><option>Evolution</option><option>Other</option></select>'+
555555 '<label id="tar-lab5" class="alipi" >Enter an author name for your contribution: </label> '+
556556 '<input id="auth-select" class="alipi" type="text" placeholder="John" /> '+
557 '<div id="blogset" > You can choose to post this in your own blog or in the default Alipi blog</div> '+
557 '<input id="tar-pass" class="alipi" type="password" placeholder="password"/>'+
558 '<div id="blogset" > We are having issues with posting to a personal Google blog. Please use demo.swtr.us to publish.</div> '+
558559 '<p id="tar-p" ><input id="our-check" class="alipi" type="radio"name="blog" /> '+
559 '<label id="tar-lab6" class="alipi" > Alipi Blog</label><input id="your-check" class="alipi" type="radio" name="blog" /> '+
560 '<label id="tar-lab6" class="alipi" > demo.swtr.us </label><input id="your-check" class="alipi" type="radio" name="blog" /> '+
560561 '<label id="tar-lab7" class="alipi">Personal Blog</label></p></div>';
561562
562563 $('body').append(publish_template);
581581 buttons: {
582582 Publish: function() {
583583 util.publish();
584 },
585 Authenticate: function() {
586 var reply = sweet.authenticate($("#auth-select").val(), $("#tar-pass").val());
587 if(reply === true)
588 alert("authenticated");
584589 }
585590 },
586591 close: function() {
10151015 getParams: function()
10161016 {
10171017 var a = [];
1018 if(window.location.hostname == config.hostname)
1018 if(window.location.hostname == config.hostname || "localhost" )
10191019 {
10201020 d = window.location.search.split('?')[1];
10211021 for (var i = 0;i<d.split('&').length;i++){
  
449449 dict['lang'] = $('#lang-select').val();
450450 dict["location"] = $('#loc-select').val();
451451 dict["style"] = $('#style-select').val();
452 dict["blog"] = "blog";
452 dict["blog"] = config.sweet;
453453 dict["elementtype"] = command.elementType;
454454 dict["xpath"] = command.xpath;
455455 dict["data"] = command.data;