def confirm(self, ticket): 'Confirm changes' # Send feedback candidate = confirmPersonCandidate(ticket) # If the candidate exists, if candidate: # Set messageCode = 'updated' if candidate.person_id else 'created' # Delete expired or similar candidates Session.execute(model.person_candidates_table.delete().where((model.PersonCandidate.when_expired < datetime.datetime.utcnow()) | (model.PersonCandidate.username == candidate.username) | (model.PersonCandidate.nickname == candidate.nickname) | (model.PersonCandidate.email == candidate.email))) Session.commit() # If the candidate does not exist, else: # Set messageCode = 'expired' # Return return redirect(url('person_login', url='/', messageCode=messageCode))
def confirm(self, ticket): 'Confirm changes' # Send feedback candidate = confirmPersonCandidate(ticket) # If the candidate exists, if candidate: # Set messageCode = 'updated' if candidate.person_id else 'created' # Delete expired or similar candidates Session.execute(model.person_candidates_table.delete().where( (model.PersonCandidate.when_expired < datetime.datetime.utcnow()) | (model.PersonCandidate.username == candidate.username) | (model.PersonCandidate.nickname == candidate.nickname) | (model.PersonCandidate.email == candidate.email))) Session.commit() # If the candidate does not exist, else: # Set messageCode = 'expired' # Return return redirect(url('person_login', url='/', messageCode=messageCode))
def getSRID(proj4): 'Convert proj4 to srid' # Simplify proj4Simplified = simplifyProj4(proj4) if not proj4Simplified: raise model.GeoRegistryError('Must specify valid proj4 spatial reference') # For each spatial reference, for proj4Standard, srid in Session.execute('SELECT proj4text, srid FROM spatial_ref_sys'): # Skip empty proj4s if not proj4Standard.strip(): continue # If we have a match, if simplifyProj4(proj4Standard) == proj4Simplified: return srid # If we have no matches, raise exception raise model.GeoRegistryError('Could not recognize proj4 spatial reference')
def tearDown(self): Session.execute(model.feature_tags_table.delete()) Session.execute(model.features_table.delete()) Session.execute(model.tags_table.delete()) Session.commit()
except ValueError: abort( 400, 'Could not parse simplified=%s as an integer' % simplified) # If simplification is desired, if simplified: # If a bounding box is specified, if bbox: # Convert bounding box to a metric coordinate system try: multiPoint = shapely.wkb.loads( str( Session.execute( geoalchemy.functions.wkb( geoalchemy.functions.transform( geoalchemy.WKTSpatialElement( 'MULTIPOINT(%s %s, %s %s)' % (minY, minX, maxY, maxX), srid), 3857))).fetchone()[0])) except sa.exc.InternalError: Session.rollback() y1, x1, y2, x2 = -20037508.34, -20037508.34, 20037508.34, 20037508.34 else: y1, x1 = multiPoint.geoms[0].coords[0] y2, x2 = multiPoint.geoms[1].coords[0] metersPerPixel = min(abs(x2 - x1), abs(y2 - y1)) / 256. # If a bounding box is not specified, else: metersPerPixel = 0.2 # Define transformation in a metric coordinate system simplify = lambda x: sa.func.ST_SimplifyPreserveTopology(
# Return return '\n'.join(str(x.id) for x in features) def delete(self): 'Delete features' # Authenticate via personID or key personID = h.getPersonIDViaKey() if not personID: abort(401, 'Please log in or provide a valid key') # Load featureIDs featureIDs = request.params.get('featureIDs', '').splitlines() if not featureIDs: abort(400, 'Must specify at least one featureID in featureIDs') # Make sure that the user has write access to the given featureIDs try: model.getWritableFeatures(featureIDs, personID) except model.GeoRegistryError, error: abort(400, str(error)) # Update timestamps for each tag for tag in Session.query(model.Tag).join(model.Tag.features).filter( model.Feature.id.in_(featureIDs)): tag.updateTimestamp() # Delete Session.execute( model.feature_tags_table.delete( model.feature_tags_table.c.feature_id.in_(featureIDs))) Session.execute( model.features_table.delete( model.features_table.c.id.in_(featureIDs))) Session.commit()
# If a bounding box is not specified, else: restrict = lambda x: x # Load simplified simplified = request.params.get('simplified', 1) try: simplified = int(simplified) except ValueError: abort(400, 'Could not parse simplified=%s as an integer' % simplified) # If simplification is desired, if simplified: # If a bounding box is specified, if bbox: # Convert bounding box to a metric coordinate system try: multiPoint = shapely.wkb.loads(str(Session.execute(geoalchemy.functions.wkb(geoalchemy.functions.transform(geoalchemy.WKTSpatialElement('MULTIPOINT(%s %s, %s %s)' % (minY, minX, maxY, maxX), srid), 3857))).fetchone()[0])) except sa.exc.InternalError: Session.rollback() y1, x1, y2, x2 = -20037508.34, -20037508.34, 20037508.34, 20037508.34 else: y1, x1 = multiPoint.geoms[0].coords[0] y2, x2 = multiPoint.geoms[1].coords[0] metersPerPixel = min(abs(x2 - x1), abs(y2 - y1)) / 256. # If a bounding box is not specified, else: metersPerPixel = 0.2 # Define transformation in a metric coordinate system simplify = lambda x: sa.func.ST_SimplifyPreserveTopology(geoalchemy.functions.transform(x, 3857), metersPerPixel) # If simplification is not desired, else: simplify = lambda x: x
# Update timestamps for each tag for tag in tags: tag.updateTimestamp() # Commit Session.commit() # Return return '\n'.join(str(x.id) for x in features) def delete(self): 'Delete features' # Authenticate via personID or key personID = h.getPersonIDViaKey() if not personID: abort(401, 'Please log in or provide a valid key') # Load featureIDs featureIDs = request.params.get('featureIDs', '').splitlines() if not featureIDs: abort(400, 'Must specify at least one featureID in featureIDs') # Make sure that the user has write access to the given featureIDs try: model.getWritableFeatures(featureIDs, personID) except model.GeoRegistryError, error: abort(400, str(error)) # Update timestamps for each tag for tag in Session.query(model.Tag).join(model.Tag.features).filter(model.Feature.id.in_(featureIDs)): tag.updateTimestamp() # Delete Session.execute(model.feature_tags_table.delete(model.feature_tags_table.c.feature_id.in_(featureIDs))) Session.execute(model.features_table.delete(model.features_table.c.id.in_(featureIDs))) Session.commit()