def search(request): if 'q' in request.GET: querystring = request.GET.get('q').strip() if len(querystring) == 0: return redirect('/search/') try: search_type = request.GET.get('type') if search_type not in ['feed', 'users']: search_type = 'feed' except Exception: search_type = 'feed' count = {} results = {} results['feed'] = Feed.query(request.user, querystring) results['users'] = User.objects.filter( Q(username__icontains=querystring) | Q(screen_name__icontains=querystring)) count['feed'] = len(results['feed']) count['users'] = results['users'].count() return render( request, 'search/results.html', { 'hide_search': True, 'querystring': querystring, 'active': search_type, 'count': count, 'results': results[search_type], }) else: return render(request, 'search/search.html', {'hide_search': True})
def search(request): if 'q' in request.GET: query_string = request.GET.get('q').strip() if len(query_string) == 0: return redirect('/search/') try: search_type = request.GET.get('type') if search_type not in ['feed', 'users']: search_type = 'feed' except Exception: search_type = 'feed' feeds = Feed.query(request.user, query_string, size=FEEDS_NUM_PAGES) if feeds: from_feed = feeds[0].package_id else: from_feed = None else: query_string = None feeds = [] from_feed = None last_reload = str(datetime.datetime.now()) users_list = User.objects.filter(is_active=True).exclude( username='******').order_by('username') for i in range(len(feeds)): _, post = extract_tags(feeds[i].post) feeds[i].post = post r = render( request, 'search/search.html', { 'feeds': feeds, 'jira': imported_jira, 'from_feed': from_feed, 'last_reload': last_reload, 'page': 1, 'users': users_list, 'sharing_groups': Group.objects.all(), 'query_string': query_string, }) r.set_cookie(key='username', value=str(request.user)) return r