Пример #1
0
def list_comments(request, return_raw_comments=False):
	terms = request.GET.get('terms', '')
	for_user = request.GET.get('foruser', '')
	
	page_title = "Latest comments on projects"
	filter_description = ""
	use_filter_description = False
	
	comments = Comment.objects.all().order_by("-pub_date")

	# For RSS feeds
	if return_raw_comments:
		return page_title, comments

	if for_user:
		for_user_obj = get_object_or_404(User, username=for_user)
		
		filter_description += "<li>user: %s</li>" % for_user
		page_title = "Latest comments for user '%s'" % for_user
		
		comments = comments.filter(author=for_user_obj)
	
	if terms:
		page_title = "Searching latest comments for '%s'" % terms
		use_filter_description = True
		query = get_query(terms, ['text',])
		comments = comments.filter(query)
	
	comments = comments.order_by('-pub_date')
	
	paginated_comments = get_paginator_page(request, comments, PROJECTS_PER_PAGE)
	
	return render_to_response('projects/comment_list.html',
			{'page_title': page_title,
			'filter_description': use_filter_description and filter_description or None,
			'search_results_type':terms and 'comments' or '',
			'search_terms':terms and terms or '',
			'paginated_comments': paginated_comments},
			context_instance=RequestContext(request))
Пример #2
0
	def search(terms):
		query = get_query(terms, ['text',])
		return Comment.objects.filter(query)
Пример #3
0
	def search(terms):
		query = get_query(terms, ['title', 'description_markdown',])
		return Project.objects.filter(query)
Пример #4
0
def list_users(request, list_type='new', return_raw_users=False):
	user = request.user
	tags = request.GET.get('tags', "")
	terms = request.GET.get('terms', "")
	
	profiles = None
	
	page_title = "People"
	filter_description = ""
	
	# Filter by tags (comes first since we use TaggedItem.objects.get_by_model)
	if list_type=='recommend':
		# Should not be called without @login_required, so we're sure we have a user
		profile = Profile.objects.get(user=user)
		user_tags = profile.get_tags()
		
		# get all profiles matching >=1 of the user's tags
		profiles = TaggedItem.objects.get_union_by_model(Profile, user_tags)
	elif tags != "":
		profiles = TaggedItem.objects.get_by_model(Profile, tags)
		filter_description += "<li>tags: %s</li>" % tags
	# or select a first crude set of results to be filtered
	else:
		profiles = Profile.objects.all()

	# Filter by search terms
	if terms != "":
		page_title = "Search results for '%s'" % terms
		query = get_query(terms, ['description_markdown','user__username'])
		profiles = profiles.filter(query)
	
	# Order results
	if list_type == 'top':
		profiles = profiles.order_by('-completed_projects_karma')
	else:
		profiles = profiles.order_by('-user__date_joined')
	
	# Prepare query string given filters, for link URLs
	qs = ""
	qs_dict = {}
	if tags:
		qs_dict['tags'] = tags
	if terms:
		qs_dict['terms'] = terms
	if qs_dict:
		qs = "?" + urllib.urlencode(qs_dict)
	
	# For RSS feeds
	if return_raw_users:
		this_page_url = "/accounts/people/" + list_type
		return page_title, this_page_url, profiles, list_type
	
	list_paginator_page = get_paginator_page(request, profiles, USERS_PER_PAGE)
	
	return render_to_response('registration/user_list.html',
			{'profile_list_page':list_paginator_page,
			'page_title': page_title,
            'list_type': list_type,
			'search_results_type':terms and 'profiles' or '',
			'search_terms':terms and terms or '',
			'filter_description': filter_description,
			'list_top_url': '/accounts/people/top/' + qs,
			'list_new_url': '/accounts/people/new/' + qs,
			'list_mytags_url': '/accounts/people/recommend/' + qs},
			context_instance=RequestContext(request))
Пример #5
0
def list_projects(request, list_type='top', is_completed=None, return_raw_projects=False):
	user = request.user
	tags = request.GET.get('tags', "")
	for_user = request.GET.get('foruser', "")
	terms = request.GET.get('terms', "")
	
	projects = None
	
	page_title = "Project list"
	filter_description = ""
	
	# Filter by tags (comes first since we use TaggedItem.objects.get_by_model)
	if list_type=='recommend':
		profile = Profile.objects.get(user=user)
		user_tags = profile.get_tags()
		
		# get all projects matching >=1 of the user's tags
		projects = TaggedItem.objects.get_union_by_model(Project, user_tags)
	elif tags != "":
		projects = TaggedItem.objects.get_by_model(Project, tags)
		filter_description += "<li>tags: %s</li>" % tags
	# or select a first crude set of results to be filtered
	else:
		projects = Project.objects.all()
	
	# Filter by completeness
	if not is_completed is None:
		if is_completed:
			page_title = "Completed projects"
			projects = projects.filter(p_completed=True, wont_be_completed=False)
		else:
			page_title = "Proposed projects"
			projects = projects.filter(p_completed=False, wont_be_completed=False)
	
	# Filter by search terms
	if terms != "":
		page_title = "Search results for '%s'" % terms
		query = get_query(terms, ['title', 'description_markdown',])
		projects = projects.filter(query)
	
	# Filter by user
	if for_user != "":
		filter_description += "<li>user: %s</li>" % for_user
		for_user_obj = get_object_or_404(User, username=for_user)
		projects = projects.filter(author=for_user_obj)
	
	# Prepare query string given filters, for link URLs
	qs = ""
	qs_dict = {}
	if tags:
		qs_dict['tags'] = tags
	if for_user:
		qs_dict['foruser'] = for_user
	if terms:
		qs_dict['terms'] = terms
	if qs_dict:
		qs = "?" + urllib.urlencode(qs_dict)
		
	top_url = '/projects/' + (is_completed and 'completed' or 'proposed') + '/top/' + qs
	new_url = '/projects/' + (is_completed and 'completed' or 'proposed') + '/new/' + qs
	mytags_url = '/projects/' + (is_completed and 'completed' or 'proposed') + '/recommend/' + qs
	this_page_url = None
	
	# Order results
	page_url = ""
	rss_url = ""
	if list_type == 'new':
		this_page_url = new_url
		rss_url = '/projects/rss/' + (is_completed and 'completed' or 'proposed') + '/new/' + qs
		projects = projects.order_by('-pub_date')
	elif list_type == 'recommend':
		this_page_url = mytags_url
	else:
		rss_url = '/projects/rss/' + (is_completed and 'completed' or 'proposed') + '/top/' + qs
		this_page_url = top_url
		if is_completed:
			projects = projects.order_by('-score_completed')
		else:
			projects = projects.order_by('-score_proposed')
	
	# For RSS feeds
	if return_raw_projects:
		return page_title, this_page_url, projects, list_type
	
	list_paginator_page = get_paginator_page(request, projects, PROJECTS_PER_PAGE)
	
	return render_to_response('projects/project_list.html',
			{'project_list_page':list_paginator_page,
			'page_title': page_title,
            'list_type': list_type,
			'filter_description': filter_description,
			# TODO: also include tags in those urls
			'list_top_url': top_url,
			'list_new_url': new_url,
			'search_results_type':terms and 'projects' or '',
			'search_terms':terms and terms or '',
			'rss_url': rss_url,
			'list_mytags_url': mytags_url},
			context_instance=RequestContext(request))