def locations(request): if request.method == 'GET' and request.GET != {}: context = {'searchValues': request.GET} context = setConstants(context) #context['currentlocation_s'] = '*' #context['pgNum'] = pgNum if 'pgNum' in context else '1' #context['url'] = url #context['displayType'] = 'list' #context['pixonly'] = 'true' #context['title'] = TITLE # do search loginfo('start search', context, request) #context = doSearch(context) locations = getlocations(connect_string) context['locations'] = locations context['loginBtnNext'] = 'locviewer/' return render(request, 'viewLocations.html', context) else: return render(request, 'viewLocations.html', {'title': TITLE, 'pgNum': 10, 'maxresults': 20, 'imageserver': IMAGESERVER, 'loginBtnNext': 'locviewer/'})
def images(request): context = setConstants({}, prmz, request) if request.method == 'GET' and request.GET != {}: context['searchValues'] = request.GET prmz.MAXFACETS = 0 if 'keyword' in request.GET: context['keyword'] = request.GET['keyword'] if 'accession' in request.GET: context['accession'] = request.GET['accession'] context['maxresults'] = 1 context['maxresults'] = prmz.MAXRESULTS # use the grid display fields (we only show two of the required ones) context['displayType'] = 'grid' # it's an image browser, so only return items with images... context['pixonly'] = 'true' # do search loginfo('imagebrowser', 'start imagebrowser search', context, request) context = doSearch(context, prmz, request) context['additionalInfo'] = AdditionalInfo.objects.filter(live=True) return render(request, 'showImages.html', context) else: context = setConstants({}, prmz, request) context['pgNum'] = 10 context['maxresults'] = 20 return render(request, 'showImages.html', context)
def deletejob(request, filename): try: remove(getJobfile(filename)) loginfo('bmu', '%s :: %s' % ('uploadmedia job deleted', filename), {}, {}) except: loginfo('bmu', '%s :: %s' % ('ERROR: uploadmedia tried and failed to delete job', filename), {}, {}) return showqueue(request)
def checkValue(cell): try: return str(cell) except: loginfo('searchmedia', 'unicode problem: ' + cell.encode('utf-8', 'ignore'), {}, {}) return cell.encode('utf-8', 'ignore')
def get_item(request, itemid): searchfield = '' for i in prmz.FIELDS['Search']: if 'objectno' in i['fieldtype']: searchfield = i['name'] break requestObject = { searchfield: itemid, 'resultsOnly': 'true', 'displayType': 'full' } form = forms.Form(requestObject) if form.is_valid(): context = {'searchValues': requestObject} context = doSearch(context, prmz, request) if '/media/' in request.path_info: context['permalink_display'] = 'media' else: context['permalink_display'] = 'object' loginfo('permalinks', 'results.%s' % context['displayType'], context, request) return render(request, 'search.html', context)
def jsonrequest(request): if request.method == 'GET': form = forms.Form(request.GET) requestObject = request.GET if request.method == 'POST': form = forms.Form(request.POST) requestObject = request.POST if form.is_valid(): context = setconstants({}, 'json') del context['additionalInfo'] del context['extra_nav'] del context['searchrows'] del context['searchcolumns'] context = handleJSONrequest(context, requestObject) loginfo(context['appname'], context, request) #if check_json(context): # context['items'] = [] return HttpResponse(json.dumps(context, default=json_util.default)) #else: # return HttpResponse(json.dumps(dump_errors(context)) else: return HttpResponse(json.dumps({'error': 'form is not valid'}))
def csv(request): if request.method == 'POST' and request.POST != {}: requestObject = dict(request.POST.iteritems()) form = forms.Form(requestObject) if form.is_valid(): try: context = {'searchValues': requestObject} csvformat, fieldset, csvitems = setupCSV( requestObject, context, prmz) loginfo(logger, 'csv', context, request) # create the HttpResponse object with the appropriate CSV header. response = HttpResponse(content_type='text/csv') response[ 'Content-Disposition'] = 'attachment; filename="%s-%s.%s"' % ( prmz.CSVPREFIX, datetime.datetime.utcnow().strftime("%Y%m%d%H%M%S"), prmz.CSVEXTENSION) return writeCsv(response, fieldset, csvitems, writeheader=True, csvFormat=csvformat) except: messages.error(request, 'Problem creating .csv file. Sorry!') context['messages'] = messages return search(request)
def getReportparameters(filename): parms = {} csidParms = True fileFound = False try: reportXML = parse(JRXMLDIRPATTERN % filename) fileFound = True parameters = reportXML.findall('{http://jasperreports.sourceforge.net/jasperreports}parameter') #print 'parameters',parameters for p in parameters: name = p.attrib['name'] isForPrompting = p.get('isForPrompting') if name == 'csid': csidParms = False try: default = p.find('{http://jasperreports.sourceforge.net/jasperreports}defaultValueExpression').text except: default = '' try: description = p.find('{http://jasperreports.sourceforge.net/jasperreports}parameterDescription').text except: description = '' parms[name] = [default.strip('"'), isForPrompting, description.strip('"')] except: #raise # indicate that .jrxml file was not found... loginfo('ireports','jrxml file not found, no parms extracted.', {}, {}) return parms,csidParms,fileFound
def setup_solr_search(queryterms, context, prmz, request, searchterm): querystring = ' OR '.join(queryterms) context['searchValues']['querystring'] = querystring context['searchValues']['url'] = '' context['searchValues']['maxresults'] = prmz.MAXRESULTS loginfo('locationhistory', 'start location history search', context, request) return do_location_search(context, prmz, querystring, searchterm)
def postxml(requestType, uri, realm, protocol, hostname, port, username, password, payload): data = None csid = '' if port != '': port = ':' + port server = protocol + "://" + hostname + port passman = urllib.request.HTTPPasswordMgr() passman.add_password(realm, server, username, password) authhandler = urllib.request.HTTPBasicAuthHandler(passman) opener = urllib.request.build_opener(authhandler) urllib.request.install_opener(opener) url = "%s/cspace-services/%s" % (server, uri) elapsedtime = time.time() request = urllib.request.Request(url, payload.encode('utf-8'), {'Content-Type': 'application/xml'}) # default method for urllib.request with payload is POST if requestType == 'PUT': request.get_method = lambda: 'PUT' try: f = urllib.request.urlopen(request) data = f.read() info = f.info() # if a POST, the Location element contains the new CSID if info['Location']: csid = re.search(uri + '/(.*)', info['Location']).group(1) else: csid = '' except urllib.error.HTTPError as e: sys.stderr.write('URL: ' + url + '\n') sys.stderr.write('PUT/POST failed.\n') if hasattr(e, 'reason'): sys.stderr.write('Reason: ' + str(e.reason) + '\n') if hasattr(e, 'code'): sys.stderr.write('Error code: ' + str(e.code) + '\n') loginfo('csvimport', payload, {}, {}) #loginfo('csvimport', data, {}, {}) if info: loginfo('csvimport', info, {}, {}) if data: sys.stderr.write('Data: ' + data + '\n') raise except urllib.error.URLError as e: sys.stderr.write('URL: ' + url + '\n') if hasattr(e, 'reason'): sys.stderr.write('Reason: ' + str(e.reason) + '\n') if hasattr(e, 'code'): sys.stderr.write('Error code: ' + str(e.code) + '\n') if True: # loginfo('csvimport', 'Error in POSTing!', {}, {}) sys.stderr.write("Error in POSTing!\n") sys.stderr.write(payload) raise except: sys.stderr.write('Some other error' + '\n') raise elapsedtime = time.time() - elapsedtime return (url, data, csid, elapsedtime)
def skeleton(request): if request.method == 'GET' and request.GET != {}: context = {'searchValues': dict(request.GET.iteritems())} context = doSearch(context, prmz, request) else: context = setConstants({}, prmz, request) loginfo(logger, 'start search', context, request) context['additionalInfo'] = AdditionalInfo.objects.filter(live=True) return render(request, 'osteo.html', context)
def dispatch(request): if request.method == 'POST' and request.POST != {}: requestObject = request.POST form = forms.Form(requestObject) if 'csv' in request.POST or 'downloadstats' in request.POST: if form.is_valid(): try: context = {'searchValues': requestObject} csvformat, fieldset, csvitems = setupCSV( request, requestObject, context, prmz) loginfo('internal', 'csv', context, request) # create the HttpResponse object with the appropriate CSV header. response = HttpResponse(content_type='text/csv') response[ 'Content-Disposition'] = 'attachment; filename="%s-%s.%s"' % ( prmz.CSVPREFIX, datetime.datetime.utcnow().strftime("%Y%m%d%H%M%S"), prmz.CSVEXTENSION) return writeCsv(response, fieldset, csvitems, writeheader=True, csvFormat=csvformat) except: messages.error(request, 'Problem creating .csv file. Sorry!') context['messages'] = messages return search(request) elif 'pdf' in request.POST: if form.is_valid(): try: context = {'searchValues': requestObject} loginfo('internal', 'pdf', context, request) return setup4PDF(request, context, prmz) except: messages.error(request, 'Problem creating .pdf file. Sorry!') context['messages'] = messages return search(request) elif 'preview' in request.POST: messages.error(request, 'Problem creating print version. Sorry!', request) context = {'messages': messages} return search(request) else: messages.error(request, 'Un-implemented action!') context = {'messages': messages} return search(request)
def bmapper(request): if request.method == 'POST' and request.POST != {}: requestObject = request.POST form = forms.Form(requestObject) if form.is_valid(): context = {'searchValues': requestObject} context = setupBMapper(requestObject, context, adhocprmz) loginfo('adhocreports', 'bmapper', context, request) return HttpResponse(context['bmapperurl'])
def search(request): if request.method == 'GET' and request.GET != {}: context = {'searchValues': dict(request.GET.iteritems())} context = doSearch(context, adhocprmz, request) else: context = setConstants({}, adhocprmz, request) loginfo('adhocreports', 'start adhocreport', context, request) context['additionalInfo'] = AdditionalInfo.objects.filter(live=True) return render(request, 'adhocreports.html', context)
def search(request): if request.method == 'GET' and request.GET != {}: context = {'searchValues': dict(request.GET.iteritems())} context = doSearch(context, prmz, request) else: context = setConstants({}, prmz, request) loginfo(logger, 'start search', context, request) context['additionalInfo'] = AdditionalInfo.objects.filter(live=True) context['extra_nav'] = {'href': '../skeleton', 'id': 'skeleton', 'name': 'Skeleton'} return render(request, 'search.html', context)
def gmapper(request): if request.method == 'POST' and request.POST != {}: requestObject = dict(request.POST.iteritems()) form = forms.Form(requestObject) if form.is_valid(): context = {'searchValues': requestObject} context = setupGoogleMap(requestObject, context, adhocprmz) loginfo(logger, 'gmapper', context, request) return render(request, 'maps.html', context)
def get_recordtypes(): RECORDTYPES = config.get('info', 'recordtypes') try: RECORDTYPES = json.loads(RECORDTYPES.replace('\n', '')) for r in RECORDTYPES: RECORDTYPES[r].append(load_mapping_file(RECORDTYPES[r][1])) except: raise RECORDTYPES = {'configerror': ['Configuration Error', []]} loginfo('csvimport', 'Error loading mapping file', {}, {}) return RECORDTYPES
def gmapper(request): if request.method == "POST" and request.POST != {}: requestObject = dict(request.POST.iteritems()) form = forms.Form(requestObject) if form.is_valid(): context = {"searchValues": requestObject} context = setupGoogleMap(request, requestObject, context, prmz) loginfo(logger, "gmapper", context, request) return render(request, "maps.html", context)
def retrieveResults(request): if request.method == "POST" and request.POST != {}: requestObject = dict(request.POST.iteritems()) form = forms.Form(requestObject) if form.is_valid(): context = {"searchValues": requestObject} context = doSearch(context, prmz, request) loginfo(logger, "results.%s" % context["displayType"], context, request) return render(request, "searchResults.html", context)
def bmapper(request): if request.method == "POST" and request.POST != {}: requestObject = dict(request.POST.iteritems()) form = forms.Form(requestObject) if form.is_valid(): context = {"searchValues": requestObject} context = setupBMapper(request, requestObject, context, prmz) loginfo(logger, "bmapper", context, request) return HttpResponse(context["bmapperurl"])
def bmapper(request): if request.method == 'POST' and request.POST != {}: requestObject = dict(request.POST.iteritems()) form = forms.Form(requestObject) if form.is_valid(): context = {'searchValues': requestObject} context = setupBMapper(requestObject, context, prmz) loginfo(logger, 'bmapper', context, request) return HttpResponse(context['bmapperurl'])
def search(request): if request.method == "GET" and request.GET != {}: context = {"searchValues": dict(request.GET.iteritems())} context = doSearch(context, prmz, request) else: context = setConstants({}, prmz, request) loginfo(logger, "start search", context, request) context["additionalInfo"] = AdditionalInfo.objects.filter(live=True) return render(request, "search.html", context)
def retrieveResults(request): if request.method == 'POST' and request.POST != {}: requestObject = dict(request.POST.iteritems()) form = forms.Form(requestObject) if form.is_valid(): context = {'searchValues': requestObject} context = doSearch(context, prmz) loginfo(logger, 'results.%s' % context['displayType'], context, request) return render(request, 'searchResults.html', context)
def search(request): if request.method == 'GET' and request.GET != {}: context = {'searchValues': dict(request.GET.iteritems())} context = doSearch(context, prmz) else: context = setConstants({}, prmz) loginfo(logger, 'start search', context, request) context['additionalInfo'] = AdditionalInfo.objects.filter(live=True) return render(request, 'ucjeps_searchmedia.html', context)
def gmapper(request): if request.method == 'POST' and request.POST != {}: requestObject = dict(request.POST.iteritems()) form = forms.Form(requestObject) if form.is_valid(): context = {'searchValues': requestObject} context = setupGoogleMap(requestObject, context, prmz) loginfo(logger, 'gmapper', context, request) return render(request, 'maps.html', context)
def search(request): if request.method == 'GET' and request.GET != {}: context = {'searchValues': request.GET} context = doSearch(context, prmz, request) else: context = setConstants({}, prmz, request) loginfo('internal', 'start search', context, request) context['additionalInfo'] = AdditionalInfo.objects.filter(live=True) return render(request, 'search.html', context)
def retrieveResults(request): if request.method == 'POST' and request.POST != {}: requestObject = request.POST form = forms.Form(requestObject) if form.is_valid(): context = {'searchValues': requestObject} context = doSearch(context, prmz, request) loginfo('internal', 'results.%s' % context['displayType'], context, request) return render(request, 'searchResults.html', context)
def gmapper(request): if request.method == 'POST' and request.POST != {}: requestObject = request.POST form = forms.Form(requestObject) if form.is_valid(): context = {'searchValues': requestObject} context = setupGoogleMap(request, requestObject, context, prmz) loginfo('internal', 'gmapper', context, request) return render(request, 'maps.html', context)
def retrieveResults(request): if request.method == 'POST' and request.POST != {}: requestObject = dict(request.POST.iteritems()) form = forms.Form(requestObject) if form.is_valid(): context = {'searchValues': requestObject} context = doSearch(context, adhocprmz, request) loginfo(logger, 'results.%s' % context['displayType'], context, request) return render(request, 'adhocresults.html', context)
def startjob(request, filename): try: elapsedtime = time.time() context = setConstants(request, im) (jobnumber, step, csv ) = filename.split('.') context['jobnumber'] = jobnumber context['filename'] = filename runjob(jobnumber, context, request) # give the job a chance to start to ensure the queue listing is updated properly. time.sleep(2) loginfo('bmu', '%s :: %s' % ('uploadmedia online job submission requested', filename), {}, {}) except: loginfo('bmu', '%s :: %s' % ('ERROR: uploadmedia tried and failed to start job', filename), {}, {}) return showqueue(request)
def tool(request, appname): if appname == 'json': return jsonrequest(request) # if we are here, we have been given a particular appname, e.g. "keyinfo", as part of the url context = setconstants({}, appname) if request.method == 'GET': form = forms.Form(request.GET) else: form = forms.Form() if form.is_valid(): # context = dispatch(context, request.GET, appname) loginfo(appname, context, request) return render(request, 'toolbox.html', context)
def count_stats(stats, mapping): ok_count = 0 bad_count = 0 bad_values = 0 print loginfo('csvimport', '%-35s %10s %10s %-10s %10s' % tuple(stats[1][:5]), {}, {}) print for s in stats[0]: if s[3] == 'OK': ok_count += 1 loginfo('csvimport', '%-35s %10s %10s %-10s %10s' % tuple(s[:5]), {}, {}) else: bad_count += 1 loginfo('csvimport', '%-35s %10s %10s %-10s %10s' % tuple(s[:5]), {}, {}) items = s[7] for item_key in sorted(items): if items[item_key][0] != 'OK': if s[0] in mapping: if mapping[s[0]][2] == 'refname' or mapping[ s[0]][2] == 'static': label = items[item_key][0] else: label = 'invalid value:' loginfo('csvimport', ' %15s: %s' % (label, item_key), {}, {}) bad_values += 1 return ok_count, bad_count, bad_values
def validate_cell(CSPACE_MAPPING, key, values): max_problems_to_log = 4 num_problems = 0 messages = [] validated_values = {} if key in CSPACE_MAPPING: for v in values: try: isaproblem, message, validated_value = check_cell_in_cspace( CSPACE_MAPPING[key], key, v) except Exception as inst: loginfo('csvimport', inst, {}, {}) loginfo('csvimport', "problem key", key, {}, {}) loginfo('csvimport', "problem value", v.encode('utf-8'), {}, {}) loginfo('csvimport', "mapping", CSPACE_MAPPING[key], {}, {}) isaproblem, message, validated_value = 1, 'exception', v raise validated_values[v] = validated_value num_problems += isaproblem if isaproblem != 0: if num_problems > max_problems_to_log: continue else: messages.append(message) if num_problems > max_problems_to_log: messages.append('[... and %s more.]' % num_problems) else: messages = ['column ignored: not a mapped field'] valid_label = 'OK' if num_problems == 0 else 'Not OK' return valid_label, num_problems, '; '.join(messages), validated_values
def getRecords(rawFile): rawFile.seek(0) delimiters = '\t ,'.split(' ') try: # see if the sniffer can figger out the csv dialect sample = rawFile.read(4096) dialect = csv.Sniffer().sniff(sample, delimiters=',\t') rawFile.seek(0) csvfile = csv.reader(rawFile, dialect) except IOError as e: loginfo('csvimport', "item%s " % e, {}, {}) sys.exit(1) except: # nope, can't sniff: try a brute force approach, look for tabs, then commas... for delimiter in delimiters: if delimiter in sample: rawFile.seek(0) csvfile = csv.reader(rawFile, delimiter=delimiter) break try: rows = [] cell_values = {} bad_rows = ['rows have different number of cells', 0, []] for rowNumber, row in enumerate(csvfile): if rowNumber == 0: header = row continue rows.append(row) if len(row) != len(header): bad_rows[1] += 1 bad_rows[2].append(rowNumber + 1) raise Exception( 'row and header have different number of columns %s' % str(rowNumber + 1)) for col_number, cell in enumerate(row): if cell == "#": continue # skip comments col_name = header[col_number] cell_values.setdefault(col_name, {}) if not row[col_number] in cell_values[col_name]: cell_values[col_name][row[col_number]] = 0 #cell_values[col_name]['bcid'] = row[0] cell_values[col_name][row[col_number]] += 1 return cell_values, rows, rowNumber, header, bad_rows except IOError as e: loginfo('csvimport', "item%s " % e, {}, {}) sys.exit(1) except: raise
def skeleton(request): if request.method == 'GET' and request.GET != {}: # context = {'searchValues': dict(request.GET.iteritems())} aggregate, search_keys = gatherosteoparms(dict(request.GET.iteritems())) requestObject = {'querystring': (' OR '.join(aggregate)), 'url': 'url', 'special': 'true'} context = {'searchValues': requestObject} context['aggregate'] = search_keys context = doSearch(context, prmz, request) else: context = setConstants({}, prmz, request) loginfo(logger, 'start skeleton search', context, request) context['additionalInfo'] = AdditionalInfo.objects.filter(live=True) context['extra_nav'] = {'href': '../search', 'id': 'search', 'name': 'Metadata Search'} return render(request, 'osteo.html', context)
def get_item(request, itemid): searchfield = '' for i in prmz.FIELDS['Search']: if 'objectno' in i['fieldtype']: searchfield = i['name'] break requestObject = {searchfield: itemid, 'resultsOnly': 'true', 'displayType': 'full'} form = forms.Form(requestObject) if form.is_valid(): context = {'searchValues': requestObject} context = doSearch(context, prmz, request) loginfo(logger, 'results.%s' % context['displayType'], context, request) return render(request, 'search.html', context)
def bmapper(request): if request.method == 'POST' and request.POST != {}: requestObject = request.POST form = forms.Form(requestObject) if form.is_valid(): context = {'searchValues': requestObject} if 'kml' in request.path: response = setupKML(request, requestObject, context, prmz) loginfo('internal', 'kml', context, request) return response else: context = setupBMapper(request, requestObject, context, prmz) loginfo('internal', 'bmapper', context, request) return HttpResponse(context['bmapperurl'])
def get_special(label, labels, row): # handle some special cases if label == 'default' and 'default' in row[labels['Role']]: x = row[labels['Role']].split(',') role= x[0] default = x[1].split('=')[1] row[labels['Role']] = [role, label, default] return value = row[labels['Role']] if label in value: parsed_valued = value.replace('%s=' % label,'') try: values = loads(parsed_valued) row[labels['Role']] = [label, values] except: loginfo('search startup', 'could not parse JSON for %s: %s' % (value,parsed_valued), {}, {})
def index(request): context = setConstants({}, prmz) # http://blog.mobileesp.com/ # the middleware must be installed for the following to work... if request.is_phone: context['device'] = 'phone' elif request.is_tablet: context['device'] = 'tablet' else: context['device'] = 'other' if request.method == 'GET': context['searchValues'] = request.GET prmz.MAXFACETS = 0 if 'keyword' in request.GET: context['keyword'] = request.GET['keyword'] if 'accession' in request.GET: context['accession'] = request.GET['accession'] context['maxresults'] = 1 if 'submit' in request.GET: context['maxresults'] = prmz.MAXRESULTS if "Metadata" in request.GET['submit']: context['resultType'] = 'metadata' context['displayType'] = 'full' elif "Images" in request.GET['submit']: context['resultType'] = 'images' context['pixonly'] = 'true' context['displayType'] = 'grid' elif "Lucky" in request.GET['submit']: context['resultType'] = 'metadata' context['maxresults'] = 1 else: context['resultType'] = 'metadata' # do search loginfo(logger, 'start imaginator search', context, request) context = doSearch(context, prmz) context['additionalInfo'] = AdditionalInfo.objects.filter(live=True) return render(request, 'imagineImages.html', context) else: return render(request, 'imagineImages.html', context)
def dispatch(request): if request.method == 'POST' and request.POST != {}: requestObject = dict(request.POST.iteritems()) form = forms.Form(requestObject) if 'csv' in request.POST or 'downloadstats' in request.POST: if form.is_valid(): try: context = {'searchValues': requestObject} csvformat, fieldset, csvitems = setupCSV(request, requestObject, context, prmz) loginfo(logger, 'csv', context, request) # create the HttpResponse object with the appropriate CSV header. response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename="%s-%s.%s"' % ( prmz.CSVPREFIX, datetime.datetime.utcnow().strftime("%Y%m%d%H%M%S"), prmz.CSVEXTENSION) return writeCsv(response, fieldset, csvitems, writeheader=True, csvFormat=csvformat) except: messages.error(request, 'Problem creating .csv file. Sorry!') context['messages'] = messages return search(request) elif 'pdf' in request.POST: if form.is_valid(): try: context = {'searchValues': requestObject} loginfo(logger, 'pdf', context, request) return setup4PDF(request, context, prmz) except: messages.error(request, 'Problem creating .pdf file. Sorry!') context['messages'] = messages return search(request) elif 'preview' in request.POST: messages.error(request, 'Problem creating print version. Sorry!') context = {'messages': messages} return search(request) else: messages.error(request, 'Un-implemented action!') context = {'messages': messages} return search(request)
def statistics(request): if request.method == 'POST' and request.POST != {}: requestObject = dict(request.POST.iteritems()) form = forms.Form(requestObject) if form.is_valid(): elapsedtime = time.time() try: context = {'searchValues': requestObject} loginfo(logger, 'statistics1', context, request) context = computeStats(requestObject, context, prmz) loginfo(logger, 'statistics2', context, request) context['summarytime'] = '%8.2f' % (time.time() - elapsedtime) # 'downloadstats' is handled in writeCSV, via post return render(request, 'statsResults.html', context) except: context['summarytime'] = '%8.2f' % (time.time() - elapsedtime) return HttpResponse('Please pick some values!')
def statistics(request): if request.method == "POST" and request.POST != {}: requestObject = dict(request.POST.iteritems()) form = forms.Form(requestObject) if form.is_valid(): elapsedtime = time.time() try: context = {"searchValues": requestObject} loginfo(logger, "statistics1", context, request) context = computeStats(request, requestObject, context, prmz) loginfo(logger, "statistics2", context, request) context["summarytime"] = "%8.2f" % (time.time() - elapsedtime) # 'downloadstats' is handled in writeCSV, via post return render(request, "statsResults.html", context) except: context["summarytime"] = "%8.2f" % (time.time() - elapsedtime) return HttpResponse("Please pick some values!")
def retrieveJSON(request): if request.method == 'GET' and request.GET != {}: requestObject = dict(request.GET.iteritems()) form = forms.Form(requestObject) if form.is_valid(): context = {'searchValues': requestObject} context = doSearch(context, prmz, request) loginfo(logger, 'results.%s' % context['displayType'], context, request) #del context['FIELDS'] #del context['facets'] if not 'items' in context: return HttpResponse(json.dumps('error')) else: return HttpResponse(json.dumps({'items': context['items'],'labels': context['labels']})) else: return HttpResponse(json.dumps('no data seen'))
def dispatch(request): if request.method == "POST" and request.POST != {}: requestObject = dict(request.POST.iteritems()) form = forms.Form(requestObject) if "csv" in request.POST or "downloadstats" in request.POST: if form.is_valid(): try: context = {"searchValues": requestObject} csvformat, fieldset, csvitems = setupCSV(request, requestObject, context, prmz) loginfo(logger, "csv", context, request) # create the HttpResponse object with the appropriate CSV header. response = HttpResponse(content_type="text/csv") response["Content-Disposition"] = 'attachment; filename="%s-%s.%s"' % ( prmz.CSVPREFIX, datetime.datetime.utcnow().strftime("%Y%m%d%H%M%S"), prmz.CSVEXTENSION, ) return writeCsv(response, fieldset, csvitems, writeheader=True, csvFormat=csvformat) except: messages.error(request, "Problem creating .csv file. Sorry!") context["messages"] = messages return search(request) elif "pdf" in request.POST: if form.is_valid(): try: context = {"searchValues": requestObject} loginfo(logger, "pdf", context, request) return setup4PDF(request, context, prmz) except: messages.error(request, "Problem creating .pdf file. Sorry!") context["messages"] = messages return search(request) elif "preview" in request.POST: messages.error(request, "Problem creating print version. Sorry!") context = {"messages": messages} return search(request)
def images(request): context = setConstants({}, prmz, request) # http://blog.mobileesp.com/ # the middleware must be installed for the following to work... if request.is_phone: context['device'] = 'phone' elif request.is_tablet: context['device'] = 'tablet' else: context['device'] = 'other' if request.method == 'GET' and request.GET != {}: context['searchValues'] = request.GET prmz.MAXFACETS = 0 if 'keyword' in request.GET: context['keyword'] = request.GET['keyword'] if 'accession' in request.GET: context['accession'] = request.GET['accession'] context['maxresults'] = 1 context['maxresults'] = prmz.MAXRESULTS # use the grid display fields (we only show two of the required ones) context['displayType'] = 'grid' # it's an image browser, so only return items with images... context['pixonly'] = 'true' # do search loginfo(logger, 'start imagebrowser search', context, request) context = doSearch(context, prmz, request) context['additionalInfo'] = AdditionalInfo.objects.filter(live=True) return render(request, 'showImages.html', context) else: context = setConstants({}, prmz, request) context['pgNum'] = 10 context['maxresults'] = 20 return render(request, 'showImages.html', context)
def index(request): context = setConstants({}, prmz, request) if request.method == 'GET': context['searchValues'] = request.GET prmz.MAXFACETS = 0 if 'keyword' in request.GET: context['keyword'] = request.GET['keyword'] if 'accession' in request.GET: context['accession'] = request.GET['accession'] context['maxresults'] = 1 if 'submit' in request.GET: context['maxresults'] = prmz.MAXRESULTS if "Metadata" in request.GET['submit']: context['resultType'] = 'metadata' context['displayType'] = 'full' elif "Images" in request.GET['submit']: context['resultType'] = 'images' context['pixonly'] = 'true' context['displayType'] = 'grid' elif "Lucky" in request.GET['submit']: context['resultType'] = 'metadata' context['maxresults'] = 1 else: context['resultType'] = 'metadata' # do search loginfo(logger, 'start imaginator search', context, request) context = doSearch(context, prmz, request) context['additionalInfo'] = AdditionalInfo.objects.filter(live=True) return render(request, 'imagineImages.html', context) else: return render(request, 'imagineImages.html', context)
def loadNewFields(request, fieldfile, prmz): loadFields(fieldfile + '.csv', prmz) context = setConstants({}, prmz) loginfo(logger, 'loaded fields', context, request) return render(request, 'search.html', context)
def setup_solr_search(queryterms, context, prmz, request): context['searchValues']['querystring'] = ' OR '.join(queryterms) context['searchValues']['url'] = '' context['searchValues']['maxresults'] = prmz.MAXRESULTS loginfo(logger, 'start grouper search', context, request) return doSearch(context, prmz, request)
def loadNewFields(request, fieldfile, prmx): loadFields(fieldfile + ".csv", prmx) context = setConstants({}, prmx, request) loginfo(logger, "loaded fields", context, request) return render(request, "search.html", context)