Commit 1657ac121170ffcfabb81792563cdc286d12b973
1 parent
f8747b74
Exists in
master
and in
39 other branches
Moving home to it's own app
Showing
9 changed files
with
41 additions
and
91 deletions
Show diff stats
src/colab/deprecated/fixtures/generate_fixtures.sh
src/colab/deprecated/views/__init__.py
src/colab/deprecated/views/other.py
... | ... | @@ -1,85 +0,0 @@ |
1 | -#!/usr/bin/env python | |
2 | -# encoding: utf-8 | |
3 | -""" | |
4 | -other.py | |
5 | - | |
6 | -Created by Sergio Campos on 2012-01-10. | |
7 | -""" | |
8 | - | |
9 | -import datetime | |
10 | - | |
11 | -from django.template import RequestContext | |
12 | -from django.http import HttpResponseNotAllowed | |
13 | -from django.shortcuts import render_to_response | |
14 | -from django.utils import timezone | |
15 | -from django.utils.translation import ugettext as _ | |
16 | - | |
17 | -from haystack.query import SearchQuerySet | |
18 | - | |
19 | -from super_archives import queries | |
20 | - | |
21 | - | |
22 | -def home(request): | |
23 | - """Index page view""" | |
24 | - | |
25 | - latest_threads = queries.get_latest_threads() | |
26 | - hottest_threads = queries.get_hottest_threads() | |
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 | - | |
36 | - template_data = { | |
37 | - 'hottest_threads': hottest_threads[:6], | |
38 | - 'latest_threads': latest_threads[:6], | |
39 | - 'type_count': count_types, | |
40 | - 'latest_results': SearchQuerySet().all().order_by( | |
41 | - '-modified', '-created' | |
42 | - )[:6], | |
43 | - } | |
44 | - return render_to_response('home.html', template_data, | |
45 | - context_instance=RequestContext(request)) | |
46 | - | |
47 | - | |
48 | -def search(request): | |
49 | - if request.method != 'GET': | |
50 | - return HttpResponseNotAllowed(['GET']) | |
51 | - | |
52 | - query = request.GET.get('q') | |
53 | - sort = request.GET.get('o') | |
54 | - type_ = request.GET.get('type') | |
55 | - try: | |
56 | - page_number = int(request.GET.get('p', '1')) | |
57 | - except ValueError: | |
58 | - page_number = 1 | |
59 | - | |
60 | - try: | |
61 | - results_per_page = int(request.GET.get('per_page', 16)) | |
62 | - except ValueError: | |
63 | - results_per_page = 16 | |
64 | - | |
65 | - filters = { | |
66 | - 'Type': type_, | |
67 | - } | |
68 | - | |
69 | - query = solrutils.build_query(query, filters) | |
70 | - | |
71 | - # Query Solr for results | |
72 | - solr_dict_resp = solrutils.select(query, results_per_page, | |
73 | - page_number, sort) | |
74 | - | |
75 | - docs = solrutils.SolrPaginator(solr_dict_resp, page_number) | |
76 | - | |
77 | - template_data = { | |
78 | - 'docs': docs, | |
79 | - 'anonymous': _(u'anônimo'), | |
80 | - 'q': query, | |
81 | - 'type': type_, | |
82 | - } | |
83 | - | |
84 | - return render_to_response('search.html', template_data, | |
85 | - RequestContext(request)) |
src/colab/urls.py
... | ... | @@ -11,7 +11,7 @@ from super_archives.models import Message |
11 | 11 | admin.autodiscover() |
12 | 12 | |
13 | 13 | urlpatterns = patterns('', |
14 | - url(r'^$', 'colab.deprecated.views.other.home', name='home'), | |
14 | + url(r'^$', 'home.views.index', name='home'), | |
15 | 15 | |
16 | 16 | url(r'^search/', include('search.urls')), |
17 | 17 | url(r'open-data/$', TemplateView.as_view(template_name='open-data.html'), | ... | ... |
... | ... | @@ -0,0 +1,31 @@ |
1 | +from django.shortcuts import render | |
2 | + | |
3 | +from django.utils import timezone | |
4 | + | |
5 | +from haystack.query import SearchQuerySet | |
6 | +from super_archives import queries | |
7 | + | |
8 | + | |
9 | +def index(request): | |
10 | + """Index page view""" | |
11 | + | |
12 | + latest_threads = queries.get_latest_threads() | |
13 | + hottest_threads = queries.get_hottest_threads() | |
14 | + | |
15 | + count_types = {} | |
16 | + six_months = timezone.now() - timezone.timedelta(days=180) | |
17 | + for type in ['wiki', 'thread', 'changeset', 'ticket']: | |
18 | + count_types[type] = SearchQuerySet().filter( | |
19 | + type=type, | |
20 | + modified__gte=six_months, | |
21 | + ).count() | |
22 | + | |
23 | + context = { | |
24 | + 'hottest_threads': hottest_threads[:6], | |
25 | + 'latest_threads': latest_threads[:6], | |
26 | + 'type_count': count_types, | |
27 | + 'latest_results': SearchQuerySet().all().order_by( | |
28 | + '-modified', '-created' | |
29 | + )[:6], | |
30 | + } | |
31 | + return render(request, 'home.html', context) | ... | ... |