def license_delete(request): session = DBSession() id = request.matchdict['license'] license = session.query(License).get(id) session.delete(license) session.flush() request.session.flash('License removed!') return HTTPFound(location = route_url('licenses', request))
def split_tile(request): job_id = request.matchdict['job'] x = request.matchdict['x'] y = request.matchdict['y'] zoom = request.matchdict['zoom'] session = DBSession() job = session.query(Job).get(job_id) tile = session.query(Tile).get((x, y, zoom, job_id)) session.delete(tile) new_tiles = [] t = [] for i in range(0, 2): for j in range(0, 2): tile = Tile(int(x)*2 + i, int(y)*2 + j, int(zoom)+1) tile.job = job t.append(tile) for tile in t: new_tiles.append(Feature(geometry=tile.to_polygon(), id=str(tile.x) + '-' + str(tile.y) + '-' + str(tile.zoom))) return dict(success=True, split_id="-".join([x, y, zoom]), new_tiles=FeatureCollection(new_tiles))
def split_tile(request): job_id = request.matchdict['job'] x = request.matchdict['x'] y = request.matchdict['y'] zoom = request.matchdict['zoom'] session = DBSession() job = session.query(Job).get(job_id) tile = session.query(Tile).get((x, y, zoom, job_id)) session.delete(tile) new_tiles = [] t = [] for i in range(0, 2): for j in range(0, 2): tile = Tile(int(x) * 2 + i, int(y) * 2 + j, int(zoom) + 1) tile.job = job t.append(tile) for tile in t: new_tiles.append( Feature(geometry=tile.to_polygon(), id=str(tile.x) + '-' + str(tile.y) + '-' + str(tile.zoom))) return dict(job=tile.job, split_id="-".join([x, y, zoom]), new_tiles=FeatureCollection(new_tiles))
def job_delete(request): id = request.matchdict['job'] session = DBSession() # prevent integrity errors tiles_history = session.query(TileHistory).filter(TileHistory.job_id==id) for tile in tiles_history: session.delete(tile) job = session.query(Job).get(id) title = job.title session.delete(job) # remove the tiles history twice because removing records from main table # adds records in the history table tiles_history = session.query(TileHistory).filter(TileHistory.job_id==id) for tile in tiles_history: session.delete(tile) request.session.flash('Job "%s" removed!' % title) return HTTPFound(location = route_url('home', request))
def job_delete(request): id = request.matchdict['job'] session = DBSession() # prevent integrity errors tiles_history = session.query(TileHistory).filter(TileHistory.job_id == id) for tile in tiles_history: session.delete(tile) job = session.query(Job).get(id) title = job.title session.delete(job) # remove the tiles history twice because removing records from main table # adds records in the history table tiles_history = session.query(TileHistory).filter(TileHistory.job_id == id) for tile in tiles_history: session.delete(tile) request.session.flash('Job "%s" removed!' % title) return HTTPFound(location=route_url('home', request))
__requires__ = 'OSMTM' import os import sys import transaction from sqlalchemy import create_engine from pyramid.paster import ( get_appsettings, setup_logging, ) from OSMTM.models import ( DBSession, Job, Tile, TileHistory, Base, ) from OSMTM.utils import * id = sys.argv[1] engine = create_engine('sqlite:///OSMTM.db') DBSession.configure(bind=engine) with transaction.manager: job = DBSession.query(Job).filter(Job.id == id).one() DBSession.delete(job)
def split_tile(request): """ Split the tile and copy history of the parent tile """ job_id = request.matchdict['job'] x = request.matchdict['x'] y = request.matchdict['y'] zoom = request.matchdict['zoom'] session = DBSession() job = session.query(Job).get(job_id) tile = session.query(Tile).get((x, y, zoom, job_id)) session.delete(tile) # reference tile history tileHistory = ( session.query(TileHistory) .filter_by(x=x, y=y, zoom=zoom, job_id=job_id) .order_by(TileHistory.update) .all() ) new_tiles = [] t = [] for i in range(0, 2): for j in range(0, 2): # add new tile X = int(x) * 2 + i Y = int(y) * 2 + j Zoom = int(zoom) + 1 newTile = Tile(X, Y, Zoom) newTile.job = job for idx, historyRecord in enumerate(tileHistory): # copy tileHistory... use negative versions to prevent unique # key conflicts, and enable filtering (exclusion) when # generating stats newTileHistory = TileHistory( x=newTile.x, y=newTile.y, zoom=newTile.zoom, username=historyRecord.username, update=historyRecord.update, checkout=historyRecord.checkout, checkin=historyRecord.checkin, change=historyRecord.change, comment=historyRecord.comment, job_id=job.id, version=-idx ) session.add(newTileHistory) t.append(newTile) for tile in t: new_tiles.append( Feature( geometry=tile.to_polygon(), id=str(tile.x) + '-' + str(tile.y) + '-' + str(tile.zoom))) return dict( success=True, split_id="-".join([x, y, zoom]), new_tiles=FeatureCollection(new_tiles) )
#!env/bin/python __requires__ = "OSMTM" import os import sys import transaction from sqlalchemy import create_engine from pyramid.paster import get_appsettings, setup_logging from OSMTM.models import DBSession, Job, Tile, TileHistory, Base from OSMTM.utils import * id = sys.argv[1] engine = create_engine("sqlite:///OSMTM.db") DBSession.configure(bind=engine) with transaction.manager: job = DBSession.query(Job).filter(Job.id == id).one() DBSession.delete(job)