From 10913c3ee3d5406f0e5a130d7118005f2194f8f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20das=20Chagas=20Silva?= Date: Tue, 15 Dec 2009 19:36:08 -0200 Subject: Started search engine implementation - no totally integrated yet :( --- djangopypi/forms.py | 3 +++ djangopypi/urls.py | 5 +++-- djangopypi/views.py | 17 ++++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/djangopypi/forms.py b/djangopypi/forms.py index 5484747..6587ef0 100644 --- a/djangopypi/forms.py +++ b/djangopypi/forms.py @@ -15,4 +15,7 @@ class ReleaseForm(forms.ModelForm): class Meta: model = Release exclude = ['project'] + +class SearchForm(forms.Form): + search_value = forms.CharField(max_length=200) diff --git a/djangopypi/urls.py b/djangopypi/urls.py index d6cccb5..79b16be 100644 --- a/djangopypi/urls.py +++ b/djangopypi/urls.py @@ -19,5 +19,6 @@ urlpatterns = patterns("djangopypi.views", url(r'^(?P[\w\d_\.\-]+)/$', "show_links", {'template_name': 'djangopypi/pypi_show_links.html'}, name="djangopypi-pypi_show_links"), -) - + + url(r'^search','search',name='djangopypi-search') +) \ No newline at end of file diff --git a/djangopypi/views.py b/djangopypi/views.py index 8817f66..03b92e5 100644 --- a/djangopypi/views.py +++ b/djangopypi/views.py @@ -15,12 +15,13 @@ from django.utils.datastructures import MultiValueDict from django.utils.translation import ugettext_lazy as _ from django.core.files.uploadedfile import SimpleUploadedFile from django.contrib.auth import authenticate, login +from django.db.models import Q 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 +from djangopypi.forms import ProjectForm, ReleaseForm, SearchForm from djangopypi.http import HttpResponseUnauthorized from djangopypi.http import HttpResponseNotImplemented from djangopypi.utils import decode_fs @@ -227,3 +228,17 @@ def show_version(request, dist_name, version, }) return render_to_response(template_name, context_instance=context) + +def search(request): + 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) + else: + search_form = SearchForm() + return render_to_response( + "djangopypi/search.html", + {'search_form':search_form}, + context_instance=RequestContext(request) + ) \ No newline at end of file -- cgit v1.2.3