def get(self, user_key=None): ''' Send e-mail to user ordered a delivery and the admin ''' user = User.get(user_key) profile = Profile.all().filter('user ='******'already verified') context = { 'user': user, 'profile': profile, } body = render_template('mail/verify.html', **context) message = mail.EmailMessage() message.to = user.email message.body = body message.subject = SUBJECT_REGISTRATION message.sender = SENDER message.reply_to = REPLY_TO message.send() return Response(body)
def _proxy( self, allow, data=None ): api = self._getApiFromUrl() test = api.startswith( 'test/' ) if test: api = api.replace( 'test/', '', 1 ) debug = api.startswith( 'debug/' ) if debug: api = api.replace( 'debug/', '', 1 ) if not re.match( allow, api ): self.abort( 403 ) if test: response = Response( api ) response.headers['Content-Type'] = 'text/plain' return response result = EarthEngine( self ).post( api, data ) if debug: json = json_encode( result, indent=4 ) else: json = json_encode( result ) response = Response( json ) if debug: response.headers['Content-Type'] = 'text/plain' else: response.headers['Content-Type'] = 'application/json' return response
def receive(self, mail_message, **kwargs): for content_type, body in mail_message.bodies('text/plain'): decoded = body.decode() if decoded: return Response(decoded) return Response('')
def test_real_logout(self): user = User.create('foo', 'foo_id', auth_remember=True) with self.get_app().get_test_context() as request: store = MultiAuthStore(request) store.login_with_auth_id('foo_id', remember=False) response = Response() request.session_store.save(response) with self.get_app().get_test_context( '/', headers={ 'Cookie': '\n'.join(response.headers.getlist('Set-Cookie')), }) as request: store = MultiAuthStore(request) self.assertNotEqual(store.user, None) self.assertEqual(store.user.username, 'foo') store.logout() response = Response() request.session_store.save(response) with self.get_app().get_test_context( '/', headers={ 'Cookie': '\n'.join(response.headers.getlist('Set-Cookie')), }) as request: store = MultiAuthStore(request) self.assertEqual(store.session, None)
def get(self, **kwargs): invoice = db.get(kwargs['invoiceid']) if invoice: # self.response.headers['Content-Type'] = "image/jpeg" return Response(invoice.File) else: return Response("Image not available")
def get(self, app): stored_app = OdeskApplication.get_by_key_name(app) if not stored_app: r = Response( 'There is no app %s registered in oDesk Auth Proxy' % app) r.status_code = 404 return r client = odesk.Client(stored_app.public_key, stored_app.secret_key) return Response(client.auth.auth_url())
def get(self, **kwargs): job = JobModel.get(kwargs['jobid']) output = StringIO.StringIO() z = zipfile.ZipFile(output,'w') history = JobHistoryModel.all() history.filter("Job = ", job) items = "" for item in history: username = item.CreatedBy.username items += item.Created.strftime("%b %d %Y - %I:%M%P") + "," + username +","+ item.Description+"\r\n" historycsv = StringIO.StringIO(items) z.writestr("history.csv", historycsv.read().encode('utf-8')) historycsv.close() communication = CommunicationModel.all() communication.filter("Job = ", job) items = "" for item in communication: username = item.CreatedBy.username items += item.Created.strftime("%b %d %Y - %I:%M%P") + "," + username +","+ item.Text+"\r\n" commcsv = StringIO.StringIO(items) z.writestr("communication.csv", commcsv.read().encode('utf-8')) commcsv.close() artifacts = job.Artifacts items = "" for item in artifacts: file = blobstore.get(item) items += file.filename+"\r\n" filescsv = StringIO.StringIO(items) z.writestr("files.csv", filescsv.read().encode('utf-8')) filescsv.close() items = "" items += "name, " + job.Nickname + "\r\n" items += "description, " + job.Description + "\r\n" items += "created, " + job.Created.strftime("%b %d %Y - %I:%M%P") + "\r\n" items += "created by, " + job.CreatedBy.username + "\r\n" items += "client, " + job.Client.Name + "\r\n" if job.Quote: items += "quote, " + job.Quote + "\r\n" datacsv = StringIO.StringIO(items) z.writestr("data.csv", datacsv.read().encode('utf-8')) datacsv.close() z.close() response = Response(output.getvalue()) response.headers["Content-Type"] = "multipart/x-zip" response.headers['Content-Disposition'] = "attachment; filename=" + job.JobNumber +".zip" return response
def get(self,key): response = Response() response.headers['Content-Type'] = "image" response.headers['Content-Disposition'] = "attachment" try: manager = EventDelegate('Event') result = manager.getFile(key.split('.')[0],150) except Exception,e: result = self.wrapFault(e.message)
def get(self, tableId=None, rowId=None): client = fusion.Client(self) selection = client.query('SELECT geometry FROM ' + fusion.fixId(tableId) + ' WHERE rowid = ' + fusion.fixId(rowId)) row = selection and selection[0] kml = row and row['geometry'] response = Response(kml) response.headers[ 'Content-Type'] = 'text/plain' # 'application/vnd.google-earth.kml+xml' return response
def get( self, tableId=None, rowId=None ): client = fusion.Client( self ) selection = client.query( 'SELECT geometry FROM ' + fusion.fixId(tableId) + ' WHERE rowid = ' + fusion.fixId(rowId) ) row = selection and selection[0] kml = row and row['geometry'] response = Response( kml ) response.headers['Content-Type'] = 'text/plain' # 'application/vnd.google-earth.kml+xml' return response
def get(self): response = Response() cookie = self.session_store.get_secure_cookie('test') or {} res = cookie.get('test') if not res: res = 'undefined' self.session_store.set_secure_cookie(response, 'test', {'test': 'a secure cookie value'}) response.data = res return response
def get(self, app): frob = self.request.args.get('frob') if not frob: r = Response("Missed required param frob") r.status_code = 400 return r stored_app = OdeskApplication.get_by_key_name(app) if not stored_app: r = Response( 'There is no app %s registered in oDesk Auth Proxy' % app) r.status_code = 404 return r client = odesk.Client(stored_app.public_key, stored_app.secret_key) auth_token, user = client.auth.get_token(frob) return Response(auth_token)
def get(self): res = [msg for msg, level in self.session.get_flashes()] if not res: res = [{'body': 'undefined'}] self.session.flash({'body': 'a flash value'}) return Response(res[0]['body'])
def test_make_response(self): app = Tipfy() request = Request.from_values() # Empty. response = app.make_response(request) self.assertEqual(isinstance(response, app.response_class), True) self.assertEqual(response.status_code, 200) self.assertEqual(response.data, '') # From Response. response = app.make_response(request, Response('Hello, World!')) self.assertEqual(isinstance(response, app.response_class), True) self.assertEqual(response.status_code, 200) self.assertEqual(response.data, 'Hello, World!') # From string. response = app.make_response(request, 'Hello, World!') self.assertEqual(isinstance(response, app.response_class), True) self.assertEqual(response.status_code, 200) self.assertEqual(response.data, 'Hello, World!') # From tuple. response = app.make_response(request, 'Hello, World!', 404) self.assertEqual(isinstance(response, app.response_class), True) self.assertEqual(response.status_code, 404) self.assertEqual(response.data, 'Hello, World!') # From None. self.assertRaises(ValueError, app.make_response, request, None)
def handle_exception(self, handler): logging.exception(handler) code = handler.code if hasattr(handler, 'code') else 500 return Response(render_template("tipfy/ext/httpexceptions/templates/%s.html" % \ str(code if code in (404, 500) else 500), ** {'request': Tipfy.request}), status = code, mimetype = 'text/html')
def post(self, app): public = self.request.form.get('public') secret = self.request.form.get('secret') if not public and not secret: r = Response('Bad request: both public and secret is required') r.status_code = 400 return r stored_app = OdeskApplication.get_by_key_name(app) if not stored_app: stored_app = OdeskApplication(key_name=app) stored_app.created = datetime.datetime.utcnow() stored_app.public_key = public stored_app.secret_key = secret stored_app.updated = datetime.datetime.utcnow() stored_app.put() return Response('Ok')
def get(self): res = self.request.cookies.get('test') if not res: res = 'undefined' self.session_store.set_cookie('test', 'a cookie value') self.session_store.unset_cookie('test') return Response(res)
def get(self): session = self.session_store.get_session(backend='datastore') res = session.get('test') if not res: res = 'undefined' session['test'] = 'a datastore session value' return Response(res)
def _proxy(self, allow, data=None): api = self._getApiFromUrl() test = api.startswith('test/') if test: api = api.replace('test/', '', 1) debug = api.startswith('debug/') if debug: api = api.replace('debug/', '', 1) if not re.match(allow, api): self.abort(403) if test: response = Response(api) response.headers['Content-Type'] = 'text/plain' return response result = EarthEngine(self).post(api, data) if debug: json = json_encode(result, indent=4) else: json = json_encode(result) response = Response(json) if debug: response.headers['Content-Type'] = 'text/plain' else: response.headers['Content-Type'] = 'application/json' return response
def get(self, **kwargs): response = Response(mimetype = 'application/atom+xml') collection = FilterCollection(filters, request, response, cookies=False) q = models.accepted_quotes() collection.add_to_query(q) q.order('-creation_date') out = render_template( 'cppbash/atom.xml', title = "C++ Bash", link = url_for('home', full=True), quotes = q) response.response = [out] return response
def get(self): res = self.session.get('key') if not res: res = 'undefined' session = SecureCookieSession() session['key'] = 'a session value' self.session_store.set_session(self.session_store.config['cookie_name'], session) return Response(res)
def get(self): session = self.session_store.get_session(backend='datastore') res = session.get('key') if not res: res = 'undefined' session = DatastoreSession(None, 'a_random_session_id') session['key'] = 'a session value' self.session_store.set_session(self.session_store.config['cookie_name'], session, backend='datastore') return Response(res)
def get(self, **kwargs): json = request.is_xhr or request.args.get('json', '') response = Response(mimetype = 'application/json' if json else 'text/html') collection = FilterCollection(filters, request, response) q = models.accepted_quotes() collection.add_to_query(q) q.order('-creation_date') if json: out = quotejson.json(q) else: out = render_template( 'cppbash/home.html', quotes = q, filter_collection = collection) response.response = [out] return response
def post(self): logging.info(str(self.request.form)) mill = Mill( key_name=self.request.form['MILL_NO'], name=self.request.form['MILL_NAME'], location=db.GeoPt(float(self.request.form['Lat']), float(self.request.form['Long'])), ) mill.mill_no = int(self.request.form['MILL_NO']) mill.year = self.request.form['YEAR'] mill.update_location() mill.put() return Response()
def get(self, **kwargs): json = request.is_xhr or request.args.get('json', '') response = Response(mimetype = 'application/json' if json else 'text/html') collection = FilterCollection(filters, request, response) query = models.accepted_quotes() collection.add_to_query(query) query.filter('random >', random.random()) query.order('random') qs = [ q for q in query.fetch(_n) ] if len(qs) < _n: # wraparound! query = models.accepted_quotes() collection.add_to_query(query) query.order('random') qs.extend(query.fetch(_n - len(qs))) if len(qs) > 0: q = random.choice(qs) else: q = None if json: out = quotejson.single(q) else: out = render_template( 'cppbash/random_quote.html', quote = q, filter_collection = collection) response.response = [out] return response
def test_set_cookie_encoded(self): local.current_handler = handler = RequestHandler(self._get_app(), Request.from_values()) store = SessionStore(handler) store.set_cookie('foo', 'bar', format='json') store.set_cookie('baz', 'ding', format='json') response = Response() store.save(response) headers = {'Cookie': '\n'.join(response.headers.getlist('Set-Cookie'))} request = Request.from_values('/', headers=headers) self.assertEqual(json_b64decode(request.cookies.get('foo')), 'bar') self.assertEqual(json_b64decode(request.cookies.get('baz')), 'ding')
def get(self, resource=None, jobid=None): logging.log( logging.INFO, "asking for resource: " + resource + " for job id " + jobid) upload_url = blobstore.create_upload_url('/upload') artifacts = getArtifacts(jobid) response = { 'statusCode': 0, 'key': resource, 'uploadurl': upload_url, 'url': '/serve/%s' % resource, 'artifacts': artifacts } return Response( '<script type="text/javascript">window.top.window.stopUpload(%s);</script>' % simplejson.dumps(response))
def test_real_login_no_user(self): with self.get_app().get_test_context() as request: store = MultiAuthStore(request) user = store.create_user('foo', 'foo_id') store.login_with_auth_id('foo_id', remember=False) response = Response() request.session_store.save(response) user.delete() with self.get_app().get_test_context( '/', headers={ 'Cookie': '\n'.join(response.headers.getlist('Set-Cookie')), }) as request: store = MultiAuthStore(request) self.assertEqual(store.session['id'], 'foo_id') self.assertEqual(store.user, None)
def test_get_save_session(self): local.current_handler = handler = RequestHandler(self._get_app(), Request.from_values()) store = SessionStore(handler) session = store.get_session() self.assertEqual(isinstance(session, SecureCookieSession), True) self.assertEqual(session, {}) session['foo'] = 'bar' response = Response() store.save(response) request = Request.from_values('/', headers={'Cookie': '\n'.join(response.headers.getlist('Set-Cookie'))}) local.current_handler = handler = RequestHandler(self._get_app(), request) store = SessionStore(handler) session = store.get_session() self.assertEqual(isinstance(session, SecureCookieSession), True) self.assertEqual(session, {'foo': 'bar'})
def get(self): points = [] mills = Mill.all() for mill in mills: p = geojson.Point( [mill.location.lat, mill.location.lon], properties={ 'name': mill.name, 'link': self.url_for('mills/single', mill_no=mill.mill_no, slug=mill.slug) }) points.append(p) return Response( geojson.dumps(geojson.FeatureCollection(features=points))) return self.render_response('mills/markers.js', mills=mills)
def get(self, **kwargs): ''' Send e-mail to user ordered a delivery and the admin ''' user = self.auth_current_user # todo: use real user order = Order.get_orders_by_user(user) context = { 'order': order, 'username': user.username, 'format_currency': i18n.format_currency, } body = render_template('mail/order.html', **context) message = mail.EmailMessage() message.to = user.email message.body = body message.subject = SUBJECT_ORDER message.sender = SENDER message.reply_to = REPLY_TO message.send() return Response(body)
def test_set_delete_cookie(self): local.current_handler = handler = RequestHandler(self._get_app(), Request.from_values()) store = SessionStore(handler) store.set_cookie('foo', 'bar') store.set_cookie('baz', 'ding') response = Response() store.save(response) headers = {'Cookie': '\n'.join(response.headers.getlist('Set-Cookie'))} request = Request.from_values('/', headers=headers) self.assertEqual(request.cookies.get('foo'), 'bar') self.assertEqual(request.cookies.get('baz'), 'ding') store.delete_cookie('foo') store.save(response) headers = {'Cookie': '\n'.join(response.headers.getlist('Set-Cookie'))} request = Request.from_values('/', headers=headers) self.assertEqual(request.cookies.get('foo', None), '') self.assertEqual(request.cookies['baz'], 'ding')
def handle_exception(self, exception=None): response = Response('405 custom handler', status=405) response.headers['Allow'] = 'GET' return response
def handle_exception(self, exception=None): return Response('500 custom handler', status=500)
def get(self, **kwargs): return Response(self.request.json['foo'])
def handle_exception(self, exception=None): # Let's fix it. return Response('That was close!', status=200)
def get(self, **kwargs): return Response('Method: %s' % self.request.method)
def handle_exception(self, exception): return Response(res)
def get(self, **kwargs): return Response('default')
def get(self, group=None): #payload = {'success': True} #ggroups = queries.groups() #return render_response('ags4.html' , groups=ggroups, g=appGlobal, c={}) icons = {} icons['icoAgsClasses'] = 'shape_align_left.png' icons['icoAgsGroups'] = 'shape_move_back.png' icons['icoAgsHeadings'] = 'shape_ungroup.png' #icons['icoAgsClasses'] = '' icons['icoInvis'] = 'transparent.png'; icons['icoDashBoard'] = 'plugin.png'; icons['icoLanServer'] = 'server.png'; ##/* Widgets **************************************/ icons['icoAdd'] = 'add.png'; icons['icoEdit'] = 'page_white_edit.png'; icons['icoDelete'] = 'delete.png'; icons['icoMerge'] = 'shape_ungroup.png'; icons['icoHelp'] = 'help.png'; icons['icoHome'] = 'house.png'; icons['icoRefresh'] = 'arrow_refresh.png'; icons['icoRefresh2'] = 'refresh.gif'; #icons['icoGo'] = 'arrow_rotate_clockwise.png'; icons['icoSave'] = 'accept.png'; icons['icoCancel'] = 'bullet_black.png'; icons['icoClipboard'] = 'page_paste.png'; icons['icoGo'] = 'bullet_go.png'; icons['icoClose'] = 'cross.png'; #icons['icoMore'] = 'bullet_arrow_down.png'; icons['icoShowMore'] = 'zoom_in.png'; icons['icoShowLess'] = 'zoom_out.png'; icons['icoEmail'] = 'email.png'; icons['icoSms'] = 'phone.png'; icons['icoTel'] = 'telephone.png'; icons['icoFax'] = 'newspaper.png'; icons['icoMessage'] = 'text_signature.png'; icons['icoFreeText'] = 'textfield.png'; ##/* Widgets **************************************/ icons['icoBlack'] = 'bullet_black.png'; icons['icoBlue'] = 'bullet_blue.png'; icons['icoGreen'] = 'bullet_green.png'; icons['icoOrange'] = 'bullet_orange.png'; icons['icoPink'] = 'bullet_pink.png'; icons['icoPurlple'] = 'bullet_purple.png'; icons['icoRed'] = 'bullet_red.png'; icons['icoYellow'] = 'bullet_yellow.png'; icons['icoDetails'] = 'bullet_white.png'; icons['icoSearch'] = 'find.png'; ##/* Form **************************************/ icons['icoClean'] = 'bullet_black.png'; icons['icoDirty'] = 'bullet_red.png'; ##/* Wizzard **************************************/ icons['icoNext'] = 'arrow_right.png'; icons['icoPrev'] = 'arrow_left.png'; icons['icoWizard'] = 'wand.png'; icons['icoForward'] = 'arrow_right.png'; icons['icoBack'] = 'arrow_left.png'; icons['icoBrowse'] = 'browse.png'; ###/* Actions **************************************/ #//icons['icoUpload'] = 'arrow_up.png'; #//icons['icoDownload'] = 'arrow_down.png'; icons['icoUpload'] = 'page_white_get.png'; icons['icoDownload'] = 'page_white_put.png'; icons['icoQuit'] = 'control_eject.png'; icons['icoLogin'] = '******'; icons['icoContact'] = 'user.png'; icons['icoContactView'] = 'user.png'; icons['icoContactAdd'] = 'user_add.png'; icons['icoContactDelete'] = 'user_delete.png'; icons['icoContactEdit'] = 'user_edit.png'; icons['icoFile'] = 'geo_job.png'; icons['icoFileOpen'] = 'page_white_go.png'; icons['icoFileCopy'] = 'page_white_copy.png'; icons['icoFileRename'] = 'page_white_edit.png'; icons['icoFileDelete'] = 'page_white_delete.png'; #/* Samples */ #/* icons['icoSamples'] = 'package_green.png'; icons['icoSample'] = 'package.png'; icons['icoSampleAdd'] = 'package_add.png'; icons['icoSampleDelete'] = 'package_delete.png'; #*/ icons['icoSamples'] = 'tag_blue.png'; icons['icoSample'] = 'tag_green.png'; icons['icoSampleAdd'] = 'tag_blue_add.png'; icons['icoSampleDelete'] = 'tag_blue_delete.png'; ##/* Test */ icons['icoTest'] = 'chart_line.png'; icons['icoTestAdd'] = 'chart_line_add.png'; icons['icoTestEdit'] = 'chart_line_edit.png'; icons['icoTestDelete'] = 'chart_line_delete.png'; icons['icoReport'] = 'chart_curve.png'; icons['icoWeekView'] = 'calendar_view_week.png'; icons['icoOn'] = 'bullet_green.png'; icons['icoOff'] = 'bullet_black.png'; icons['icoFilterOn'] = 'bullet_pink.png'; icons['icoFilterOff'] = 'bullet_purple.png'; icons['icoStart'] = 'control_play_blue.png'; icons['icoEnd'] = 'control_stop_blue.png'; icons['icoError'] = 'exclamation.png'; icons['icoDiggs'] = 'database_table.png'; icons['icoSettings'] = 'plugin.png'; icons['icoShortcuts'] = 'arrow_inout.png'; icons['icoDev'] = 'wand.png'; icons['icoMerge'] = 'table_relationship.png'; icons['icoFolder'] = 'folder.png'; icons['icoFolderAdd'] = 'folder_add.png'; icons['icoRootTree'] = 'sitemap_color.png'; icons['icoUsers'] = 'group_gear.png'; #//** Just include this file OK #if(!defined('STOP_ME_SPOOLING_ICON')){ #$IconServerPath = file_exists('../LOCAL') # ? 'http://localhost/~test/famfamfam_silk_icons_v013/icons/' # : 'http://ico.daffodil.uk.com/' # # foreach($desktop_icons as $k => $v){ IconServerPath = 'http://ico.daffodil.uk.com' s = '' for k in sorted(icons.keys()): #s += "%s = %s\n" % (k, icons[k]) s += ".%s{background-image: url('%s/%s') !important;}\n" % (k, IconServerPath, icons[k]) s += "\n\n" # incase #response.headers['Content-Type'] = 'image/png' #response.headers['content-type'] = 'text/css' response = Response(s) response.headers['Content-Type'] = 'text/css' # Return a rendered template #return render('/style.mako') # or, return a response return response