示例#1
0
def details_view(request):
	slug = request.matchdict['slug']
	item = {}
	error = None

	try:
		item = get_api().person(slug).get()['result']

		item['positions'] = {}
		positions = get_api().position().get(person = item['_id'])['results']
		for p in positions:
			item['positions'][p['title']] = get_api().organisation(p['organisation']).get()['result']
	except ConnectionError, e:
		log.warn(e)
		error = e
示例#2
0
def results_view(request):
	query = request.matchdict['query']
	results = []
	error = None

	qp = QueryParser()
	parsed = qp.parse(query)

	try:
		if parsed.has_key('slug'):
			res = {'name': 'Slug', 'data': []}
			if len(parsed['slug']) == 1:
				url = request.route_url('details', slug=parsed['slug'][0])
				return HTTPFound(location=url)
			for slug in parsed['slug']:
				res['data'].append(get_api().person(slug).get()['result'])
			results.append(res);

		elif parsed.has_key('word') and 'all' in parsed['word']:
			res = {'name': 'All', 'data': []}
			res['data'] = get_api().person.get()['results']
			if res['data']:
				results.append(res)
            
		elif parsed.has_key('word'):
			name = {'name': 'Name', 'data': []}
			summary = {'name': 'Summary', 'data': []}
			for q in parsed['word']:
				name['data'] += get_api().person().get(name=q)['results']
				summary['data'] += get_api().person().get(summary=q)['results']
			#summary['data'] = list(imap(sub, summary['data'], name['data']))
			summary['data'] = [x for x in summary['data'] if x not in name['data']] # summary without items from name

			if name['data']:
				results.append(name)
			if summary['data']:
				results.append(summary)

	except ConnectionError, e:
		log.warn(e)
		error = "ConnectionError. The PopIt API is currently not available."
示例#3
0
def api_view(request):
	url = get_api().get_url()
	version = get_api().get_api_version()
	online = get_api().is_online()
	return dict(error = None, version = version, url = url, online = online)