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 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 From 7ebd1b87ee1d86407ac11e868c255a7613cedda3 Mon Sep 17 00:00:00 2001 From: vandersonmota Date: Fri, 18 Dec 2009 17:59:57 -0200 Subject: testsearch added --- .gitignore | 3 ++- TODO | 1 - chishop/templates/djangopypi/search.html | 2 +- chishop/templates/djangopypi/search_results.html | 4 ++-- djangopypi/tests.py | 19 +++++++++++++++++++ djangopypi/views.py | 14 +++++++------- 6 files changed, 31 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index d8e3b0d..b0a673f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ *.sqlite-journal settings_local.py .*.sw[po] +*.kpf dist/ *.egg-info doc/__build/* @@ -14,4 +15,4 @@ parts eggs bin developer-eggs -downloads \ No newline at end of file +downloads diff --git a/TODO b/TODO index 5d57eb7..f8ed064 100644 --- a/TODO +++ b/TODO @@ -11,7 +11,6 @@ PyPI feature replication I'm not sure what the difference between a co-owner and maintainer is, maybe it's just a label. * Package author admin interface (submit, edit, view) -* Search * Documentation upload * Ratings * Random Monty Python quotes :-) diff --git a/chishop/templates/djangopypi/search.html b/chishop/templates/djangopypi/search.html index a5c882c..8269508 100644 --- a/chishop/templates/djangopypi/search.html +++ b/chishop/templates/djangopypi/search.html @@ -1,4 +1,4 @@
- +
\ No newline at end of file diff --git a/chishop/templates/djangopypi/search_results.html b/chishop/templates/djangopypi/search_results.html index c2139ad..dccf61f 100644 --- a/chishop/templates/djangopypi/search_results.html +++ b/chishop/templates/djangopypi/search_results.html @@ -3,8 +3,8 @@ {% block bread_crumbs_1 %}›Search{% endblock %} {% block content %} - {% ifnotequal search_value ''%} -

Index of Packages Matching '{{ search_value }}'

+ {% ifnotequal search_term ''%} +

Index of Packages Matching '{{ search_term }}'

{% else %}

You need to supply a search term.

{% endifnotequal %} diff --git a/djangopypi/tests.py b/djangopypi/tests.py index 2d8c305..4da4122 100644 --- a/djangopypi/tests.py +++ b/djangopypi/tests.py @@ -1,6 +1,10 @@ import unittest import StringIO from djangopypi.views import parse_distutils_request +from djangopypi.models import Project, Classifier +from django.test.client import Client +from django.core.urlresolvers import reverse +from django.contrib.auth.models import User def create_post_data(action): data = { @@ -88,3 +92,18 @@ class TestParseWeirdPostData(unittest.TestCase): self.assertEquals(data[key], post.getlist(key)) else: self.assertEquals(post[key], data[key]) + +class TestSearch(unittest.TestCase): + + def setUp(self): + data = create_post_data("submit") + dummy_user = User.objects.create(username='krill', password='12345', + email='krill@opera.com') + Project.objects.create(name=data['name'], license=data['license'], + summary=data["summary"], owner=dummy_user) + + + def testSearchForPackage(self): + client = Client() + response = client.post(reverse('djangopypi-search'), {'search_term': 'foo'}) + self.assertTrue("The quick brown fox jumps over the lazy dog." in response.content) diff --git a/djangopypi/views.py b/djangopypi/views.py index 0ac6dbc..7e2d0dc 100644 --- a/djangopypi/views.py +++ b/djangopypi/views.py @@ -230,27 +230,27 @@ def show_version(request, dist_name, version, return render_to_response(template_name, context_instance=context) def search(request): - search_value = '' + search_term = '' if request.method == 'POST': - search_value = request.POST.get('search_value') - if search_value != '': - dists = Project.objects.filter(Q(name__contains=search_value) | Q(summary__contains=search_value)) + search_term = request.POST.get('search_term') + if search_term != '': + dists = Project.objects.filter(Q(name__contains=search_term) | Q(summary__contains=search_term)) return render_to_response( 'djangopypi/search_results.html', - {'dists':dists,'search_value':search_value}, + {'dists':dists,'search_term':search_term}, context_instance = RequestContext(request) ) else: dists = Project.objects.all() return render_to_response( 'djangopypi/search_results.html', - {'search_value':search_value}, + {'search_term':search_term}, context_instance = RequestContext(request) ) else: dists = Project.objects.all() return render_to_response( 'djangopypi/search_results.html', - {'search_value':search_value}, + {'search_term':search_term}, context_instance = RequestContext(request) ) \ No newline at end of file -- cgit v1.2.3