def queryMap(request): ''' Build the mapfile in a separate view ''' response = HttpResponse() params = {} for key, value in list(query_parms.items()): if type(value) in (list, tuple): params[key] = [request.GET.get(p, None) for p in value] else: params[key] = request.GET.getlist(key) # The Javascript that constructs the request items must remove any items that will make the # server busy with requests that have nothing to do with making a map; for example, removing # 'parameterparameterpng' and 'parameterparameterx3d' removed from 'only' helps speed things up. logger.debug('Instantiating STOQSQManager with params = %s', params) qm = STOQSQManager(request, response, request.META['dbAlias'], **params) qm.buildQuerySets() options = json.dumps(qm.generateOptions(), cls=encoders.STOQSJSONEncoder) ##logger.debug('options = %s', pprint.pformat(options)) _buildMapFile(request, qm, options) response['Content-Type'] = 'text/json' response.write(options) return response
def queryData(request, format=None): ''' Process data requests from the main query web page. Returns both summary Activity and actual MeasuredParameter data as retreived from STOQSQManager. ''' response = HttpResponse() params = {} for key, value in query_parms.iteritems(): if type(value) in (list, tuple): params[key] = [request.GET.get(p, None) for p in value] else: params[key] = request.GET.getlist(key) # Look for any parameter _MIN & _MAX input from the UI. After retrieving the above query_parms the # only thing left in the request QueryDict should be the parameter _MIN _MAX selections. for key, value in request.GET.iteritems(): if key.endswith('_MIN'): # Just test for _MIN; UI will always provide _MIN & _MAX name = key.split('_MIN')[0] try: pminmax = {name: (request.GET.getlist(name + '_MIN')[0], request.GET.getlist(name + '_MAX')[0])} except: logger.exception('Could not get parameter values even though ' + key + ' ends with _MIN') params['parametervalues'].append(pminmax) logger.info('Adding to parametervalues: %s', pprint.pformat(pminmax)) qm = STOQSQManager(request, response, request.META['dbAlias']) logger.debug('Calling buildQuerySets with params = %s', params) try: qm.buildQuerySets(**params) except ValidationError, e: logger.error(e) return HttpResponseBadRequest('Bad request: ' + str(e))
def queryData(request, fmt=None): ''' Process data requests from the main query web page. Returns both summary Activity and actual MeasuredParameter data as retreived from STOQSQManager. ''' response = HttpResponse() params = {} for key, value in query_parms.iteritems(): if type(value) in (list, tuple): params[key] = [request.GET.get(p, None) for p in value] else: params[key] = request.GET.getlist(key) # Look for any parameter _MIN & _MAX input from the UI. After retrieving the above query_parms the # only thing left in the request QueryDict should be the parameter _MIN _MAX selections. for key, value in request.GET.iteritems(): if key.endswith('_MIN'): # Just test for _MIN; UI will always provide _MIN & _MAX name = key.split('_MIN')[0] try: pminmax = {name: (request.GET.getlist(name + '_MIN')[0], request.GET.getlist(name + '_MAX')[0])} except: logger.exception('Could not get parameter values even though ' + key + ' ends with _MIN') params['parametervalues'].append(pminmax) logger.debug('Adding to parametervalues: %s', pprint.pformat(pminmax)) # To support unit testing and follow-on expectation that dbAlias is in request METAdata if 'dbAlias' not in request.META: request.META['dbAlias'] = dbAlias logger.debug('Instantiating STOQSQManager with params = %s', params) qm = STOQSQManager(request, response, request.META['dbAlias'], **params) try: qm.buildQuerySets() except ValidationError as e: logger.error(str(e)) return HttpResponseBadRequest('Bad request: ' + str(e)) except ConnectionDoesNotExist as e: logger.error(str(e)) return HttpResponseBadRequest('Bad request: Database "' + request.META['dbAlias'] + '" Does Not Exist') try: options = json.dumps(qm.generateOptions(), cls=encoders.STOQSJSONEncoder) # use_decimal=True) # After json v2.1.0 this can be used instead of the custom encoder class. except ConnectionDoesNotExist as e: logger.warn(e) return HttpResponseNotFound('The database alias <b>%s</b> does not exist on this server.' % dbAlias) ##logger.debug('options = %s', pprint.pformat(options)) ##logger.debug('len(simpledepthtime) = %d', len(json.loads(options)['simpledepthtime'])) if not fmt: # here we export in a given format, or just provide summary data if no format is given. response['Content-Type'] = 'text/json' response.write(options) elif fmt == 'json': response['Content-Type'] = 'text/json' response.write(serializers.serialize('json', qm.qs)) elif fmt == 'dap': logger.info('dap output') return response
def queryData(request, format=None): ''' Process data requests from the main query web page. Returns both summary Activity and actual MeasuredParameter data as retreived from STOQSQManager. ''' response = HttpResponse() params = {} for key, value in query_parms.iteritems(): if type(value) in (list, tuple): params[key] = [request.GET.get(p, None) for p in value] else: params[key] = request.GET.getlist(key) # Look for any parameter _MIN & _MAX input from the UI. After retrieving the above query_parms the # only thing left in the request QueryDict should be the parameter _MIN _MAX selections. for key, value in request.GET.iteritems(): if key.endswith('_MIN'): # Just test for _MIN; UI will always provide _MIN & _MAX name = key.split('_MIN')[0] try: pminmax = {name: (request.GET.getlist(name + '_MIN')[0], request.GET.getlist(name + '_MAX')[0])} except: logger.exception('Could not get parameter values even though ' + key + ' ends with _MIN') params['parametervalues'].append(pminmax) logger.debug('Adding to parametervalues: %s', pprint.pformat(pminmax)) # To support unit testing and follow-on expectation that dbAlias is in request METAdata if 'dbAlias' not in request.META: request.META['dbAlias'] = dbAlias qm = STOQSQManager(request, response, request.META['dbAlias']) logger.debug('Calling buildQuerySets with params = %s', params) try: qm.buildQuerySets(**params) except ValidationError as e: logger.error(e) return HttpResponseBadRequest('Bad request: ' + str(e)) try: options = json.dumps(qm.generateOptions(), cls=encoders.STOQSJSONEncoder) # use_decimal=True) # After json v2.1.0 this can be used instead of the custom encoder class. except ConnectionDoesNotExist, e: logger.warn(e) return HttpResponseNotFound('The database alias <b>%s</b> does not exist on this server.' % dbAlias)
def queryData(request, format=None): ''' Process data requests from the main query web page. Returns both summary Activity and actual MeasuredParameter data as retreived from STOQSQManager. ''' response = HttpResponse() params = {} for key, value in query_parms.iteritems(): if type(value) in (list, tuple): params[key] = [request.GET.get(p, None) for p in value] else: params[key] = request.GET.getlist(key) # Look for any parameter _MIN & _MAX input from the UI. After retrieving the above query_parms the # only thing left in the request QueryDict should be the parameter _MIN _MAX selections. for key, value in request.GET.iteritems(): if key.endswith( '_MIN' ): # Just test for _MIN; UI will always provide _MIN & _MAX name = key.split('_MIN')[0] try: pminmax = { name: (request.GET.getlist(name + '_MIN')[0], request.GET.getlist(name + '_MAX')[0]) } except: logger.exception( 'Could not get parameter values even though ' + key + ' ends with _MIN') params['parametervalues'].append(pminmax) logger.info('Adding to parametervalues: %s', pprint.pformat(pminmax)) qm = STOQSQManager(request, response, request.META['dbAlias']) logger.debug('Calling buildQuerySets with params = %s', params) try: qm.buildQuerySets(**params) except ValidationError, e: logger.error(e) return HttpResponseBadRequest('Bad request: ' + str(e))
def queryData(request, fmt=None): ''' Process data requests from the main query web page. Returns both summary Activity and actual MeasuredParameter data as retreived from STOQSQManager. ''' response = HttpResponse() params = {} for key, value in list(query_parms.items()): if type(value) in (list, tuple): params[key] = [request.GET.get(p, None) for p in value] else: params[key] = request.GET.getlist(key) # Look for any parameter _MIN & _MAX input from the UI. After retrieving the above query_parms the # only thing left in the request QueryDict should be the parameter _MIN _MAX selections. for key, value in list(request.GET.items()): if key.endswith( '_MIN' ): # Just test for _MIN; UI will always provide _MIN & _MAX name = key.split('_MIN')[0] try: pminmax = { name: (request.GET.getlist(name + '_MIN')[0], request.GET.getlist(name + '_MAX')[0]) } except: logger.exception( 'Could not get parameter values even though ' + key + ' ends with _MIN') params['parametervalues'].append(pminmax) logger.debug('Adding to parametervalues: %s', pprint.pformat(pminmax)) # To support unit testing and follow-on expectation that dbAlias is in request METAdata if 'dbAlias' not in request.META: request.META['dbAlias'] = dbAlias logger.debug('Instantiating STOQSQManager with params = %s', params) qm = STOQSQManager(request, response, request.META['dbAlias'], **params) try: qm.buildQuerySets() except ValidationError as e: logger.error(str(e)) return HttpResponseBadRequest('Bad request: ' + str(e)) except ConnectionDoesNotExist as e: logger.error(str(e)) return HttpResponseBadRequest('Bad request: Database "' + request.META['dbAlias'] + '" Does Not Exist') try: options = json.dumps(qm.generateOptions(), cls=encoders.STOQSJSONEncoder) except ConnectionDoesNotExist as e: logger.warn(e) return HttpResponseNotFound( 'The database alias <b>%s</b> does not exist on this server.' % dbAlias) ##logger.debug('options = %s', pprint.pformat(options)) ##logger.debug('len(simpledepthtime) = %d', len(json.loads(options)['simpledepthtime'])) if not fmt: # here we export in a given format, or just provide summary data if no format is given. response['Content-Type'] = 'text/json' response.write(options) elif fmt == 'json': response['Content-Type'] = 'text/json' response.write(serializers.serialize('json', qm.qs)) elif fmt == 'dap': logger.info('dap output') return response