aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVinícius das Chagas Silva <vinimaster@gmail.com>2009-12-16 16:56:08 -0200
committerVinícius das Chagas Silva <vinimaster@gmail.com>2009-12-16 16:56:08 -0200
commitec281fafcaea5348675a205fbd399ad5b19a2180 (patch)
tree94209f659278a18cae6a352649af78b05656f1d1
parent10913c3ee3d5406f0e5a130d7118005f2194f8f7 (diff)
downloadchishop-ec281fafcaea5348675a205fbd399ad5b19a2180.tar.bz2
chishop-ec281fafcaea5348675a205fbd399ad5b19a2180.tar.xz
chishop-ec281fafcaea5348675a205fbd399ad5b19a2180.zip
Integrated djangopypi search engine - TODO: Functional Tests
-rw-r--r--chishop/media/style/djangopypi.css4
-rw-r--r--chishop/templates/base.html5
-rw-r--r--chishop/templates/djangopypi/search.html4
-rw-r--r--chishop/templates/djangopypi/search_results.html31
-rw-r--r--djangopypi/forms.py6
-rw-r--r--djangopypi/views.py30
6 files changed, 66 insertions, 14 deletions
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 @@
1.search {
2 text-align:right;
3 margin-right: 10px;
4} \ 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 @@
2<html xmlns="http://www.w3.org/1999/xhtml" lang="en-au" xml:lang="en-au"> 2<html xmlns="http://www.w3.org/1999/xhtml" lang="en-au" xml:lang="en-au">
3<head> 3<head>
4<link rel="stylesheet" type="text/css" href="{% block stylesheet %}{% load adminmedia %}{% admin_media_prefix %}css/base.css{% endblock %}"/> 4<link rel="stylesheet" type="text/css" href="{% block stylesheet %}{% load adminmedia %}{% admin_media_prefix %}css/base.css{% endblock %}"/>
5<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}style/djangopypi.css"/>
5{% block extrastyle %}{% endblock %} 6{% block extrastyle %}{% endblock %}
6<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 7<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
7<title>{% block title %}{% endblock %}</title> 8<title>{% block title %}{% endblock %}</title>
@@ -20,6 +21,10 @@
20 {% block site_logo %}{% endblock %} 21 {% block site_logo %}{% endblock %}
21 <h1 id="site-name">{% block site_name_header %}{% endblock %}</h1> 22 <h1 id="site-name">{% block site_name_header %}{% endblock %}</h1>
22 </div> 23 </div>
24
25 <div class="search">
26 {% include "djangopypi/search.html" %}
27 </div>
23 28
24 <div id="user-tools"> 29 <div id="user-tools">
25 {% if user.is_authenticated %} 30 {% 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 @@
1<form action='search' method='post'>
2 <input type="text" name="search_value" id="search_value">
3 <input type='submit' value=' Search '/>
4</form> \ 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 @@
1{% extends "base_site.html" %}
2
3{% block bread_crumbs_1 %}&rsaquo;Search{% endblock %}
4
5{% block content %}
6 {% ifnotequal search_value ''%}
7 <h1>Index of Packages Matching '{{ search_value }}'</h1>
8 {% else %}
9 <h1>You need to supply a search term.</h1>
10 {% endifnotequal %}
11 {% if dists %}
12 <table>
13 <thead>
14 <th>Updated</th>
15 <th>Package</th>
16 <th>Summary</th>
17 </thead>
18 <tbody>
19 {% for dist in dists %}
20 <tr>
21 <td>{{ dist.updated|date:"d/m/y" }}
22 <td><a href="{{ dist.get_pypi_absolute_url }}"/>{{ dist.name }}</a></td>
23 <td>{{ dist.summary|truncatewords:10 }}</td>
24 </tr>
25 {% endfor %}
26 </tbody>
27 </table>
28 {% else %}
29 There were no matches.
30 {% endif %}
31{% 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):
14class ReleaseForm(forms.ModelForm): 14class ReleaseForm(forms.ModelForm):
15 class Meta: 15 class Meta:
16 model = Release 16 model = Release
17 exclude = ['project'] 17 exclude = ['project'] \ No newline at end of file
18
19class SearchForm(forms.Form):
20 search_value = forms.CharField(max_length=200)
21
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
21from registration.forms import RegistrationForm 21from registration.forms import RegistrationForm
22 22
23from djangopypi.models import Project, Classifier, Release, UPLOAD_TO 23from djangopypi.models import Project, Classifier, Release, UPLOAD_TO
24from djangopypi.forms import ProjectForm, ReleaseForm, SearchForm 24from djangopypi.forms import ProjectForm, ReleaseForm
25from djangopypi.http import HttpResponseUnauthorized 25from djangopypi.http import HttpResponseUnauthorized
26from djangopypi.http import HttpResponseNotImplemented 26from djangopypi.http import HttpResponseNotImplemented
27from djangopypi.utils import decode_fs 27from djangopypi.utils import decode_fs
@@ -230,15 +230,27 @@ def show_version(request, dist_name, version,
230 return render_to_response(template_name, context_instance=context) 230 return render_to_response(template_name, context_instance=context)
231 231
232def search(request): 232def search(request):
233 search_value = ''
233 if request.method == 'POST': 234 if request.method == 'POST':
234 search_value = request.POST.get('search_value') 235 search_value = request.POST.get('search_value')
235 matches = Project.objects.get(Q(name__contains=search_value) | Q(description__contains=search_value)) 236 if search_value != '':
236 237 dists = Project.objects.filter(Q(name__contains=search_value) | Q(summary__contains=search_value))
237 return HttpResponse(matches) 238 return render_to_response(
239 'djangopypi/search_results.html',
240 {'dists':dists,'search_value':search_value},
241 context_instance = RequestContext(request)
242 )
243 else:
244 dists = Project.objects.all()
245 return render_to_response(
246 'djangopypi/search_results.html',
247 {'search_value':search_value},
248 context_instance = RequestContext(request)
249 )
238 else: 250 else:
239 search_form = SearchForm() 251 dists = Project.objects.all()
240 return render_to_response( 252 return render_to_response(
241 "djangopypi/search.html", 253 'djangopypi/search_results.html',
242 {'search_form':search_form}, 254 {'search_value':search_value},
243 context_instance=RequestContext(request) 255 context_instance = RequestContext(request)
244 ) \ No newline at end of file 256 ) \ No newline at end of file