def advanced_search(request): user_group = check_user_group(request) empty = True form = AdvancedSearchForm(data = request.POST or None) tutors = [] post = False if request.method == "POST": post = True if form.is_valid(): first = form.cleaned_data['first_name'] last = form.cleaned_data['last_name'] school = form.cleaned_data['school'] subj = form.cleaned_data['subject'] proficient_area = form.cleaned_data['proficient_area'] fees = form.cleaned_data['fees'] experience = form.cleaned_data['experience'] days = form.cleaned_data['days'] cgpa = form.cleaned_data['cgpa'] if first is not "": empty = False tutors += Tutor.objects.filter(Q(user__first_name__icontains=first)).distinct() if last is not "": empty = False tutors += Tutor.objects.filter(Q(user__last_name__icontains=last)).distinct() if school is not "": empty = False tutors += Tutor.objects.filter(Q(school__school__icontains=school)).distinct() if subj is not "": empty = False tutors += Tutor.objects.filter(Q(subject__title__icontains=subj)).distinct() if days is not "": empty = False tutors += Tutor.objects.filter(Q(days__day__icontains=days)).distinct() if experience is not "": empty = False tutors += Tutor.objects.filter(Q(experience__icontains=experience)).distinct() if proficient_area is not "": empty = False tutors += Tutor.objects.filter(Q(proficient_areas__icontains=proficient_area)).distinct() if fees is not None: empty = False tutors += Tutor.objects.filter(fees_per_hour <= fees).distinct() if cgpa is not None: empty = False tutors += Tutor.objects.filter(cgpa >= cgpa).distinct() return render_to_response('tuition/advanced_search.html', {'user_group': user_group, 'current_home': "current", 'tutors':tutors, 'post':post, 'empty':empty, 'form':form}, context_instance=RequestContext(request)) ## Advanced search with specified fields... ## googlemap location preference ## tuition service ## change the model to add subjects as per schools...check if the subject entered is valid and add it to the subjects available database. ## dynamic creation of check-boxes when school is added # each school associated with courses. # then each tutor associated with each school.
def advanced_search(request, template="forum/advanced_search.html"): t = None if request.GET: f = AdvancedSearchForm(request.GET) if f.is_valid(): t = Thread.objects.all() if f.cleaned_data['searchtext']: stext = f.cleaned_data['searchtext'] t = t.filter(Q(post__text__contains=stext) | Q(title__contains=stext)) if f.cleaned_data['user']: t = t.filter(post__author__username__exact=f.cleaned_data['user']) if f.cleaned_data['solved']: t = t.filter(solved=True) t = t.distinct()[:30] else: f = AdvancedSearchForm() return render_to_response(template, { "threads": t, "form": f, }, context_instance=RequestContext(request))