def validator(form, value): session = DBSession() if session.query(RouteMaster).filter_by(ref=value['ref'], city=context, type=value['type']).count() != 0: t = 'Route with this ref and type already exists' exc = colander.Invalid(form, t) exc['ref'] = t raise exc
def city_view(context, request): session = DBSession() rms = session.query(RouteMaster).filter_by(city=context).all() route_masters_by_transport = [ (type, [rm for rm in rms if rm.type == type]) for type in allowed_types ] return dict(city=context, route_masters_by_transport=route_masters_by_transport)