Commit ccf2d18dc368c2070042842ca1d3d7fb30037a91

Authored by Luan
1 parent 79e8a63d

Fixing home and removing old search

src/colab/deprecated/views/other.py
@@ -6,12 +6,16 @@ other.py @@ -6,12 +6,16 @@ other.py
6 Created by Sergio Campos on 2012-01-10. 6 Created by Sergio Campos on 2012-01-10.
7 """ 7 """
8 8
  9 +import datetime
  10 +
9 from django.template import RequestContext 11 from django.template import RequestContext
10 from django.http import HttpResponseNotAllowed 12 from django.http import HttpResponseNotAllowed
11 from django.shortcuts import render_to_response 13 from django.shortcuts import render_to_response
  14 +from django.utils import timezone
12 from django.utils.translation import ugettext as _ 15 from django.utils.translation import ugettext as _
13 16
14 -from colab.deprecated import solrutils 17 +from haystack.query import SearchQuerySet
  18 +
15 from super_archives import queries 19 from super_archives import queries
16 20
17 21
@@ -21,11 +25,21 @@ def home(request): @@ -21,11 +25,21 @@ def home(request):
21 latest_threads = queries.get_latest_threads() 25 latest_threads = queries.get_latest_threads()
22 hottest_threads = queries.get_hottest_threads() 26 hottest_threads = queries.get_hottest_threads()
23 27
  28 + count_types = {}
  29 + six_months = timezone.now() - datetime.timedelta(days=180)
  30 + for type in ['wiki', 'thread', 'changeset', 'ticket']:
  31 + count_types[type] = SearchQuerySet().filter(
  32 + type=type,
  33 + modified__gte=six_months,
  34 + ).count()
  35 +
