Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:brack3t/djangopeople.me

  • Loading branch information...
commit bb3252bf8256c99ea3f30f402fb98e7f222204ab 2 parents 0d7b712 + 59b0a0b
@kennethlove kennethlove authored
Showing with 15 additions and 11 deletions.
  1. +3 −2 dp/generic/templates/generic/search.html
  2. +12 −9 dp/generic/views.py
View
5 dp/generic/templates/generic/search.html
@@ -13,9 +13,9 @@
{% crispy form %}
</div>
<div class="span8" id="searchResults">
+ {% if object_list %}
<h1>Results</h1>
- {% if users %}
- {% for user in users %}
+ {% for user in object_list %}
{% if units == "mi" %}
<p>{{ user.user.first_name }} - {{ user.distance.mi }}</p>
{% else %}
@@ -25,6 +25,7 @@
{% endif %}
</div>
</div>
+{% include "_partials/_pagination.html" %}
{% endblock %}
{% block extra_js %}
View
21 dp/generic/views.py
@@ -4,7 +4,7 @@
from django.contrib.gis.measure import D
from django.views.generic import RedirectView, TemplateView, FormView
-from braces.views import LoginRequiredMixin, SelectRelatedMixin
+from braces.views import LoginRequiredMixin
from generic.forms import SearchForm
from generic.geocoder import Geocoder
@@ -31,34 +31,37 @@ def get(self, request, *args, **kwargs):
class SearchView(FormView):
form_class = SearchForm
+ model = UserProfile
template_name = "generic/search.html"
- point = u"POINT(%s %s)" % (-115.300516,36.136818)
def form_valid(self, form):
location = form.cleaned_data["location"]
distance = form.cleaned_data["distance"]
units = form.cleaned_data["units"]
skills = form.cleaned_data.get("skills", None)
- skills = [s.strip() for s in skills.split(",")]
+
+ if skills:
+ skills = [s.strip() for s in skills.split(",")]
+
point = Geocoder().mapquest_geocode(location)
if point["status"]:
- qs = UserProfile.objects.select_related("user").exclude(
+ queryset = self.model.objects.select_related("user").exclude(
point__isnull=True).distance(point["point"])
if units == "km":
- qs = qs.filter(point__distance_lte=(
+ queryset = queryset.filter(point__distance_lte=(
point["point"], D(km=distance)
))
else:
- qs = qs.filter(point__distance_lte=(
+ queryset = queryset.filter(point__distance_lte=(
point["point"], D(mi=distance)
))
- qs = qs.order_by("distance")
- qs = self._filter_by_skills(qs, skills)
+ queryset = queryset.order_by("distance")
+ queryset = self._filter_by_skills(queryset, skills)
- return self.render_to_response({"users": qs, "form": form,
+ return self.render_to_response({"object_list": queryset, "form": form,
"units": units})
def _filter_by_skills(self, queryset, skills):
Please sign in to comment.
Something went wrong with that request. Please try again.