class UploadHandler(RequestHandler, Jinja2Mixin, tipfy_blobstore.BlobstoreUploadMixin): middleware = [SessionMiddleware()] def post(self, id): """Upload a document.""" user = models.User.get_by_email(self.session.get('email')) if not user: return self.redirect('/') case = models.Case.get_by_id(id) upload_files = self.get_uploads('file') if upload_files: blob_info = upload_files[0] else: blob_info = None models.CaseAction.upload_document_action( case, self.request.form.get('purpose'), user, blob_info, self.request.form.get('notes')) response = self.redirect('/case/details/%s' % case.key().id()) response.data = '' return response
class CaseEmailsHandler(RequestHandler, Jinja2Mixin): middleware = [SessionMiddleware()] def get(self, id): """Show/change email settings for a case.""" user = models.User.get_by_email(self.session.get('email')) if not user: return self.redirect('/') case = models.Case.get_by_id(id) notifications = models.EmailNotification.query_by_case(case) notif_on = {} for a in models.NOTIFIABLE_ACTIONS: notif_on[a] = False for notif in notifications: if notif.email == user.email: notif_on[notif.action] = True logging.info('notif_on: %s', notif_on) context = { 'user': user, 'case': case, 'notif': notif_on, 'actions': models.NOTIFIABLE_ACTIONS, } context.update(config.config) return self.render_response('notifications.html', **context)
class CaseReviewHandler(RequestHandler, Jinja2Mixin): middleware = [SessionMiddleware()] def get(self, id): """Show details of a case and allow editing it.""" user = models.User.get_by_email(self.session.get('email')) if not user or not user.can_approve: return self.redirect('/') case = models.Case.get_by_id(id) case.review(user) actions = models.CaseAction.query_by_case(case) documents = models.CaseAction.query_by_case(case, 'Update') context = { 'user': user, 'case': case, 'actions': actions, 'documents': documents, 'uploadables': models.PURPOSES, 'upload_url': 'bogus', } context.update(config.config) return self.render_response('case.html', **context)
class AddActionHandler(RequestHandler, Jinja2Mixin): middleware = [SessionMiddleware()] def get(self): """Add a message about an action.""" juris = self.request.args.get('juris') msg = self.request.args.get('msg') models.LatropMessage.create(juris, msg) return 'OK'
class BaseHandler( RequestHandler, Jinja2Mixin ): middleware = [ SessionMiddleware() ] def redirect( self, url=None ): if url == None: url = '/' return super(BaseHandler,self).redirect( url ) def redirect_path( self, default='/' ): url = self.request.args.get( 'continue', '/' ) if url.startswith('/'): return default return url
class DownloadHandler(RequestHandler, Jinja2Mixin, tipfy_blobstore.BlobstoreDownloadMixin): middleware = [SessionMiddleware()] def get(self, key, filename): """Download a document.""" user = models.User.get_by_email(self.session.get('email')) if not user: return self.redirect('/') return self.send_blob(blobstore.BlobInfo.get(key))
class HomeHandler(RequestHandler, Jinja2Mixin): middleware = [SessionMiddleware()] def get(self): """Home Page, show latest 5 messages.""" latest = models.LatropMessage.get_all().fetch(5) logging.info('Latest: %r', latest) context = { 'latest': latest, } context.update(config.config) return self.render_response('home.html', **context)
class BaseHandler(RequestHandler, Jinja2Mixin): middleware = [SessionMiddleware(), UserRequiredIfAuthenticatedMiddleware()] @cached_property def messages(self): """A list of status messages to be displayed to the user.""" return self.session.get_flashes(key='_messages') def render_response(self, filename, **kwargs): auth_session = None if self.auth.session: auth_session = self.auth.session kwargs.update({ 'auth_session': auth_session, 'current_user': self.auth.user, 'login_url': self.auth.login_url(), 'logout_url': self.auth.logout_url(), 'current_url': self.request.url, }) if self.messages: kwargs['messages'] = json_encode([ dict(body=body, level=level) for body, level in self.messages ]) return super(BaseHandler, self).render_response(filename, **kwargs) def redirect_path(self, default='/'): if '_continue' in self.session: url = self.session.pop('_continue') else: url = self.request.args.get('continue', '/') if not url.startswith('/'): url = default return url def _on_auth_redirect(self): """Redirects after successful authentication using third party services. """ if '_continue' in self.session: url = self.session.pop('_continue') else: url = '/' if not self.auth.user: url = self.auth.signup_url() return self.redirect(url)
class CaseSubmitHandler(RequestHandler, Jinja2Mixin): middleware = [SessionMiddleware()] def post(self, id): """Submit a case for approval.""" user = models.User.get_by_email(self.session.get('email')) if not user: return self.redirect('/') notes = self.request.form.get('notes') case = models.Case.get_by_id(id) case.submit(user, notes) return self.redirect('/applicant/home')
class CaseCommentHandler(RequestHandler, Jinja2Mixin): middleware = [SessionMiddleware()] def post(self, id): """Comment on a case.""" user = models.User.get_by_email(self.session.get('email')) if not user or not user.can_approve: return self.redirect('/') notes = self.request.form.get('notes') case = models.Case.get_by_id(id) case.comment(user, notes) return self.redirect('/approver/home')
class CreateCaseHandler(RequestHandler, Jinja2Mixin): middleware = [SessionMiddleware()] def get(self): """Create a new case.""" user = models.User.get_by_email(self.session.get('email')) if not user: return self.redirect('/') # TODO: add a form! case = models.Case.create(owner=user, address=self.request.args.get('address')) return self.redirect('/case/details/%s' % case.key().id())
class HomeHandler(RequestHandler, Jinja2Mixin): middleware = [SessionMiddleware()] def get(self): """Home Page, assumes no state!.""" # Get user from session or CGI params. if self.request.args.get('logout'): email = None if 'email' in self.session: del self.session['email'] else: email = self.request.args.get('email', None) if email: # set email in session self.session['email'] = email else: # try to get email from session email = self.session.get('email', None) if email: user = models.User.get_by_email(email) if not user: user = models.User(email=email) user.put() else: user = None if user: role = self.request.args.get('role', None) if role: user.role = role user.put() if user.role == 'Applicant': return self.redirect('/applicant/home') if user.role == 'Permit Approver': return self.redirect('/approver/home') context = { 'user': user, 'roles': models.USER_ROLES, } context.update(config.config) return self.render_response('home.html', **context)
class EmailsChangeHandler(RequestHandler, Jinja2Mixin): middleware = [SessionMiddleware()] def get(self, id): """Change email settings for a case.""" user = models.User.get_by_email(self.session.get('email')) if not user: return self.redirect('/') case = models.Case.get_by_id(id) for a in models.NOTIFIABLE_ACTIONS: if self.request.args.get(a) == 'on': models.EmailNotification.set_on(case, a, user.email) else: models.EmailNotification.set_off(case, a, user.email) return self.redirect('/case/details/%s' % case.key().id())
class AddDocumentHandler(RequestHandler, Jinja2Mixin): middleware = [SessionMiddleware()] def get(self, id): """Add a document to a case.""" user = models.User.get_by_email(self.session.get('email')) if not user: return self.redirect('/') case = models.Case.get_by_id(id) upload_url = blobstore.create_upload_url( '/document/upload/%s' % case.key().id()) context = { 'upload_url': upload_url, 'user': user, 'case': case, } context.update(config.config) return self.render_response('document_upload.html', **context)
class HomeHandler(RequestHandler, Jinja2Mixin): middleware = [SessionMiddleware()] def get(self): """Home Page for an Applicant.""" user = models.User.get_by_email(self.session.get('email')) if not user: return self.redirect('/') cases = models.Case.query_by_owner(user) cases = list(cases.order('state')) logging.debug(cases) cases.sort(key=lambda c: c.last_modified, reverse=True) context = { 'user': user, 'cases': cases, } context.update(config.config) return self.render_response('applicant_home.html', **context)
class AuthRequestHandler(RequestHandler): middleware = [SessionMiddleware()] def _on_auth_redirect(self): """Redirects after successful authentication.""" if '_redirect' in self.session: url = self.session.pop('_redirect') else: url = '/' if not self.auth.user: url = self.auth.signup_url() return self.redirect(url) def redirect_path(self, default='/'): if '_redirect' in self.session: url = self.session.pop('_redirect') else: url = self.request.args.get('redirect', '/') if not url.startswith('/'): url = default return url
class HomeHandler(RequestHandler, Jinja2Mixin): middleware = [SessionMiddleware()] def get(self): """Home Page for an Approver.""" user = models.User.get_by_email(self.session.get('email')) if not user or not user.can_approve: return self.redirect('/') open_cases = models.Case.query_submitted() open_cases = list(open_cases.order('state').run()) open_cases.sort(key=lambda c: c.last_modified, reverse=True) my_cases, other_cases = models.Case.reviewed_by(user) context = { 'user': user, 'open_cases': open_cases, 'num_other_cases': len(other_cases), 'my_cases': my_cases, } context.update(config.config) return self.render_response('approver_home.html', **context)
class CaseDetailsHandler(RequestHandler, Jinja2Mixin): middleware = [SessionMiddleware()] def get(self, id): """Show details of a case and allow editing it.""" user = models.User.get_by_email(self.session.get('email')) if not user: return self.redirect('/') case = models.Case.get_by_id(id) actions = models.CaseAction.query_by_case(case).order('-timestamp') upload_url = blobstore.create_upload_url('/document/upload/%s' % case.key().id()) context = { 'user': user, 'case': case, 'actions': actions, 'uploadables': models.PURPOSES, 'upload_url': upload_url, } context.update(config.config) return self.render_response('case.html', **context)
class MyHandler(RequestHandler): middleware = [SessionMiddleware(), i18n.I18nMiddleware()] def get(self, **kwargs): locale = self.i18n.locale return Response(locale)
class MainHandler(RequestHandler): middleware = [SessionMiddleware()] def get_namespace(self, headers): headers.get('Host') namespace = self.request.host.split('.')[0] www = self.request.host return namespace, www def check_cookie(self,response, cookie_name, host): cookie = self.request.cookies.get(cookie_name) unique = True if cookie and 'visited' in cookie: unique = False else: response.set_cookie(cookie_name,{'visited':True}, domain=host, max_age = 2629743) return response, unique def get(self, hash=None): #GET THE CURRENT TIME! now = time.time() #DETERMINE NAMESPACE AND THE ACTUAL HOST URL namespace, host = self.get_namespace(self.request.headers) if self.request.args.get('namespace'): namespace = self.request.args.get('namespace') logging.info('Redirector: Setting namespace to: '+namespace) namespace_manager.set_namespace(namespace) #SEE IF THAT HASH IS CACHED FOR THIS NAMESPACE SO I DONT NEED TO LOOKUP the hash key? hashed = memcache.get(namespace+'-hash-'+str(hash)) h_found = False if hashed: h_found = True hashed = hashes.Hash.get_by_key_name(str(hashed)) if not hashed: h_found = False hashed = hashes.Hash.all().filter('hash =',hash).filter('deleted =',False).get() #IF HASHED DOESNT EXIST if not hashed: return self.abort(404) #OTHERWISE LETS START PROCESSING else: family, device = devices.determine_device(self.request.headers) logging.info('Redirector: Headers Following') logging.info(self.request.headers) logging.info('Redirector: Family = '+family) logging.info('Redirector: Device = '+device) #SET THE HASH if not h_found: logging.info('Redirector: Not found in memcache, setting memcache key') memcache.set(namespace+'-hash-'+str(hash), hashed.key().name(),time = 2629743) #redirector should set cookie loc = hashed.get_location(family) logging.info('Redirector: Redirect found: Family = '+loc.family+' Loc='+loc.location) r = self.redirect(loc.location) #CHECK UNIQUENESS FROM COOKIES FOR STATISTICS #CHECK COOKIES HASH r, hash_unique = self.check_cookie(r,hash,host) #CHECK COOKIE NAMESPACE r, namespace_unique = self.check_cookie(r,'namespace_global',host) #set a queue request to process in the background #deferred.defer(self.processStatistics, t = 'farts') taskqueue.Queue('statistics').add(taskqueue.Task(url = '/background/statistics', params = { 'Hash_unique':hash_unique, 'Namespace_unique':namespace_unique, 'Namespace' : namespace, 'Device':device, 'Family':family, 'User-Agent':self.request.headers.get('User-Agent'), 'Time' : int(now), 'Hash': hash, 'Host': self.request.host, } ) ) #create a redirect element #and redirect the person, all very quickly #return self.redirect(self.request.headers.get('Host')) logging.info(r.headers) return r
class BaseHandler(Base): middleware = [ SessionMiddleware(), NamespaceMiddleware(), UserRequiredIfAuthenticatedMiddleware() ]
class LoggedInHandler(Base): middleware = [ SessionMiddleware(), NamespaceMiddleware(), UserRequiredMiddleware() ]
class BaseHandler(RequestHandler, Jinja2Mixin): middleware = [SessionMiddleware()]
class BaseHandler(RequestHandler): middleware = [SessionMiddleware()]