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, resource):
        """
        Handles an edited location
        :param resource: url safe location key
        :return:
        """
        self.get_resources(resource)

        if self.request.get('delete_location'):
            LocationManagement().delete_location(self.location.key)
            self.redirect('/manage_locations')

        elif self.request.get('save_location'):
            #get the variables from the post request
            descriptive_name = self.request.get('descriptive_name')
            active = self.request.get('active')
            camera = self.request.get('camera')
            camera_text = self.request.get('camera_text')
            video = self.request.get('video')
            video_text = self.request.get('video_text')
            points_string = self.request.get('points_string_name')
            zip_code = self.request.get('zip_code')
            #convert the points string to a list of points
            points_list = FormatConverter()\
                .convert_points_string_to_points_list(points_string)

            #create new polygon
            new_polygon = Polygon()
            new_polygon.create_polygon_by_points(points_list)

            #check to see if the polygon is valid
            if not new_polygon.is_valid_polygon():
                #if not valid redirect to unedited version of location
                url_safe_key = self.location.key.urlsafe()
                self.redirect('/edit_location/' + url_safe_key)
                return
            #check to see if the polygon has changed
            polygons_match = new_polygon\
                .polygon_is_equivalent(self.location.polygon)
            if not polygons_match:
                '''if the polygon was edited remove all old children and
                inserts new children for the location'''
                self.location.polygon = new_polygon
                LocationManagement()\
                    .edit_location_with_polygon_change(new_polygon,
                                                       self.location.key)
            #set fields of db object and put it to the db
            self.location.descriptive_name = descriptive_name
            self.location.status.active = self.convert_true_false(active)
            self.location.camera.active = self.convert_true_false(camera)
            self.location.camera.message_text = camera_text
            self.location.video.active = self.convert_true_false(video)
            self.location.video.message_text = video_text
            self.location.zip_code = zip_code
            self.location.put()

            #redirect to the location edit page
            self.url_safe_key = self.location.key.urlsafe()
            self.redirect('/edit_location/' + self.url_safe_key)