From ec281fafcaea5348675a205fbd399ad5b19a2180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20das=20Chagas=20Silva?= Date: Wed, 16 Dec 2009 16:56:08 -0200 Subject: Integrated djangopypi search engine - TODO: Functional Tests --- chishop/media/style/djangopypi.css | 4 +++ chishop/templates/base.html | 5 ++++ chishop/templates/djangopypi/search.html | 4 +++ chishop/templates/djangopypi/search_results.html | 31 ++++++++++++++++++++++++ djangopypi/forms.py | 6 +---- djangopypi/views.py | 30 ++++++++++++++++------- 6 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 chishop/media/style/djangopypi.css create mode 100644 chishop/templates/djangopypi/search.html create mode 100644 chishop/templates/djangopypi/search_results.html diff --git a/chishop/media/style/djangopypi.css b/chishop/media/style/djangopypi.css new file mode 100644 index 0000000..e6fbfd9 --- /dev/null +++ b/chishop/media/style/djangopypi.css @@ -0,0 +1,4 @@ +.search { + text-align:right; + margin-right: 10px; +} \ No newline at end of file diff --git a/chishop/templates/base.html b/chishop/templates/base.html index 76483ce..dd797e7 100644 --- a/chishop/templates/base.html +++ b/chishop/templates/base.html @@ -2,6 +2,7 @@ + {% block extrastyle %}{% endblock %} {% block title %}{% endblock %} @@ -20,6 +21,10 @@ {% block site_logo %}{% endblock %}

{% block site_name_header %}{% endblock %}

+ +
{% if user.is_authenticated %} diff --git a/chishop/templates/djangopypi/search.html b/chishop/templates/djangopypi/search.html new file mode 100644 index 0000000..a5c882c --- /dev/null +++ b/chishop/templates/djangopypi/search.html @@ -0,0 +1,4 @@ +
+ + +
\ No newline at end of file diff --git a/chishop/templates/djangopypi/search_results.html b/chishop/templates/djangopypi/search_results.html new file mode 100644 index 0000000..c2139ad --- /dev/null +++ b/chishop/templates/djangopypi/search_results.html @@ -0,0 +1,31 @@ +{% extends "base_site.html" %} + +{% block bread_crumbs_1 %}›Search{% endblock %} + +{% block content %} + {% ifnotequal search_value ''%} +

Index of Packages Matching '{{ search_value }}'

+ {% else %} +

You need to supply a search term.

+ {% endifnotequal %} + {% if dists %} + + + + + + + + {% for dist in dists %} + + + + + {% endfor %} + +
UpdatedPackageSummary
{{ dist.updated|date:"d/m/y" }} + {{ dist.name }}{{ dist.summary|truncatewords:10 }}
+ {% else %} + There were no matches. + {% endif %} +{% endblock content %} \ No newline at end of file diff --git a/djangopypi/forms.py b/djangopypi/forms.py index 6587ef0..6a65d37 100644 --- a/djangopypi/forms.py +++ b/djangopypi/forms.py @@ -14,8 +14,4 @@ class ProjectForm(forms.ModelForm): class ReleaseForm(forms.ModelForm): class Meta: model = Release - exclude = ['project'] - -class SearchForm(forms.Form): - search_value = forms.CharField(max_length=200) - + exclude = ['project'] \ No newline at end of file diff --git a/djangopypi/views.py b/djangopypi/views.py index 03b92e5..0ac6dbc 100644 --- a/djangopypi/views.py +++ b/djangopypi/views.py @@ -21,7 +21,7 @@ from registration.backends import get_backend from registration.forms import RegistrationForm from djangopypi.models import Project, Classifier, Release, UPLOAD_TO -from djangopypi.forms import ProjectForm, ReleaseForm, SearchForm +from djangopypi.forms import ProjectForm, ReleaseForm from djangopypi.http import HttpResponseUnauthorized from djangopypi.http import HttpResponseNotImplemented from djangopypi.utils import decode_fs @@ -230,15 +230,27 @@ def show_version(request, dist_name, version, return render_to_response(template_name, context_instance=context) def search(request): + search_value = '' if request.method == 'POST': search_value = request.POST.get('search_value') - matches = Project.objects.get(Q(name__contains=search_value) | Q(description__contains=search_value)) - - return HttpResponse(matches) + if search_value != '': + dists = Project.objects.filter(Q(name__contains=search_value) | Q(summary__contains=search_value)) + return render_to_response( + 'djangopypi/search_results.html', + {'dists':dists,'search_value':search_value}, + context_instance = RequestContext(request) + ) + else: + dists = Project.objects.all() + return render_to_response( + 'djangopypi/search_results.html', + {'search_value':search_value}, + context_instance = RequestContext(request) + ) else: - search_form = SearchForm() + dists = Project.objects.all() return render_to_response( - "djangopypi/search.html", - {'search_form':search_form}, - context_instance=RequestContext(request) - ) \ No newline at end of file + 'djangopypi/search_results.html', + {'search_value':search_value}, + context_instance = RequestContext(request) + ) \ No newline at end of file -- cgit v1.2.3