def home(request): featured_badges = map(fetch_badge_resources, badge_api.get_featured_badges()) users = p2pu_user_api.get_users() paginator = Paginator(users, 16) page = request.GET.get('page') try: users = paginator.page(page) except PageNotAnInteger: users = paginator.page(1) except EmptyPage: return HttpResponse(status=404) if request.is_ajax(): return render_to_response('p2pu_user/browse_users.html', {'users': users}, context_instance=RequestContext(request)) last_n_projects = project_api.last_n_projects(10) for project in last_n_projects: fetch_project_resources(project, feedback_list=project_api.get_project_feedback(project['uri'])) return render_to_response('landing/home.html', { 'badges': featured_badges, 'users': users, 'projects': last_n_projects, }, context_instance=RequestContext(request))
def search_projects(text): query = Q(title__icontains=text) | \ Q(image_uri__icontains=text) | \ Q(work_url__icontains=text) | \ Q(description__icontains=text) | \ Q(reflection__icontains=text) | \ Q(tags__icontains=text) | \ Q(badge_uri__icontains=text) | \ Q(author_uri__icontains=text) projects = project_api.Project.objects.filter(query, date_deleted__isnull=True) \ .order_by('title').distinct().all() projects_val = [] for project in projects: projects_val.append(fetch_project_resources(project_api._project2dict(project))) return projects_val