24 template_data = { 36 template_data = {
25 'hottest_threads': hottest_threads[:6], 37 'hottest_threads': hottest_threads[:6],
26 'latest_threads': latest_threads[:6], 38 'latest_threads': latest_threads[:6],
27 - 'type_count': solrutils.count_types(sample=1000),  
28 - 'latest_docs': solrutils.get_latest_collaborations(6), 39 + 'type_count': count_types,
  40 + 'latest_results': SearchQuerySet().all().order_by(
  41 + '-modified', '-created'
  42 + )[:6],
29 } 43 }
30 return render_to_response('home.html', template_data, 44 return render_to_response('home.html', template_data,
31 context_instance=RequestContext(request)) 45 context_instance=RequestContext(request))
@@ -34,7 +48,7 @@ def home(request): @@ -34,7 +48,7 @@ def home(request):
34 def search(request): 48 def search(request):
35 if request.method != 'GET': 49 if request.method != 'GET':
36 return HttpResponseNotAllowed(['GET']) 50 return HttpResponseNotAllowed(['GET'])
37 - 51 +
38 query = request.GET.get('q') 52 query = request.GET.get('q')
39 sort = request.GET.get('o') 53 sort = request.GET.get('o')
40 type_ = request.GET.get('type') 54 type_ = request.GET.get('type')
@@ -42,7 +56,7 @@ def search(request): @@ -42,7 +56,7 @@ def search(request):
42 page_number = int(request.GET.get('p', '1')) 56 page_number = int(request.GET.get('p', '1'))
43 except ValueError: 57 except ValueError:
44 page_number = 1 58 page_number = 1
45 - 59 +
46 try: 60 try:
47 results_per_page = int(request.GET.get('per_page', 16)) 61 results_per_page = int(request.GET.get('per_page', 16))
48 except ValueError: 62 except ValueError:
src/colab/urls.py
1 -  
2 from django.conf.urls import patterns, include, url 1 from django.conf.urls import patterns, include, url
3 from django.conf import settings 2 from django.conf import settings
4 from django.views.generic import TemplateView 3 from django.views.generic import TemplateView
5 from django.contrib import admin 4 from django.contrib import admin
6 -from haystack.forms import ModelSearchForm  
7 -from haystack.query import SearchQuerySet  
8 -from haystack.views import SearchView  
9 5
10 from accounts.models import User 6 from accounts.models import User
11 from search.forms import ColabSearchForm 7 from search.forms import ColabSearchForm
@@ -17,14 +13,7 @@ admin.autodiscover() @@ -17,14 +13,7 @@ admin.autodiscover()
17 urlpatterns = patterns('', 13 urlpatterns = patterns('',
18 url(r'^$', 'colab.deprecated.views.other.home', name='home'), 14 url(r'^$', 'colab.deprecated.views.other.home', name='home'),
19 15
20 - # TODO change search to full_search with haystack  
21 - url(r'^search/$', 'colab.deprecated.views.other.search', name='search'),  
22 - url(r'^full_search/', SearchView(  
23 - template='search/search.html',  
24 - searchqueryset=SearchQuerySet(),  
25 - form_class=ColabSearchForm,  
26 - ), name='haystack_search'),  
27 - 16 + url(r'^search/', include('search.urls')),
28 url(r'open-data/$', TemplateView.as_view(template_name='open-data.html'), 17 url(r'open-data/$', TemplateView.as_view(template_name='open-data.html'),
29 name='opendata'), 18 name='opendata'),
30 19
src/search/forms.py
@@ -12,7 +12,7 @@ from super_archives.models import Message @@ -12,7 +12,7 @@ from super_archives.models import Message
12 12
13 13
14 class ColabSearchForm(SearchForm): 14 class ColabSearchForm(SearchForm):
15 - q = forms.CharField(label=_('Search')) 15 + q = forms.CharField(label=_('Search'), required=False)
16 order = forms.CharField(widget=forms.HiddenInput(), required=False) 16 order = forms.CharField(widget=forms.HiddenInput(), required=False)
17 type = forms.CharField(required=False, label=_(u'Type')) 17 type = forms.CharField(required=False, label=_(u'Type'))
18 18
src/search/urls.py 0 → 100644
@@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
  1 +from django.conf.urls import patterns, include, url
  2 +from haystack.query import SearchQuerySet
  3 +
  4 +from .forms import ColabSearchForm
  5 +from .views import ColabSearchView
  6 +
  7 +
  8 +urlpatterns = patterns('',
  9 + url(r'^$', ColabSearchView(
  10 + template='search/search.html',
  11 + searchqueryset=SearchQuerySet(),
  12 + form_class=ColabSearchForm,
  13 + ), name='haystack_search'),
  14 +)
src/search/views.py
1 -from django.shortcuts import render 1 +# -*- coding:utf-8 -*-
2 2
3 -# Create your views here. 3 +from django.conf import settings
  4 +from haystack.views import SearchView
  5 +
  6 +
  7 +class ColabSearchView(SearchView):
  8 + def extra_context(self, *args, **kwargs):
  9 + # Retornar todos os campos de cada tipo a serem filtrados
  10 + # retornar os nomes dos campos
  11 + # retornar os ícones dos tipos
  12 +
  13 + # a critical point on the system
  14 + types = {
  15 + 'wiki': {
  16 + 'icon': 'file',
  17 + 'fields': [
  18 + 'title', 'description', 'author', 'collaborators',
  19 + 'created', 'modified',
  20 + ],
  21 + },
  22 + 'discussion': {
  23 + 'icon': 'thread',
  24 + 'fields': [
  25 + 'title', 'description', 'created', 'modified', 'author',
  26 + 'tag',
  27 + ],
  28 + },
  29 + 'ticket': {
  30 + 'icon': 'ticket',
  31 + 'fields': [
  32 + 'title', 'description', 'milestone', 'priority',
  33 + 'component', 'version', 'severity', 'reporter', 'author',
  34 + 'status', 'keywords', 'collaborators', 'created',
  35 + 'modified',
  36 + ],
  37 + },
  38 + 'changeset': {
  39 + 'icon': 'changeset',
  40 + 'fields': [
  41 + 'title', 'author', 'description', 'repository_name',
  42 + 'created', 'modified',
  43 + ],
  44 + },
  45 + 'user': {
  46 + 'icon': 'user',
  47 + 'fields': [
  48 + 'title', 'description', 'username', 'name',
  49 + 'email', 'institution', 'role', 'google_talk', 'webpage',
  50 + ],
  51 + },
  52 + }
  53 + types = self.form.cleaned_data['type']
  54 + return dict(
  55 + types=types.split(),
  56 + types_str=types,
  57 + order_data=settings.ORDERING_DATA
  58 + )
src/templates/home.html
@@ -27,12 +27,12 @@ @@ -27,12 +27,12 @@
27 title="{% trans 'RSS - Latest collaborations' %}"> 27 title="{% trans 'RSS - Latest collaborations' %}">
28 </a> 28 </a>
29 <ul class="message-list"> 29 <ul class="message-list">
30 - {% for doc in latest_docs %}  
31 - {% include "message-preview.html" %} 30 + {% for result in latest_results %}
  31 + {% include "search/preview-search.html" %}
32 {% endfor %} 32 {% endfor %}
33 </ul> 33 </ul>
34 <a class="column-align" 34 <a class="column-align"
35 - href="{% url 'search' %}?o=modified+desc"> 35 + href="{% url 'haystack_search' %}?order=latest">
36 {% trans "View more collaborations..." %} 36 {% trans "View more collaborations..." %}
37 </a> 37 </a>
38 <div>&nbsp;</div> 38 <div>&nbsp;</div>
src/templates/search/preview-search.html
@@ -14,14 +14,18 @@ @@ -14,14 +14,18 @@
14 <a href="{{ result.url }}" {% if result.description %}title="{{ result.description|escape|truncatechars:200 }}"{% endif %}> 14 <a href="{{ result.url }}" {% if result.description %}title="{{ result.description|escape|truncatechars:200 }}"{% endif %}>
15 <span class="subject"> 15 <span class="subject">
16 <!-- a striptags filter was raising an error here because using with highlight --> 16 <!-- a striptags filter was raising an error here because using with highlight -->
17 - {% highlight result.title with query max_length "1000" %} 17 + {% if query %}
  18 + {% highlight result.title with query max_length "1000" %}
  19 + {% else %}
  20 + {{ result.title }}
  21 + {% endif %}
18 </span> 22 </span>
19 </a> 23 </a>
20 {% endif %} 24 {% endif %}
21 25
22 {% if result.description %} 26 {% if result.description %}
23 <!-- a striptags filter was raising an error here because using with highlight --> 27 <!-- a striptags filter was raising an error here because using with highlight -->
24 - <span class="quiet">- {% highlight result.description with query max_length "150" %}</span> 28 + <span class="quiet">- {% if query %}{% highlight result.description with query max_length "150" %}{% else %}{{ result.description }}{% endif %}</span>
25 {% endif %} 29 {% endif %}
26 30
27 {% if result.author or result.modified %} 31 {% if result.author or result.modified %}
@@ -29,7 +33,13 @@ @@ -29,7 +33,13 @@
29 {% if result.author %} 33 {% if result.author %}
30 <span class="pull-left">{% trans "by" %} 34 <span class="pull-left">{% trans "by" %}
31 {% if result.author and result.author_url %} 35 {% if result.author and result.author_url %}
32 - <a href="{{ result.author_url }}">{% highlight result.author with query %}</a> 36 + <a href="{{ result.author_url }}">
  37 + {% if query %}
  38 + {% highlight result.author with query %}
  39 + {% else %}
  40 + {{ result.author }}
  41 + {% endif %}
  42 + </a>
33 {% else %} 43 {% else %}
34 <span>{{ result.author }}</span> 44 <span>{{ result.author }}</span>
35 {% endif %} 45 {% endif %}