|
10 | 10 | from anthill.people.forms import SearchForm, ProfileForm, PasswordForm, UserContactForm |
11 | 11 |
|
12 | 12 | def search(request): |
| 13 | + context = { 'form': SearchForm() } |
| 14 | + |
13 | 15 | if request.GET: |
14 | 16 | form = SearchForm(request.GET) |
15 | | - form.is_valid() |
16 | | - location = form.cleaned_data['location'] |
17 | | - skills = form.cleaned_data['skills'] |
18 | | - name = form.cleaned_data['name'] |
19 | | - position = form.cleaned_data['position'] |
20 | | - location_range = form.cleaned_data['location_range'] |
| 17 | + if form.is_valid(): |
| 18 | + location = form.cleaned_data['location'] |
| 19 | + skills = form.cleaned_data['skills'] |
| 20 | + name = form.cleaned_data['name'] |
| 21 | + position = form.cleaned_data['position'] |
| 22 | + location_range = form.cleaned_data['location_range'] |
21 | 23 |
|
22 | | - users = Profile.objects.all().select_related().exclude(user__id=request.user.id) |
23 | | - if skills: |
24 | | - tags = [t.strip() for t in skills.split(',')] |
25 | | - for tag in tags: |
26 | | - users = users.filter(skills__icontains=tag) |
27 | | - if position: |
28 | | - users = users.filter(role=position) |
29 | | - if name: |
30 | | - users = users.filter(user__first_name__icontains=name) |
31 | | - if location: |
32 | | - users = users.search_by_distance(location, location_range) |
33 | | - context = { 'form': form, 'searched': True, 'search_results': users } |
34 | | - else: |
35 | | - context = { 'form': SearchForm() } |
| 24 | + users = Profile.objects.all().select_related().exclude(user__id=request.user.id) |
| 25 | + if skills: |
| 26 | + tags = [t.strip() for t in skills.split(',')] |
| 27 | + for tag in tags: |
| 28 | + users = users.filter(skills__icontains=tag) |
| 29 | + if position: |
| 30 | + users = users.filter(role=position) |
| 31 | + if name: |
| 32 | + users = users.filter(user__first_name__icontains=name) |
| 33 | + if location: |
| 34 | + users = users.search_by_distance(location, location_range) |
| 35 | + context = { 'form': form, 'searched': True, 'search_results': users } |
36 | 36 |
|
37 | 37 | return render_to_response('people/search.html', context, |
38 | 38 | context_instance=RequestContext(request)) |
|
0 commit comments