def noun(request, noun, debug = False): noun = noun.lstrip('+').rstrip('+') track_page_view(request) noun_query = NounExternal.objects.filter(noun = noun, status__lte = 30) if noun_query.exists(): if noun_query.count() < 100: random.choice([SearchBing, SearchGoogle]).do_next_search(noun) this_image = NounExternal.get_random_noun(noun, 30) if not this_image.image: this_image.populate() if this_image.image: if debug: return detail(request, this_image) return this_image.http_image random.choice([SearchBing, SearchGoogle]).do_next_search(noun) while True: noun_query = NounExternal.objects.filter(noun = noun, status__lte = 30) if noun_query.exists(): this_image = NounExternal.get_random_noun(noun, 30) if not this_image.image: this_image.populate() if not this_image.image: continue if debug: return detail(request, this_image) return this_image.http_image else: random.choice([SearchBing, SearchGoogle]).do_next_search(noun)