From ccf2d18dc368c2070042842ca1d3d7fb30037a91 Mon Sep 17 00:00:00 2001 From: Luan Date: Thu, 17 Oct 2013 17:10:51 -0300 Subject: [PATCH] Fixing home and removing old search --- src/colab/deprecated/views/other.py | 24 +++++++++++++++++++----- src/colab/urls.py | 13 +------------ src/search/forms.py | 2 +- src/search/urls.py | 14 ++++++++++++++ src/search/views.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/templates/home.html | 6 +++--- src/templates/search/preview-search.html | 16 +++++++++++++--- 7 files changed, 108 insertions(+), 26 deletions(-) create mode 100644 src/search/urls.py diff --git a/src/colab/deprecated/views/other.py b/src/colab/deprecated/views/other.py index 7e731d9..f244c06 100644 --- a/src/colab/deprecated/views/other.py +++ b/src/colab/deprecated/views/other.py @@ -6,12 +6,16 @@ other.py Created by Sergio Campos on 2012-01-10. """ +import datetime + from django.template import RequestContext from django.http import HttpResponseNotAllowed from django.shortcuts import render_to_response +from django.utils import timezone from django.utils.translation import ugettext as _ -from colab.deprecated import solrutils +from haystack.query import SearchQuerySet + from super_archives import queries @@ -21,11 +25,21 @@ def home(request): latest_threads = queries.get_latest_threads() hottest_threads = queries.get_hottest_threads() + count_types = {} + six_months = timezone.now() - datetime.timedelta(days=180) + for type in ['wiki', 'thread', 'changeset', 'ticket']: + count_types[type] = SearchQuerySet().filter( + type=type, + modified__gte=six_months, + ).count() + template_data = { 'hottest_threads': hottest_threads[:6], 'latest_threads': latest_threads[:6], - 'type_count': solrutils.count_types(sample=1000), - 'latest_docs': solrutils.get_latest_collaborations(6), + 'type_count': count_types, + 'latest_results': SearchQuerySet().all().order_by( + '-modified', '-created' + )[:6], } return render_to_response('home.html', template_data, context_instance=RequestContext(request)) @@ -34,7 +48,7 @@ def home(request): def search(request): if request.method != 'GET': return HttpResponseNotAllowed(['GET']) - + query = request.GET.get('q') sort = request.GET.get('o') type_ = request.GET.get('type') @@ -42,7 +56,7 @@ def search(request): page_number = int(request.GET.get('p', '1')) except ValueError: page_number = 1 - + try: results_per_page = int(request.GET.get('per_page', 16)) except ValueError: diff --git a/src/colab/urls.py b/src/colab/urls.py index d249c47..3c1bf67 100644 --- a/src/colab/urls.py +++ b/src/colab/urls.py @@ -1,11 +1,7 @@ - from django.conf.urls import patterns, include, url from django.conf import settings from django.views.generic import TemplateView from django.contrib import admin -from haystack.forms import ModelSearchForm -from haystack.query import SearchQuerySet -from haystack.views import SearchView from accounts.models import User from search.forms import ColabSearchForm @@ -17,14 +13,7 @@ admin.autodiscover() urlpatterns = patterns('', url(r'^$', 'colab.deprecated.views.other.home', name='home'), - # TODO change search to full_search with haystack - url(r'^search/$', 'colab.deprecated.views.other.search', name='search'), - url(r'^full_search/', SearchView( - template='search/search.html', - searchqueryset=SearchQuerySet(), - form_class=ColabSearchForm, - ), name='haystack_search'), - + url(r'^search/', include('search.urls')), url(r'open-data/$', TemplateView.as_view(template_name='open-data.html'), name='opendata'), diff --git a/src/search/forms.py b/src/search/forms.py index 95b37df..4eaebe7 100644 --- a/src/search/forms.py +++ b/src/search/forms.py @@ -12,7 +12,7 @@ from super_archives.models import Message class ColabSearchForm(SearchForm): - q = forms.CharField(label=_('Search')) + q = forms.CharField(label=_('Search'), required=False) order = forms.CharField(widget=forms.HiddenInput(), required=False) type = forms.CharField(required=False, label=_(u'Type')) diff --git a/src/search/urls.py b/src/search/urls.py new file mode 100644 index 0000000..0139e86 --- /dev/null +++ b/src/search/urls.py @@ -0,0 +1,14 @@ +from django.conf.urls import patterns, include, url +from haystack.query import SearchQuerySet + +from .forms import ColabSearchForm +from .views import ColabSearchView + + +urlpatterns = patterns('', + url(r'^$', ColabSearchView( + template='search/search.html', + searchqueryset=SearchQuerySet(), + form_class=ColabSearchForm, + ), name='haystack_search'), +) diff --git a/src/search/views.py b/src/search/views.py index 91ea44a..56f3e99 100644 --- a/src/search/views.py +++ b/src/search/views.py @@ -1,3 +1,58 @@ -from django.shortcuts import render +# -*- coding:utf-8 -*- -# Create your views here. +from django.conf import settings +from haystack.views import SearchView + + +class ColabSearchView(SearchView): + def extra_context(self, *args, **kwargs): + # Retornar todos os campos de cada tipo a serem filtrados + # retornar os nomes dos campos + # retornar os ícones dos tipos + + # a critical point on the system + types = { + 'wiki': { + 'icon': 'file', + 'fields': [ + 'title', 'description', 'author', 'collaborators', + 'created', 'modified', + ], + }, + 'discussion': { + 'icon': 'thread', + 'fields': [ + 'title', 'description', 'created', 'modified', 'author', + 'tag', + ], + }, + 'ticket': { + 'icon': 'ticket', + 'fields': [ + 'title', 'description', 'milestone', 'priority', + 'component', 'version', 'severity', 'reporter', 'author', + 'status', 'keywords', 'collaborators', 'created', + 'modified', + ], + }, + 'changeset': { + 'icon': 'changeset', + 'fields': [ + 'title', 'author', 'description', 'repository_name', + 'created', 'modified', + ], + }, + 'user': { + 'icon': 'user', + 'fields': [ + 'title', 'description', 'username', 'name', + 'email', 'institution', 'role', 'google_talk', 'webpage', + ], + }, + } + types = self.form.cleaned_data['type'] + return dict( + types=types.split(), + types_str=types, + order_data=settings.ORDERING_DATA + ) diff --git a/src/templates/home.html b/src/templates/home.html index 4de0363..cdfdcac 100644 --- a/src/templates/home.html +++ b/src/templates/home.html @@ -27,12 +27,12 @@ title="{% trans 'RSS - Latest collaborations' %}"> + href="{% url 'haystack_search' %}?order=latest"> {% trans "View more collaborations..." %}
 
diff --git a/src/templates/search/preview-search.html b/src/templates/search/preview-search.html index 7d42951..5e5d51b 100644 --- a/src/templates/search/preview-search.html +++ b/src/templates/search/preview-search.html @@ -14,14 +14,18 @@ - {% highlight result.title with query max_length "1000" %} + {% if query %} + {% highlight result.title with query max_length "1000" %} + {% else %} + {{ result.title }} + {% endif %} {% endif %} {% if result.description %} - - {% highlight result.description with query max_length "150" %} + - {% if query %}{% highlight result.description with query max_length "150" %}{% else %}{{ result.description }}{% endif %} {% endif %} {% if result.author or result.modified %} @@ -29,7 +33,13 @@ {% if result.author %} {% trans "by" %} {% if result.author and result.author_url %} - {% highlight result.author with query %} + + {% if query %} + {% highlight result.author with query %} + {% else %} + {{ result.author }} + {% endif %} + {% else %} {{ result.author }} {% endif %} -- libgit2 0.21.2