Esempio n. 1
0
def people(request):
	if request.method == 'POST':
		form = MultiProfileDisplay(request.POST, request.FILES)
		if form.is_valid():
			cleaned_data = form.clean()
			filterText = cleaned_data['filters']
			if filterText == "None":
				users = UserData.objects.all()
			else:
				chosenFilter = Filter.objects.filter(name=filterText)
				users = UserData.objects.filter(filters__id=chosenFilter)
			form = MultiProfileDisplay()
	else:
		users = UserData.objects.all().order_by("user")
		form = MultiProfileDisplay()
		filterText = "None"
	return render(request, 'MultiProfileDisplay.html', {'users':users, 'form':form, 'filterText': filterText})
Esempio n. 2
0
def people(request):
	if request.user.is_authenticated():
		if request.method == 'POST':
			if 'username' in request.POST:
				form = MultiProfileDisplay(request.POST)
				if form.is_valid():
					cleaned_data = form.clean()
					user_name = cleaned_data['username']

					#username follows form "first.last"
					username = '******'.join(user_name.lower().split())
					return HttpResponseRedirect('/profile/'+username+'/')

			elif 'filternames' in request.POST:
				form = SortByFilter(request.POST)
				if form.is_valid():
					try:
						cleaned_data = form.clean()
						filterName = cleaned_data['filternames']
						filterName = re.split(' - ', filterName, 1)
						filterText, filterType = filterName[1], filterName[0]
						chosenFilter = Filter.objects.filter(name=filterText, helpfilter=filterType)
						users = UserData.objects.filter(filters__id=chosenFilter).order_by("user")
						form = MultiProfileDisplay()
						form2 = SortByFilter()
						filterText = "None"
						return render(request, 'MultiProfileDisplay.html', {'users':users, 'form':form, 'filterText': filterText, 'form2':form2})
					except:
						return HttpResponseRedirect('/people/')
		else:
		
			#query database for list of all users and redisplay the same page.
			users = UserData.objects.all().order_by("user")
			form = MultiProfileDisplay()
			form2 = SortByFilter()
			filterText = "None"
		return render(request, 'MultiProfileDisplay.html', {'users':users, 'form':form, 'filterText': filterText, 'form2':form2})
	else:
		return HttpResponseRedirect('/login/')