Exemplo n.º 1
0
def search(request):
  if request.GET:
    query = request.GET['term']
    offset = request.GET['offset']
  else:
    return HttpResponseRedirect("/")


  # Replace all runs of whitespace with a single +
  # query = re.sub(r"\s+", '+', query)
  query = urllib2.quote(query)
  results = s.getList(query, offset,  'name', 'image', 'original_release_date', \
    'deck', 'id', 'site_detail_url')
  if results == None:
    return render_to_response('staticpages/no_game_found.html')
  for x in results:
    x['number_of_listing'] = Currentlist.objects.filter(giantBombID=x['id'], status = 'open').count()
  if x['number_of_listing'] == None:
    x['number_of_listing'] = 0
    
  previous=int(int(offset)-10)
  if previous == -10:
    previous=-1;
  
  next=int(int(offset)+10)
  if len(results) != 10:
    next=-1;
  
  return render(request, 'search_page.html', 
  {'results':results,
  'query':query,
  'previous':previous,
  'next':next
  })
Exemplo n.º 2
0
def get_request(request):
  if request.is_ajax():
    inputString=urllib2.quote(request.GET.get('term'))
    games = s.getList(inputString, 0, 'id', 'name')
    results = []
    for game in games:
      game_json={}
      game_json['id']=game['id']
      game_json['value']=game['name'] 
      game_json['label']=game['name']
      results.append(game_json)
    message=json.dumps(results)
  else:
    message="Not AJAX"
  return HttpResponse(message)
Exemplo n.º 3
0
import search as s
print 'Testing search on just name'
print s.getList('assassin', 'name') 
print '\n'
game = s.getList('halo', 'name', 'id') 
print '\n'
print s.getList('halo', 'name', 'id')
print '\n'
id = game['Halo Wars']['id']
print game.keys()
print 'accessing the search result \'Halo Zero\' to get id=' + id 
print '\n'
print 'Using Id to test get game details'
print s.getGameDetsById(id, 'name', 'id', 'original_release_date', 'deck' )
id = '123215431464257'
print s.getGameDetsById(id, 'name', 'id', 'original_release_date', 'deck' )