def pgelement_adapter(obj, request): # In order to pass a geometry object to the pyramid json renderer # we have to pull the geometry and generate a python dict # Postgis's geojson function returns a string, so we have to pass # that to json loads in order for the final output to be correct. # FIXME, this method currently makes a query against the database # for each geometry s = DBSession() return json.loads(s.scalar(obj.geojson))
def post_validate(form): session = DBSession() try: user = session.query(User).filter_by( name=form.name.data, password=User.encode_password(form.password.data)).one() headers = remember(request, user.id) return HTTPFound(headers=headers, location=request.route_url('index')) except NoResultFound, e: return {'form': form, 'errors': [e]}
def load_fixtures(fixture_path): fixtures = yaml.load(open(fixture_path, 'r').read()) session = DBSession() for fixture in fixtures: model = resolve(fixture.get('class')) try: inst = model(**fixture['fields']) with transaction.manager: session.add(inst) except Exception, e: raise e
def add_resource(request, model, schema_cls): session = DBSession() try: schema = schema_cls() vals = schema.deserialize(request.json_body) ints = model(**vals) session.add(ints) session.flush() return ints except colander.Invalid, e: request.response.status = 'Bad request 400' return e.asdict()
def __init__(self, request): self.request = request self.session = DBSession()
def show_devices(request): session = DBSession() return list(session.query(Device).all())
def show_rides(request): session = DBSession() return list(session.query(Ride).all())
def show_traces(request): session = DBSession() return list(session.query(Trace).all())