def post(self): #get the variables from the post request descriptive_name = self.request.get('sight_name_location_name') points_string = self.request.get('points_string_name') #convert the points string to a list of point objects points_list = FormatConverter()\ .convert_points_string_to_points_list(points_string) #create the polygon object polygon = Polygon() polygon.create_polygon_by_points(points_list) if not polygon.is_valid_polygon(): #handle bad polygon here pass #get user object this_user = User().by_user_name(self.user_name) location_management = LocationManagement() #insert the location into the database pl_key = location_management.location_creation(this_user, polygon, descriptive_name) if pl_key: #if insert was successful redirect use to editing page url_safe_key = pl_key.urlsafe() self.redirect('/edit_location/' + url_safe_key) else: #if insert was unsuccessful handle it self.write('catch this error')
def post(self): # TODO: sanitize form input. all values must be present! self.type = self.request.get('type') self.name = self.request.get('name') self.lat = self.request.get('lat') self.lon = self.request.get('lon') self.cost = self.request.get('cost') self.city = self.request.get('city') self.end_date = datetime.datetime.strptime(self.request.get('end_date'), '%m/%d/%Y') self.start_date = datetime.datetime.strptime(self.request.get('start_date'), '%m/%d/%Y') self.user = self.arg_dict['user'] latlon = '%s, %s' %(self.lat, self.lon) print self.user user_instance = User.by_user_name(self.user) print user_instance p = Permit() p.owner = user_instance p.name = self.name p.geo_location = ndb.GeoPt(latlon) p.type = self.type p.cost = self.cost p.city = self.city p.start_date = self.start_date p.end_date = self.end_date k = p.put() self.arg_dict['type'] = list(Permit.type._choices) self.render('permit_maker.html', **self.arg_dict)
def post(self): self.add_page_name('signup_page') #get the user inputs from the post request user_name = self.request.get('email_signup_name') password = self.request.get('password_signup_name') password_match = self.request.get('password_match_signup_name') phone_number = self.request.get('phone_number_signup_name') #email = self.request.get('email_signup_name') #roles = self.request.items() #roles = ['approver', 'saftey'] self.arg_dict['user_name'] = user_name #self.arg_dict['email'] = email #Check to see that all of the inputs appear to be valid valid_inputs = ValidInputs() has_error = False # if not valid_inputs.valid_user_name(user_name): # self.arg_dict['error_user_name'] = "That's not a valid username." # has_error = True if not valid_inputs.valid_password(password): self.arg_dict['error_password'] = "******" has_error = True elif password != password_match: self.arg_dict['error_verify'] = "Your passwords didn't match." has_error = True if not valid_inputs.valid_email(user_name): self.arg_dict['error_email'] = "That's not a valid email." has_error = True if not valid_inputs.valid_phone_number(phone_number): self.arg_dict['error_phone_number'] = "That is not a valid phone number." has_error = True #if there was a bad value re-render the signup page if has_error: self.render('signup_form.html', **self.arg_dict) else: if User().by_user_name(user_name): self.arg_dict['error_email'] = "That user already exists." self.render('signup_form.html', **self.arg_dict) print 'r', self.arg_dict else: pw_hash = SecureValue().make_pw_hash(user_name, password) User().register_user(user_name, pw_hash, phone_number) self.login(user_name) # fix this? self.redirect('/')
def get(self): if not self.confirm_user_logged_in(): return user = User().by_user_name(self.user_name) locations = PrivateLocation().get_all_locations_by_user(user) self.arg_dict['locations'] = {} for location in locations: self.location_to_arg_dict(location) self.add_page_name('manage_locations') self.render('manage_locations_form.html', **self.arg_dict)
def get_resources(self, resource): """ helper function to get the variable from the request :param resource: http request document :return: """ self.resource = resource self.resource_string = urllib.unquote(resource) self.resource_key = ndb.Key(urlsafe=self.resource_string) self.location = self.resource_key.get() self.user = User().by_user_name(self.user_name)
def post(handler, parameters, url_parameters, ids_parameters): """POST method""" if not parameters: handler.logger.debug("Ignoring") handler.send_json("{}") return obj = User() for key, value in parameters.items(): if key in obj.__dict__: setattr(obj, key, value) obj = handler.session.add(obj) handler.logger.debug("Created successfully") handler.send_object(obj)
def post(self): if not self.confirm_user_logged_in(): self.redirect('/login') return if self.request.get('save_landing_zone'): self.add_page_name('landing_zone') lz_dict = LandingZoneInterface.read_inputs(self) if lz_dict['send_sms'] == 'true': LandingZoneEmailHandler().send_alert(lz_dict['warning_text']) this_user = User().by_user_name(self.user_name) lz = LandingZone() lz_key = lz.save_landing_zone(this_user.key, lz_dict['warning_text'], lz_dict['lat'], lz_dict['lng'], lz_dict['formatted_start_time'], lz_dict['formatted_end_time'], lz_dict['radius']) url_safe_key = lz_key.urlsafe() self.redirect('/landing_zone_edit/' + url_safe_key)
def post(self): lat = self.request.get('lat') lon = self.request.get('lon') time = datetime.strftime( datetime.now(), "%H:%M:%S") # this should actually be captured on webpage side? #date = datetime.strftime(datetime.date(), "%m:%d:%Y") #print time user = User.query(User.user_name == self.arg_dict['user']).fetch()[0] #latlon = '%s, %s' %(lat, lon) fl = FlyingLocation() fl.user = user #fl.geo_location = ndb.GeoPt(latlon) fl.lat = lat fl.lon = lon fl.time = time #fl.date = date fl.put()
def post(self, resource): if not self.confirm_user_logged_in(): self.redirect('/login') return url_safe_key = urllib.unquote(resource) lz_key = ndb.Key(urlsafe=url_safe_key) lz = LandingZone.get_by_key(lz_key) self.arg_dict[ 'lz'] = LandingZoneInterface.make_landing_zone_dictionary(lz) if self.request.get('save_landing_zone'): self.add_page_name('landing_zone') lz_dict = LandingZoneInterface.read_inputs(self) this_user = User().by_user_name(self.user_name) lz_key = lz.update_landing_zone(this_user.key, lz_dict['warning_text'], lz_dict['lat'], lz_dict['lng'], lz_dict['formatted_start_time'], lz_dict['formatted_end_time'], lz_dict['radius']) url_safe_key = lz_key.urlsafe() self.redirect('/landing_zone_edit/' + url_safe_key)
def post(self): self.add_page_name('login_page') user_name = self.request.get('user_name_login_name') password = self.request.get('password_login_name') has_error = False #check to see if the username is in the User db user = User().by_user_name(user_name) if not user: self.arg_dict['error_msg'] = "Invalid user name." has_error = True else: #check to see if usename and password are valid secure = SecureValue().check_valid_password( user_name, password, user.pw_hash) if not secure: self.arg_dict['error_msg'] = "Password not valid for user." has_error = True if has_error: self.render('login_form.html', **self.arg_dict) else: self.login(user.user_name) self.redirect('/')
def post(self): # if not self.request.get('phone_number'): # self.render('permits/%s.html' %zone) # return user_name = self.request.get('email_name') password = self.request.get('password_name') #password_match = self.request.get('password_match_name') phone_number = self.request.get('phone_number') uav_make = self.request.get('uav_make') uav_model = self.request.get('uav_model') description = self.request.get('description') permit_id = self.request.get('permit_id') date = self.request.get('flight_date') city = self.request.get('city') # TODO: move up to Permit flight_date = datetime.datetime.strptime(date, "%Y-%m-%d") # TODO: have the permit_id, need to find the Permit entity # print 'permit_id', permit_id # print ndb.Key('Permit', permit_id).get() # print Permit.get_by_id('4600081772707840') # p = PermitForm.query(PermitForm.key == permit_ndb_key).fetch() # print 'p', p # f = PermitForm.query(PermitForm.key == permit_ndb_key).count() # # print 'f', f # if User.phone_number_exists(phone_number): # print 'User exists!' # user = User.by_phone_number(phone_number=phone_number) # else: # print 'User does not exist. creating new user.' # user = User() #create_user(user_name=user_name, email=user_email, phone_number=phone_number) # user.user_name = user_name # user.email = user_email # user.phone_number = phone_number # if not self.arg_dict['user'] == 'guest': # pass # else: # pass # # if not len(user_name) == 0: # #Check to see that all of the inputs appear to be valid # valid_inputs = ValidInputs() # has_error = False # # if not valid_inputs.valid_user_name(user_name): # # self.arg_dict['error_user_name'] = "That's not a valid username." # # has_error = True # if not valid_inputs.valid_password(password): # self.arg_dict['error_password'] = "******" # has_error = True # # elif password != password_match: # # self.arg_dict['error_verify'] = "Your passwords didn't match." # # has_error = True # if not valid_inputs.valid_email(user_name): # self.arg_dict['error_email'] = "That's not a valid email." # has_error = True # #if there was a bad value re-render the signup page # if has_error: # print has_error, self.arg_dict # self.render('/permits/atherton.html', **self.arg_dict) # return # else: # if User().by_user_name(user_name): # self.arg_dict['error_email'] = "That user already exists." # self.render('/permits/atherton.html', **self.arg_dict) # #print self.arg_dict # return # else: # pw_hash = SecureValue().make_pw_hash(user_name, password) # user = User()#.register_user(user_name, pw_hash, email) # user.user_name = user_name # user.pw_hash = pw_hash # user.phone_number = phone_number # user.put() # self.login(user_name) # fix this? # #self.redirect('/') # else: # user = User.by_user_name(self.arg_dict['user']) has_error = False user = User().by_user_name(user_name) if user: secure = SecureValue().check_valid_password(user_name, password, user.pw_hash) if not secure: self.arg_dict['error_password'] = "******" has_error = True elif not user: pw_hash = SecureValue().make_pw_hash(user_name, password) user = User()#.register_user(user_name, pw_hash, email) user.user_name = user_name user.pw_hash = pw_hash user.phone_number = phone_number user.put() # finish up if has_error: self.render('/permits/atherton.html', **self.arg_dict) return else: self.login(user.user_name) p = PermitForm() p.user = user #p.permit=permit.key p.uav_model=uav_model p.uav_make=uav_make #p.description=description, p.flight_date=flight_date # TODO: move up to Permit p.city = city pn = p.put() #print 'permit_app', p self.render('permit_applied.html', **self.arg_dict)