diff options
author | Ask Solem <askh@opera.com> | 2009-12-21 16:19:30 +0100 |
---|---|---|
committer | Ask Solem <askh@opera.com> | 2009-12-21 16:19:30 +0100 |
commit | 52e9fe1830e1fea5107272403547c2d0f9e0b17c (patch) | |
tree | abf6db0cfd8a7ff6368519e16949a3ec1e2abdaa | |
parent | eeec2e63e8f6b1cca8258912b763fb6407c44072 (diff) | |
parent | 7ebd1b87ee1d86407ac11e868c255a7613cedda3 (diff) | |
download | chishop-52e9fe1830e1fea5107272403547c2d0f9e0b17c.tar.bz2 chishop-52e9fe1830e1fea5107272403547c2d0f9e0b17c.tar.xz chishop-52e9fe1830e1fea5107272403547c2d0f9e0b17c.zip |
Merge branch 'viniciuschagas/master'
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | chishop/media/style/djangopypi.css | 4 | ||||
-rw-r--r-- | chishop/templates/base.html | 5 | ||||
-rw-r--r-- | chishop/templates/djangopypi/search.html | 4 | ||||
-rw-r--r-- | chishop/templates/djangopypi/search_results.html | 31 | ||||
-rw-r--r-- | djangopypi/forms.py | 3 | ||||
-rw-r--r-- | djangopypi/tests.py | 19 | ||||
-rw-r--r-- | djangopypi/urls.py | 5 | ||||
-rw-r--r-- | djangopypi/views.py | 27 |
10 files changed, 96 insertions, 6 deletions
@@ -5,6 +5,7 @@ | |||
5 | *.sqlite-journal | 5 | *.sqlite-journal |
6 | settings_local.py | 6 | settings_local.py |
7 | .*.sw[po] | 7 | .*.sw[po] |
8 | *.kpf | ||
8 | dist/ | 9 | dist/ |
9 | *.egg-info | 10 | *.egg-info |
10 | doc/__build/* | 11 | doc/__build/* |
@@ -14,4 +15,4 @@ parts | |||
14 | eggs | 15 | eggs |
15 | bin | 16 | bin |
16 | developer-eggs | 17 | developer-eggs |
17 | downloads \ No newline at end of file | 18 | downloads |
@@ -11,7 +11,6 @@ PyPI feature replication | |||
11 | I'm not sure what the difference between a co-owner and maintainer is, | 11 | I'm not sure what the difference between a co-owner and maintainer is, |
12 | maybe it's just a label. | 12 | maybe it's just a label. |
13 | * Package author admin interface (submit, edit, view) | 13 | * Package author admin interface (submit, edit, view) |
14 | * Search | ||
15 | * Documentation upload | 14 | * Documentation upload |
16 | * Ratings | 15 | * Ratings |
17 | * Random Monty Python quotes :-) | 16 | * Random Monty Python quotes :-) |
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..8269508 --- /dev/null +++ b/chishop/templates/djangopypi/search.html | |||
@@ -0,0 +1,4 @@ | |||
1 | <form action='search' method='post'> | ||
2 | <input type="text" name="search_term" id="search_term"> | ||
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..dccf61f --- /dev/null +++ b/chishop/templates/djangopypi/search_results.html | |||
@@ -0,0 +1,31 @@ | |||
1 | {% extends "base_site.html" %} | ||
2 | |||
3 | {% block bread_crumbs_1 %}›Search{% endblock %} | ||
4 | |||
5 | {% block content %} | ||
6 | {% ifnotequal search_term ''%} | ||
7 | <h1>Index of Packages Matching '{{ search_term }}'</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 5484747..6a65d37 100644 --- a/djangopypi/forms.py +++ b/djangopypi/forms.py | |||
@@ -14,5 +14,4 @@ class ProjectForm(forms.ModelForm): | |||
14 | class ReleaseForm(forms.ModelForm): | 14 | class 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 | |||
diff --git a/djangopypi/tests.py b/djangopypi/tests.py index dc71efc..44ec3ac 100644 --- a/djangopypi/tests.py +++ b/djangopypi/tests.py | |||
@@ -1,6 +1,10 @@ | |||
1 | import unittest | 1 | import unittest |
2 | import StringIO | 2 | import StringIO |
3 | from djangopypi.views import parse_distutils_request | 3 | from djangopypi.views import parse_distutils_request |
4 | from djangopypi.models import Project, Classifier | ||
5 | from django.test.client import Client | ||
6 | from django.core.urlresolvers import reverse | ||
7 | from django.contrib.auth.models import User | ||
4 | 8 | ||
5 | def create_post_data(action): | 9 | def create_post_data(action): |
6 | data = { | 10 | data = { |
@@ -89,3 +93,18 @@ class TestParseWeirdPostData(unittest.TestCase): | |||
89 | self.assertTrue(post[key] is None) | 93 | self.assertTrue(post[key] is None) |
90 | else: | 94 | else: |
91 | self.assertEquals(post[key], data[key]) | 95 | self.assertEquals(post[key], data[key]) |
96 | |||
97 | class TestSearch(unittest.TestCase): | ||
98 | |||
99 | def setUp(self): | ||
100 | data = create_post_data("submit") | ||
101 | dummy_user = User.objects.create(username='krill', password='12345', | ||
102 | email='krill@opera.com') | ||
103 | Project.objects.create(name=data['name'], license=data['license'], | ||
104 | summary=data["summary"], owner=dummy_user) | ||
105 | |||
106 | |||
107 | def testSearchForPackage(self): | ||
108 | client = Client() | ||
109 | response = client.post(reverse('djangopypi-search'), {'search_term': 'foo'}) | ||
110 | self.assertTrue("The quick brown fox jumps over the lazy dog." in response.content) | ||
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", | |||
19 | url(r'^(?P<dist_name>[\w\d_\.\-]+)/$', "show_links", | 19 | url(r'^(?P<dist_name>[\w\d_\.\-]+)/$', "show_links", |
20 | {'template_name': 'djangopypi/pypi_show_links.html'}, | 20 | {'template_name': 'djangopypi/pypi_show_links.html'}, |
21 | name="djangopypi-pypi_show_links"), | 21 | name="djangopypi-pypi_show_links"), |
22 | ) | 22 | |
23 | 23 | url(r'^search','search',name='djangopypi-search') | |
24 | ) \ No newline at end of file | ||
diff --git a/djangopypi/views.py b/djangopypi/views.py index 952b269..9c78fcf 100644 --- a/djangopypi/views.py +++ b/djangopypi/views.py | |||
@@ -15,6 +15,7 @@ from django.utils.datastructures import MultiValueDict | |||
15 | from django.utils.translation import ugettext_lazy as _ | 15 | from django.utils.translation import ugettext_lazy as _ |
16 | from django.core.files.uploadedfile import SimpleUploadedFile | 16 | from django.core.files.uploadedfile import SimpleUploadedFile |
17 | from django.contrib.auth import authenticate, login | 17 | from django.contrib.auth import authenticate, login |
18 | from django.db.models import Q | ||
18 | 19 | ||
19 | from registration.backends import get_backend | 20 | from registration.backends import get_backend |
20 | from registration.forms import RegistrationForm | 21 | from registration.forms import RegistrationForm |
@@ -227,3 +228,29 @@ def show_version(request, dist_name, version, | |||
227 | }) | 228 | }) |
228 | 229 | ||
229 | return render_to_response(template_name, context_instance=context) | 230 | return render_to_response(template_name, context_instance=context) |
231 | |||
232 | def search(request): | ||
233 | search_term = '' | ||
234 | if request.method == 'POST': | ||
235 | search_term = request.POST.get('search_term') | ||
236 | if search_term != '': | ||
237 | dists = Project.objects.filter(Q(name__contains=search_term) | Q(summary__contains=search_term)) | ||
238 | return render_to_response( | ||
239 | 'djangopypi/search_results.html', | ||
240 | {'dists':dists,'search_term':search_term}, | ||
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_term':search_term}, | ||
248 | context_instance = RequestContext(request) | ||
249 | ) | ||
250 | else: | ||
251 | dists = Project.objects.all() | ||
252 | return render_to_response( | ||
253 | 'djangopypi/search_results.html', | ||
254 | {'search_term':search_term}, | ||
255 | context_instance = RequestContext(request) | ||
256 | ) \ No newline at end of file | ||