Show More
@@ -0,0 +1,32 b'' | |||||
|
1 | from django.shortcuts import render | |||
|
2 | from django.template import RequestContext | |||
|
3 | from django.views.generic import View | |||
|
4 | from haystack.query import SearchQuerySet | |||
|
5 | from boards.abstracts.paginator import get_paginator | |||
|
6 | from boards.forms import SearchForm, PlainErrorList | |||
|
7 | ||||
|
8 | __author__ = 'neko259' | |||
|
9 | ||||
|
10 | TEMPLATE = 'search/search.html' | |||
|
11 | ||||
|
12 | ||||
|
13 | class BoardSearchView(View): | |||
|
14 | def get(self, request): | |||
|
15 | context = RequestContext(request) | |||
|
16 | form = SearchForm(request.GET, error_class=PlainErrorList) | |||
|
17 | context['form'] = form | |||
|
18 | ||||
|
19 | if form.is_valid(): | |||
|
20 | query = form.cleaned_data['query'] | |||
|
21 | if len(query) >= 3: | |||
|
22 | results = SearchQuerySet().auto_query(query).order_by('-id') \ | |||
|
23 | .highlight() | |||
|
24 | paginator = get_paginator(results, 10) | |||
|
25 | ||||
|
26 | if 'page' in request.GET: | |||
|
27 | page = int(request.GET['page']) | |||
|
28 | else: | |||
|
29 | page = 1 | |||
|
30 | context['page'] = paginator.page(page) | |||
|
31 | ||||
|
32 | return render(request, TEMPLATE, context) No newline at end of file |
@@ -29,6 +29,7 b" ERROR_IMAGE_DUPLICATE = _('Such image wa" | |||||
29 | LABEL_TITLE = _('Title') |
|
29 | LABEL_TITLE = _('Title') | |
30 | LABEL_TEXT = _('Text') |
|
30 | LABEL_TEXT = _('Text') | |
31 | LABEL_TAG = _('Tag') |
|
31 | LABEL_TAG = _('Tag') | |
|
32 | LABEL_SEARCH = _('Search') | |||
32 |
|
33 | |||
33 | TAG_MAX_LENGTH = 20 |
|
34 | TAG_MAX_LENGTH = 20 | |
34 |
|
35 | |||
@@ -349,3 +350,6 b' class AddTagForm(NeboardForm):' | |||||
349 |
|
350 | |||
350 | return cleaned_data |
|
351 | return cleaned_data | |
351 |
|
352 | |||
|
353 | ||||
|
354 | class SearchForm(NeboardForm): | |||
|
355 | query = forms.CharField(max_length=500, label=LABEL_SEARCH, required=False) No newline at end of file |
@@ -113,7 +113,7 b' class PostManager(models.Manager):' | |||||
113 | thread = post.get_thread() |
|
113 | thread = post.get_thread() | |
114 |
|
114 | |||
115 | if post.is_opening(): |
|
115 | if post.is_opening(): | |
116 |
thread.delete |
|
116 | thread.delete() | |
117 | else: |
|
117 | else: | |
118 | thread.last_edit_time = timezone.now() |
|
118 | thread.last_edit_time = timezone.now() | |
119 | thread.save() |
|
119 | thread.save() |
@@ -32,7 +32,7 b' class ThreadManager(models.Manager):' | |||||
32 | if settings.ARCHIVE_THREADS: |
|
32 | if settings.ARCHIVE_THREADS: | |
33 | self._archive_thread(thread) |
|
33 | self._archive_thread(thread) | |
34 | else: |
|
34 | else: | |
35 |
|
|
35 | thread.delete() | |
36 |
|
36 | |||
37 | logger.info('Processed %d old threads' % num_threads_to_delete) |
|
37 | logger.info('Processed %d old threads' % num_threads_to_delete) | |
38 |
|
38 | |||
@@ -41,9 +41,6 b' class ThreadManager(models.Manager):' | |||||
41 | thread.last_edit_time = timezone.now() |
|
41 | thread.last_edit_time = timezone.now() | |
42 | thread.save(update_fields=['archived', 'last_edit_time']) |
|
42 | thread.save(update_fields=['archived', 'last_edit_time']) | |
43 |
|
43 | |||
44 | def _delete_thread(self, thread): |
|
|||
45 | thread.delete_with_posts() |
|
|||
46 |
|
||||
47 |
|
44 | |||
48 | class Thread(models.Model): |
|
45 | class Thread(models.Model): | |
49 | objects = ThreadManager() |
|
46 | objects = ThreadManager() | |
@@ -98,17 +95,6 b' class Thread(models.Model):' | |||||
98 |
|
95 | |||
99 | return post_count < settings.MAX_POSTS_PER_THREAD |
|
96 | return post_count < settings.MAX_POSTS_PER_THREAD | |
100 |
|
97 | |||
101 | # TODO Do it in the 'delete' method |
|
|||
102 | def delete_with_posts(self): |
|
|||
103 | """ |
|
|||
104 | Completely deletes thread and all its posts |
|
|||
105 | """ |
|
|||
106 |
|
||||
107 | if self.replies.exists(): |
|
|||
108 | self.replies.all().delete() |
|
|||
109 |
|
||||
110 | self.delete() |
|
|||
111 |
|
||||
112 | def get_last_replies(self): |
|
98 | def get_last_replies(self): | |
113 | """ |
|
99 | """ | |
114 | Gets several last replies, not including opening post |
|
100 | Gets several last replies, not including opening post | |
@@ -194,3 +180,9 b' class Thread(models.Model):' | |||||
194 | """ |
|
180 | """ | |
195 |
|
181 | |||
196 | return self.get_opening_post().pub_time |
|
182 | return self.get_opening_post().pub_time | |
|
183 | ||||
|
184 | def delete(self, using=None): | |||
|
185 | if self.replies.exists(): | |||
|
186 | self.replies.all().delete() | |||
|
187 | ||||
|
188 | super(Thread, self).delete(using) No newline at end of file |
@@ -47,7 +47,7 b'' | |||||
47 | <div class="navigation_panel"> |
|
47 | <div class="navigation_panel"> | |
48 | {% block metapanel %}{% endblock %} |
|
48 | {% block metapanel %}{% endblock %} | |
49 | [<a href="{% url "login" %}">{% trans 'Login' %}</a>] |
|
49 | [<a href="{% url "login" %}">{% trans 'Login' %}</a>] | |
50 |
[<a href="{% url " |
|
50 | [<a href="{% url "search" %}">{% trans 'Search' %}</a>] | |
51 | {% with ppd=posts_per_day|floatformat:2 %} |
|
51 | {% with ppd=posts_per_day|floatformat:2 %} | |
52 | {% blocktrans %}Speed: {{ ppd }} posts per day{% endblocktrans %} |
|
52 | {% blocktrans %}Speed: {{ ppd }} posts per day{% endblocktrans %} | |
53 | {% endwith %} |
|
53 | {% endwith %} |
@@ -5,18 +5,21 b'' | |||||
5 |
|
5 | |||
6 | {% block content %} |
|
6 | {% block content %} | |
7 | <div class="post-form-w"> |
|
7 | <div class="post-form-w"> | |
8 | <h3>{% trans 'Search' %}</h3> |
|
8 | <div class="post-form"> | |
9 | <form method="get" action=""> |
|
9 | <h3>{% trans 'Search' %}</h3> | |
10 | {{ form.as_p }} |
|
10 | <form method="get" action=""> | |
11 | <input type="submit" value="{% trans 'Search' %}"> |
|
11 | {{ form.as_div }} | |
12 | </form> |
|
12 | <div class="form-submit"> | |
|
13 | <input type="submit" value="{% trans 'Search' %}"> | |||
|
14 | </div> | |||
|
15 | </form> | |||
|
16 | </div> | |||
13 | </div> |
|
17 | </div> | |
14 |
|
18 | |||
15 |
{% if |
|
19 | {% if page %} | |
16 | {% if page.has_previous %} |
|
20 | {% if page.has_previous %} | |
17 | <div class="page_link"> |
|
21 | <div class="page_link"> | |
18 | <a href="?q={{ query }}&page={{ page.previous_page_number }}"> |
|
22 | <a href="?query={{ query }}&page={{ page.previous_page_number }}">{% trans "Previous page" %} | |
19 | {% trans "Previous page" %} |
|
|||
20 | </a> |
|
23 | </a> | |
21 | </div> |
|
24 | </div> | |
22 | {% endif %} |
|
25 | {% endif %} | |
@@ -29,8 +32,7 b'' | |||||
29 |
|
32 | |||
30 | {% if page.has_next %} |
|
33 | {% if page.has_next %} | |
31 | <div class="page_link"> |
|
34 | <div class="page_link"> | |
32 | <a href="?q={{ query }}&page={{ page.next_page_number }}"> |
|
35 | <a href="?query={{ query }}&page ={{ page.next_page_number }}">{% trans "Next page" %} | |
33 | {% trans "Next page" %} |
|
|||
34 | </a> |
|
36 | </a> | |
35 | </div> |
|
37 | </div> | |
36 | {% endif %} |
|
38 | {% endif %} |
@@ -57,7 +57,7 b' class PostTests(TestCase):' | |||||
57 | thread = opening_post.get_thread() |
|
57 | thread = opening_post.get_thread() | |
58 | reply = Post.objects.create_post("", "", thread=thread) |
|
58 | reply = Post.objects.create_post("", "", thread=thread) | |
59 |
|
59 | |||
60 |
thread.delete |
|
60 | thread.delete() | |
61 |
|
61 | |||
62 | self.assertFalse(Post.objects.filter(id=reply.id).exists()) |
|
62 | self.assertFalse(Post.objects.filter(id=reply.id).exists()) | |
63 |
|
63 |
@@ -6,6 +6,7 b' from boards.views import api, tag_thread' | |||||
6 | from boards.views.authors import AuthorsView |
|
6 | from boards.views.authors import AuthorsView | |
7 | from boards.views.delete_post import DeletePostView |
|
7 | from boards.views.delete_post import DeletePostView | |
8 | from boards.views.ban import BanUserView |
|
8 | from boards.views.ban import BanUserView | |
|
9 | from boards.views.search import BoardSearchView | |||
9 | from boards.views.static import StaticPageView |
|
10 | from boards.views.static import StaticPageView | |
10 | from boards.views.post_admin import PostAdminView |
|
11 | from boards.views.post_admin import PostAdminView | |
11 |
|
12 | |||
@@ -77,6 +78,6 b" urlpatterns = patterns(''," | |||||
77 | name='add_post'), |
|
78 | name='add_post'), | |
78 |
|
79 | |||
79 | # Search |
|
80 | # Search | |
80 | url(r'^search/', include('haystack.urls')), |
|
81 | url(r'^search/$', BoardSearchView.as_view(), name='search'), | |
81 |
|
82 | |||
82 | ) |
|
83 | ) |
@@ -10,7 +10,6 b' from boards.models import Post, Thread, ' | |||||
10 | from boards.views.banned import BannedView |
|
10 | from boards.views.banned import BannedView | |
11 | from boards.views.base import BaseBoardView, PARAMETER_FORM |
|
11 | from boards.views.base import BaseBoardView, PARAMETER_FORM | |
12 | from boards.views.posting_mixin import PostMixin |
|
12 | from boards.views.posting_mixin import PostMixin | |
13 | import neboard |
|
|||
14 |
|
13 | |||
15 | TAG_DELIMITER = ' ' |
|
14 | TAG_DELIMITER = ' ' | |
16 |
|
15 |
General Comments 0
You need to be logged in to leave comments.
Login now