def dispatch(self, *args, **kwargs): " All requests must have valid, in-date activation codes. " self.page_blocks = page_db.get_page_block_dict() self.activation_code = self.request.get('code') if not self.activation_code: self.abort(404) # lookup org by activation code orgs_by_code = Organization.all() \ .filter('activation_code', self.activation_code) if orgs_by_code.count() != 1: self.abort(404) self.org_by_code = orgs_by_code[0] # send response if already activated if self.org_by_code.is_active: self.render( already_activated_template, org=self.org_by_code ) return # send response if too late if self.org_by_code.activate_by < datetime.datetime.utcnow(): self.render( activation_too_late_template, org=self.org_by_code ) return # continue handling request super(ActivationHandler, self).dispatch(*args, **kwargs)
def dispatch(self, *args, **kwargs): " All requests must have valid, in-date activation codes. " self.page_blocks = page_db.get_page_block_dict() self.activation_code = self.request.get('code') if not self.activation_code: self.abort(404) # lookup org by activation code orgs_by_code = Organization.all() \ .filter('activation_code', self.activation_code) if orgs_by_code.count() != 1: self.abort(404) self.org_by_code = orgs_by_code[0] # send response if already activated if self.org_by_code.is_active: self.render(already_activated_template, org=self.org_by_code) return # send response if too late if self.org_by_code.activate_by < datetime.datetime.utcnow(): self.render(activation_too_late_template, org=self.org_by_code) return # continue handling request super(ActivationHandler, self).dispatch(*args, **kwargs)
def AuthenticatedGet(self, org, event): site_proj = db.Query( Site, projection=('county', 'state'), distinct=True ).filter('event', event) counties_and_states = { site.county_and_state : (site.county, site.state) for site in site_proj } Form = create_site_filter_form(counties_and_states) form = Form(self.request.GET) if not form.validate(): form = Form() # => use defaults # construct query query = Site.all().filter('event', event.key()) if form.county_and_state.data: county, state = counties_and_states[form.county_and_state.data] query = query.filter('county', county).filter('state', state) if form.order.data: query = query.order(form.order.data) # run query sites = list(query.run( offset=form.page.data * self.SITES_PER_PAGE, limit=self.SITES_PER_PAGE )) self.response.out.write(template.render(dict( page_db.get_page_block_dict(), **{ "form": form, "sites": sites, "sites_per_page": self.SITES_PER_PAGE, })))
def AuthenticatedGet(self, org, event): site_proj = db.Query(Site, projection=('county', 'state'), distinct=True).filter('event', event) counties_and_states = { site.county_and_state: (site.county, site.state) for site in site_proj } Form = create_site_filter_form(counties_and_states) form = Form(self.request.GET) if not form.validate(): form = Form() # => use defaults # construct query query = Site.all().filter('event', event.key()) if form.county_and_state.data: county, state = counties_and_states[form.county_and_state.data] query = query.filter('county', county).filter('state', state) if form.order.data: query = query.order(form.order.data) # run query sites = list( query.run(offset=form.page.data * self.SITES_PER_PAGE, limit=self.SITES_PER_PAGE)) self.response.out.write( template.render( dict( page_db.get_page_block_dict(), **{ "form": form, "sites": sites, "sites_per_page": self.SITES_PER_PAGE, })))
def get(self): logged_in = False org, event = key.CheckAuthorization(self.request) if org and key: logged_in = True template_params = page_db.get_page_block_dict() template_params['logged_in'] = logged_in self.response.out.write(template.render(template_params))
def get(self): events = event_db.GetAllCached() logged_in = False org, event = key.CheckAuthorization(self.request) if org and key: logged_in = True template_params = page_db.get_page_block_dict() template_params.update({ "events": events, "logged_in": logged_in, }) self.response.out.write(template.render(template_params))
def render(self, template, **kwargs): " Render a template, including page blocks. " page_blocks = page_db.get_page_block_dict() template_params = dict( page_blocks, **kwargs ) self.response.out.write( template.render( template_params ) )
def AuthenticatedGet(self, org, event): if org.permissions == "Situational Awareness": self.redirect("/sit_aware_redirect") return #single_site_template = jinja_environment.get_template('single_site.html') #if event.short_name in [HATTIESBURG_SHORT_NAME, GEORGIA_SHORT_NAME]: #single_site_template = jinja_environment.get_template('single_site_derechos.html') #if not event.short_name in [HATTIESBURG_SHORT_NAME, GEORGIA_SHORT_NAME, "sandy"]: #single_site_template = jinja_environment.get_template('single_site_incident_form.html') message = cgi.escape(self.request.get("message")) if len(message) == 0: message = None form = None #if event.short_name in [HATTIESBURG_SHORT_NAME, GEORGIA_SHORT_NAME]: #form = site_db.DerechosSiteForm() #else: #form = site_db.SiteForm() # get event.key() # search for form with that event q = db.Query(form_db.IncidentForm) q.filter("incident =", event.key()) query = q.get() # set it as form_stub # send to single site inc_form = None if query: inc_form = query.form_html single_site = single_site_template.render( { "form": form, "org": org, "incident_form_block": inc_form,}) page_blocks = page_db.get_page_block_dict() self.response.out.write( template.render(dict( page_blocks, **{ "version" : os.environ['CURRENT_VERSION_ID'], "message" : message, "menubox" : menubox_template.render({"org": org, "event": event, "admin": org.is_admin}), "single_site" : single_site, "form": form, "id": None, "page": "/", "event_name": event.name } )) )
def get(self): logged_in = False org, event = key.CheckAuthorization(self.request) if org and key: logged_in = True events_list = db.GqlQuery("SELECT * FROM Event ORDER BY created_date DESC") template_params = page_db.get_page_block_dict() template_params.update({ "logged_in": logged_in, "events_list": events_list, }) self.response.out.write(template.render(template_params))
def get(self): org, event = key.CheckAuthorization(self.request) if org and event: self.redirect(urllib.unquote(self.request.get('destination', default_value='/')).encode('ascii')) return template_params = page_db.get_page_block_dict() template_params.update({ "form" : GetOrganizationForm(self.request.POST), "destination" : self.request.get('destination', default_value='/'), "page" : "/authentication", "error_message": self.request.get("error_message") }) self.response.out.write(template.render(template_params))
def get(self): logged_in = False org, event = key.CheckAuthorization(self.request) if org and key: logged_in = True events_list = db.GqlQuery( "SELECT * FROM Event ORDER BY created_date DESC") template_params = page_db.get_page_block_dict() template_params.update({ "logged_in": logged_in, "events_list": events_list, }) self.response.out.write(template.render(template_params))
def AuthenticatedGet(self, org, event): global_admin = (org.name == GLOBAL_ADMIN_NAME) if not global_admin: self.redirect("/") return template_params = page_db.get_page_block_dict() template_params.update({ "form" : GetOrganizationForm(self.request.POST), "destination" : self.request.get('destination', default_value='/'), "page" : "/admin-delete-password", "error_message": self.request.get("error_message"), "initial_event_name": self.request.get("initial_event_name", ""), "error_message": self.request.get("message") }) self.response.out.write(template.render(template_params))
def AuthenticatedPost(self, org, event): name = self.request.get("name") form = GetOrganizationForm(self.request.POST) event_name = None if form.event.data: event_name = form.event.data if event_name == "None" or event_name == None: event_name = self.request.get("event_name") logging.info("new password") logging.info(name) logging.info(event_name) password = self.request.get("password") # raise Exception(event_name) if self.request.get("accept") == "true": event_name = self.request.get("event_name") this_event = event_db.Event.all().filter("name =", event_name).get() org = organization.Organization.all().filter( "name =", name).filter("incidents =", this_event.key()).get() password_hash = generate_hash.recursive_hash(password) if org: if password_hash in org._password_hash_list: self.rediect( "/admin?message=That password already exists for that organization" ) return org._password_hash_list.append(password_hash) org._password_hash_list = list(set(org._password_hash_list)) organization.PutAndCache(org) audit = audit_db.new_password(org, password_hash) url = "/admin?message=New password added to " + name + " working on " + event_name self.redirect(url) return else: url = "/admin-generate-new-password?error_message=Could not find " + name + "for: " + event_name self.redirect(url) return password = random_password.generate_password() template_params = page_db.get_page_block_dict() template_params.update({ "password": password, "name": name, "event_name": event_name }) self.response.out.write(post_template.render(template_params))
def get(self): logged_in = False org, event = key.CheckAuthorization(self.request) if org and key: logged_in = True # get page block params template_params = page_db.get_page_block_dict() # add version dictionary params try: with open('version.json') as version_json_fd: version_d = json.load(version_json_fd) except: version_d = None template_params.update({'version_d': version_d}) template_params['logged_in'] = logged_in self.response.out.write(template.render(template_params))
def AuthenticatedGet(self, org, event): global_admin = (org.name == GLOBAL_ADMIN_NAME) if not global_admin: self.redirect("/") return template_params = page_db.get_page_block_dict() template_params.update({ "form": GetOrganizationForm(self.request.POST), "destination": self.request.get('destination', default_value='/'), "page": "/admin-generate-new-password", "error_message": self.request.get("error_message"), "initial_event_name": self.request.get("initial_event_name", ""), }) self.response.out.write(template.render(template_params))
def get(self): pass events = event_db.GetAllCached() logged_in = False org, event = key.CheckAuthorization(self.request) query_string = "SELECT * FROM Event WHERE short_name = '{0}'".format(self.request.get("event")) query = db.GqlQuery(query_string) event = query.get() # raise Exception(event) if org and key: logged_in = True template_params = page_db.get_page_block_dict() template_params.update({ "events": events, "logged_in": logged_in, "initial_incident_id": self.request.GET.get("initial_incident_id", ""), "incident": self.request.get("incident"), "event": self.request.get("event"), "event_name": self.request.get("event_name") }) self.response.out.write(template.render(template_params))
def get(self): filters = [ #["debris_only", "Remove Debris Only"], #["electricity", "Has Electricity"], #["no_standing_water", "No Standing Water"], #["not_habitable", "Home is not habitable"], ["Flood", "Primary problem is flood damage"], ["Trees", "Primary problem is trees"], ["Goods or Services", "Primary need is goods and services"]] #["CT", "Connecticut"], #["NJ", "New Jersey"], #["NY", "New York"]] org, event = key.CheckAuthorization(self.request) if not (org and event): self.redirect("/authentication") return if org.permissions == "Situational Awareness": self.redirect("/sit_aware_redirect") return if org: filters = [["claimed", "Claimed by " + org.name], ["unclaimed", "Unclaimed"], ["open", "Open"], ["closed", "Closed"], ["reported", "Reported by " + org.name], ] + filters site_id = self.request.get("id") # default to 15 zoom_level = self.request.get("z", default_value = "15") template_values = page_db.get_page_block_dict() template_values.update({ "version" : os.environ['CURRENT_VERSION_ID'], #"uncompiled" : True, "counties" : event.counties, "org" : org, "menubox" : menubox_template.render({"org": org, "event": event, "include_search": True, "admin": org.is_admin, }), "status_choices" : [json.dumps(c) for c in site_db.Site.status.choices], "filters" : filters, "demo" : False, "zoom_level" : zoom_level, "site_id" : site_id, "event_name": event.name, }) else: # TODO(Jeremy): Temporary code until this handler scales. self.redirect("/authentication?destination=/map") return # Allow people to bookmark an unauthenticated event map, # by setting the event ID. event = event_db.GetEventFromParam(self.request.get("event_id")) if not event: self.response.set_status(404) return template_values = page_db.get_page_block_dict() template_values.update({ "sites" : [json.dumps({ "latitude": round(s.latitude, 2), "longitude": round(s.longitude, 2), "debris_removal_only": s.debris_removal_only, "electricity": s.electricity, "standing_water": s.standing_water, "tree_damage": s.tree_damage, "habitable": s.habitable, "electrical_lines": s.electrical_lines, "cable_lines": s.cable_lines, "cutting_cause_harm": s.cutting_cause_harm, "work_type": s.work_type, "state": s.state, }) for s in [p[0] for p in site_db.GetAllCached(event)]], "filters" : filters, "demo" : True, }) self.response.out.write(template.render(template_values))
def post(self): choose_event = self.request.get("choose_event") data = organization.OrganizationForm(self.request.POST) if not data.validate(): events_list = db.GqlQuery("SELECT * FROM Event ORDER BY created_date DESC") template_params = page_db.get_page_block_dict() template_params.update({ "form": data, "errors": data.errors, "events_list": events_list, }) self.response.out.write(template.render(template_params)) else: event_id = data.choose_event.data event = event_db.GetEventFromParam(event_id) new_org = organization.Organization(name = data.name.data, email = data.email.data, phone = data.phone.data, address = data.address.data, city = data.city.data, state = data.state.data, zip_code = data.zip_code.data, physical_presence = bool(data.physical_presence.data), number_volunteers = data.number_volunteers.data, voad_member = bool(data.voad_member.data), canvass = bool(data.canvass.data), assessment = bool(data.assessment.data), water_pumping = bool(data.water_pumping.data), muck_out = bool(data.muck_out.data), interior_debris = bool(data.interior_debris.data), gutting = bool(data.gutting.data), tree_removal = bool(data.tree_removal.data), exterior_debris = bool(data.exterior_debris.data), sanitizing = bool(data.sanitizing.data), mold_treatment = bool(data.mold_treatment.data), design = bool(data.design.data), permits = bool(data.permits.data), reconstruction = bool(data.reconstruction.data), replace_appliances = bool(data.replace_appliances.data), replace_furniture = bool(data.replace_furniture.data), choose_event = event, org_verified=bool(0), twitter = data.twitter.data, url = data.url.data, voad_referral = data.voad_referral.data, work_area = data.work_area.data, voad_member_url = data.voad_member_url.data, facebook = data.facebook.data, publish = data.publish.data, incident = event.key(), ) new_contact = primary_contact_db.Contact(first_name = data.contact_first_name.data, last_name = data.contact_last_name.data, email = data.contact_email.data, phone=data.contact_phone.data, is_primary=True) organization.PutAndCacheOrganizationAndContact(organization = new_org, contact = new_contact, ) self.redirect("/welcome")
def render(self, template, **kwargs): " Render a template, including page blocks. " page_blocks = page_db.get_page_block_dict() template_params = dict(page_blocks, **kwargs) self.response.out.write(template.render(template_params))
def get(self): user_agent = self.request.headers["User-Agent"] desktop = True if "iPad" in user_agent or "iPhone" in user_agent or "Android" in user_agent: desktop = False filters = [ #["debris_only", "Remove Debris Only"], #["electricity", "Has Electricity"], #["no_standing_water", "No Standing Water"], #["not_habitable", "Home is not habitable"], ["Flood", "Primary problem is flood damage"], ["Trees", "Primary problem is trees"], ["Goods or Services", "Primary need is goods and services"] ] #["CT", "Connecticut"], #["NJ", "New Jersey"], #["NY", "New York"]] org, event = key.CheckAuthorization(self.request) if not (org and event): self.redirect("/authentication") return if org.permissions == "Situational Awareness": self.redirect("/sit_aware_redirect") return if org: filters = [ ["claimed", "Claimed by " + org.name], ["unclaimed", "Unclaimed"], ["open", "Open"], ["closed", "Closed"], ["reported", "Reported by " + org.name], ] + filters site_id = self.request.get("id") # default to 15 zoom_level = self.request.get("z", default_value="15") template_values = page_db.get_page_block_dict() template_values.update({ "version": os.environ['CURRENT_VERSION_ID'], "desktop": desktop, #"uncompiled" : True, "counties": event.counties, "org": org, "menubox": menubox_template.render({ "org": org, "event": event, "include_search": True, "admin": org.is_admin, }), "status_choices": [json.dumps(c) for c in site_db.Site.status.choices], "filters": filters, "demo": False, "zoom_level": zoom_level, "site_id": site_id, "event_name": event.name, }) else: # TODO(Jeremy): Temporary code until this handler scales. self.redirect("/authentication?destination=/map") return # Allow people to bookmark an unauthenticated event map, # by setting the event ID. event = event_db.GetEventFromParam(self.request.get("event_id")) if not event: self.response.set_status(404) return template_values = page_db.get_page_block_dict() template_values.update({ "sites": [ json.dumps({ "latitude": round(s.latitude, 2), "longitude": round(s.longitude, 2), "debris_removal_only": s.debris_removal_only, "electricity": s.electricity, "standing_water": s.standing_water, "tree_damage": s.tree_damage, "habitable": s.habitable, "electrical_lines": s.electrical_lines, "cable_lines": s.cable_lines, "cutting_cause_harm": s.cutting_cause_harm, "work_type": s.work_type, "site_id": site_id, "state": s.state, }) for s in [p[0] for p in site_db.GetAllCached(event)] ], "filters": filters, "script": script, "demo": True, }) self.response.out.write(template.render(template_values))
def AuthenticatedGet(self, org, event): if org.permissions == "Situational Awareness": self.redirect("/sit_aware_redirect") return #single_site_template = jinja_environment.get_template('single_site.html') #if event.short_name in [HATTIESBURG_SHORT_NAME, GEORGIA_SHORT_NAME]: #single_site_template = jinja_environment.get_template('single_site_derechos.html') #if not event.short_name in [HATTIESBURG_SHORT_NAME, GEORGIA_SHORT_NAME, "sandy"]: #single_site_template = jinja_environment.get_template('single_site_incident_form.html') message = cgi.escape(self.request.get("message")) if len(message) == 0: message = None form = None #if event.short_name in [HATTIESBURG_SHORT_NAME, GEORGIA_SHORT_NAME]: #form = site_db.DerechosSiteForm() #else: #form = site_db.SiteForm() # get event.key() # search for form with that event q = db.Query(form_db.IncidentForm) q.filter("incident =", event.key()) query = q.get() # set it as form_stub # send to single site inc_form = None if query: inc_form = query.form_html single_site = single_site_template.render({ "form": form, "org": org, "incident_form_block": inc_form, }) page_blocks = page_db.get_page_block_dict() self.response.out.write( template.render( dict( page_blocks, **{ "version": os.environ['CURRENT_VERSION_ID'], "message": message, "menubox": menubox_template.render({ "org": org, "event": event, "admin": org.is_admin }), "single_site": single_site, "form": form, "id": None, "page": "/", "event_name": event.name })))