def post(self, user, account, **kwargs): app_id = (kwargs['app_id'] if 'app_id' in kwargs else 'new') body_json = self.request.body body = json.loads(body_json) if 'name' not in body: logging.exception(exception) self.response.set_status(400) self.response.write('Invalid JSON data') # return BadRequest("Invalid JSON data") if app_id == 'new': app = App(name=body['name'], created_by=account.key(), editors=[account.key()]) else: app = App.get_by_id(int(app_id)) if app is None: return render_json_response(self, {'error': 'app-not-found'}) if account.key() not in app.editors: return render_json_response(self, {'error': 'access-denied'}) app.name = body['name'] app.body = db.Text(body_json.decode('utf-8')) app.put() return render_json_response(self, {'id': app.key().id()})
def delete(self, user, account, **kwargs): app_id = kwargs['app_id'] app = App.get_by_id(int(app_id)) if app is None: return render_json_response(self, {'error': 'app-not-found'}) if account.key() not in app.editors: return render_json_response(self, {'error': 'access-denied'}) app.delete() return render_json_response(self, {'status': 'ok'})
def delete(self, user, account, **kwargs): app_id = kwargs["app_id"] app = App.get_by_id(int(app_id)) if app is None: return render_json_response(self, {"error": "app-not-found"}) if account.key() not in app.editors: return render_json_response(self, {"error": "access-denied"}) app.delete() return render_json_response(self, {"status": "ok"})
def post(self, user, account, **kwargs): app_id = kwargs["app_id"] if "app_id" in kwargs else "new" body_json = self.request.body body = json.loads(body_json) if "name" not in body: logging.exception(exception) self.response.set_status(400) self.response.write("Invalid JSON data") # return BadRequest("Invalid JSON data") if app_id == "new": app = App(name=body["name"], created_by=account.key(), editors=[account.key()]) else: app = App.get_by_id(int(app_id)) if app is None: return render_json_response(self, {"error": "app-not-found"}) if account.key() not in app.editors: return render_json_response(self, {"error": "access-denied"}) app.name = body["name"] app.body = db.Text(body_json.decode("utf-8")) app.put() return render_json_response(self, {"id": app.key().id()})
def get(self, app_id): # user = users.get_current_user() # if user is None: # return render_json_response(self, { 'error': 'signed-out' }) # else: # account = Account.all().filter('user', user).get() # if account is None: # account = Account(user=user) # account.put() app = App.get_by_id(int(app_id)) if app is None: return render_json_response(self, {'error': 'app-not-found'}) # if account.key() not in app.editors: # return render_json_response(self, { 'error': 'access-denied' }) body_json = app.body content = json.loads(body_json) body = "\n".join([s['html'] for s in content['screens']]) body = body.replace('"static', '"/static') body = body.replace('"images', '"/images') html = """ <!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="apple-mobile-web-app-status-bar-style" content="default" /> <link charset='utf-8' href='/static/iphone/iphone.css' media='screen' rel='stylesheet' title='no title' type='text/css' /> <script charset='utf-8' src='/static/lib/jquery.js' type='text/javascript'></script> <style> .c-background { display: none; }</style> <script> jQuery(function($) { $('.c-background:first').show(); $('.has-action').click(function() { var action = $(this).attr('action'); var m; if (m = action.match(/^screen:(.*)$/)) { var screenId = "screen-" + m[1]; console.log("Jumping to #" + screenId); $('.c-background').hide(); $('#' + screenId).show(); } }); }); </script> <title> %(title)s </title> </head> <body class="run"> %(content)s </body> </html> """ % dict(title=content['name'], content=body) # return Response(html, content_type="text/html") self.response.headers['Content-Type'] = 'text/html' self.response.write(html)
def get(self, app_id): # user = users.get_current_user() # if user is None: # return render_json_response(self, { 'error': 'signed-out' }) # else: # account = Account.all().filter('user', user).get() # if account is None: # account = Account(user=user) # account.put() app = App.get_by_id(int(app_id)) if app is None: return render_json_response(self, {"error": "app-not-found"}) # if account.key() not in app.editors: # return render_json_response(self, { 'error': 'access-denied' }) body_json = app.body content = json.loads(body_json) body = "\n".join([s["html"] for s in content["screens"]]) body = body.replace('"static', '"/static') body = body.replace('"images', '"/images') html = """ <!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="apple-mobile-web-app-status-bar-style" content="default" /> <link charset='utf-8' href='/static/iphone/iphone.css' media='screen' rel='stylesheet' title='no title' type='text/css' /> <script charset='utf-8' src='/static/lib/jquery.js' type='text/javascript'></script> <style> .c-background { display: none; }</style> <script> jQuery(function($) { $('.c-background:first').show(); $('.has-action').click(function() { var action = $(this).attr('action'); var m; if (m = action.match(/^screen:(.*)$/)) { var screenId = "screen-" + m[1]; console.log("Jumping to #" + screenId); $('.c-background').hide(); $('#' + screenId).show(); } }); }); </script> <title> %(title)s </title> </head> <body class="run"> %(content)s </body> </html> """ % dict( title=content["name"], content=body ) # return Response(html, content_type="text/html") self.response.headers["Content-Type"] = "text/html" self.response.write(html)