##// END OF EJS Templates
Simplified pagination templates. Added a list of pages to the search results page
neko259 -
r1878:7fb52044 default
parent child Browse files
Show More
@@ -0,0 +1,26 b''
1 {% extends 'boards/base.html' %}
2
3 {% load i18n %}
4 {% load board %}
5
6 {% block metapanel %}
7
8 <span class="metapanel">
9 {% trans "Pages:" %}
10 [
11 {% with dividers=paginator.get_dividers %}
12 {% for page in paginator.get_divided_range %}
13 {% if page in dividers %}
14 …,
15 {% endif %}
16 <a
17 {% ifequal page current_page.number %}
18 class="current_page"
19 {% endifequal %}
20 href="{% page_url paginator page %}">{{ page }}</a>{% if not forloop.last %},{% endif %}
21 {% endfor %}
22 {% endwith %}
23 ]
24 </span>
25
26 {% endblock %}
@@ -1,208 +1,208 b''
1 {% extends "boards/base.html" %}
1 {% extends "boards/paginated.html" %}
2 2
3 3 {% load i18n %}
4 4 {% load board %}
5 5 {% load static %}
6 6 {% load tz %}
7 7
8 8 {% block head %}
9 9 <meta name="robots" content="noindex">
10 10
11 11 {% if tag %}
12 12 <title>{{ tag.get_name }} - {{ site_name }}</title>
13 13 {% else %}
14 14 <title>{{ site_name }}</title>
15 15 {% endif %}
16 16
17 17 {% if prev_page_link %}
18 18 <link rel="prev" href="{{ prev_page_link }}" />
19 19 {% endif %}
20 20 {% if next_page_link %}
21 21 <link rel="next" href="{{ next_page_link }}" />
22 22 {% endif %}
23 23
24 24 {% endblock %}
25 25
26 26 {% block content %}
27 27
28 28 {% get_current_language as LANGUAGE_CODE %}
29 29 {% get_current_timezone as TIME_ZONE %}
30 30
31 31 {% for banner in banners %}
32 32 <div class="post">
33 33 <div class="title">{{ banner.title }}</div>
34 34 <div>{{ banner.get_text|safe }}</div>
35 35 <div>{% trans 'Details' %}: <a href="{{ banner.post.get_absolute_url }}">>>{{ banner.post.id }}</a></div>
36 36 </div>
37 37 {% endfor %}
38 38
39 39 {% if tag %}
40 40 <div class="tag_info" style="border-bottom: solid .5ex #{{ tag.get_color }}">
41 41 {% if random_image_post %}
42 42 <div class="tag-image">
43 43 {% with image=random_image_post.get_first_image %}
44 44 <a href="{{ random_image_post.get_absolute_url }}"><img
45 45 src="{{ image.get_thumb_url }}"
46 46 width="{{ image.get_preview_size.0 }}"
47 47 height="{{ image.get_preview_size.1 }}"
48 48 alt="{{ random_image_post.id }}"/></a>
49 49 {% endwith %}
50 50 </div>
51 51 {% endif %}
52 52 <div class="tag-text-data">
53 53 <h2>
54 54 /{{ tag.get_view|safe }}/
55 55 </h2>
56 56 {% if perms.change_tag %}
57 57 <div class="moderator_info"><a href="{% url 'admin:boards_tag_change' tag.id %}">{% trans 'Edit tag' %}</a></div>
58 58 {% endif %}
59 59 <p>
60 60 <form action="{% url 'tag' tag.get_name %}" method="post" class="post-button-form">
61 61 {% if is_favorite %}
62 62 <button name="method" value="unsubscribe" class="fav">β˜… {% trans "Remove from favorites" %}</button>
63 63 {% else %}
64 64 <button name="method" value="subscribe" class="not_fav">β˜… {% trans "Add to favorites" %}</button>
65 65 {% endif %}
66 66 </form>
67 67 <form action="{% url 'tag' tag.get_name %}" method="post" class="post-button-form">
68 68 {% if is_hidden %}
69 69 <button name="method" value="unhide" class="fav">{% trans "Show" %}</button>
70 70 {% else %}
71 71 <button name="method" value="hide" class="not_fav">{% trans "Hide" %}</button>
72 72 {% endif %}
73 73 </form>
74 74 <a href="{% url 'tag_gallery' tag.get_name %}">{% trans 'Gallery' %}</a>
75 75 </p>
76 76 {% if tag.get_description %}
77 77 <p>{{ tag.get_description|safe }}</p>
78 78 {% endif %}
79 79 <p>
80 80 {% with active_count=tag.get_active_thread_count bumplimit_count=tag.get_bumplimit_thread_count archived_count=tag.get_archived_thread_count %}
81 81 {% if active_count %}
82 82 ● {{ active_count }}&ensp;
83 83 {% endif %}
84 84 {% if bumplimit_count %}
85 85 ◍ {{ bumplimit_count }}&ensp;
86 86 {% endif %}
87 87 {% if archived_count %}
88 88 β—‹ {{ archived_count }}&ensp;
89 89 {% endif %}
90 90 {% endwith %}
91 91 β™₯ {{ tag.get_post_count }}
92 92 </p>
93 93 {% if tag.get_all_parents %}
94 94 <p>
95 95 {% for parent in tag.get_all_parents %}
96 96 {{ parent.get_view|safe }} &gt;
97 97 {% endfor %}
98 98 {{ tag.get_view|safe }}
99 99 </p>
100 100 {% endif %}
101 101 {% if tag.get_children.all %}
102 102 <p>
103 103 {% trans "Subsections: " %}
104 104 {% for child in tag.get_children.all %}
105 105 {{ child.get_view|safe }}{% if not forloop.last%}, {% endif %}
106 106 {% endfor %}
107 107 </p>
108 108 {% endif %}
109 109 </div>
110 110 </div>
111 111 {% endif %}
112 112
113 113 {% if threads %}
114 114 {% if prev_page_link %}
115 115 <div class="page_link">
116 116 <a href="{{ prev_page_link }}">&lt;&lt; {% trans "Previous page" %} &lt;&lt;</a>
117 117 </div>
118 118 {% endif %}
119 119
120 120 {% for thread in threads %}
121 121 <div class="thread">
122 122 {% post_view thread.get_opening_post thread=thread truncated=True need_open_link=True %}
123 123 {% if not thread.archived %}
124 124 {% with last_replies=thread.get_last_replies %}
125 125 {% if last_replies %}
126 126 {% with skipped_replies_count=thread.get_skipped_replies_count %}
127 127 {% if skipped_replies_count %}
128 128 <div class="skipped_replies">
129 129 <a href="{% url 'thread' thread.get_opening_post_id %}">
130 130 {% blocktrans count count=skipped_replies_count %}Skipped {{ count }} reply. Open thread to see all replies.{% plural %}Skipped {{ count }} replies. Open thread to see all replies.{% endblocktrans %}
131 131 </a>
132 132 </div>
133 133 {% endif %}
134 134 {% endwith %}
135 135 <div class="last-replies">
136 136 {% for post in last_replies %}
137 137 {% post_view post truncated=True %}
138 138 {% endfor %}
139 139 </div>
140 140 {% endif %}
141 141 {% endwith %}
142 142 {% endif %}
143 143 </div>
144 144 {% endfor %}
145 145
146 146 {% if next_page_link %}
147 147 <div class="page_link">
148 148 <a href="{{ next_page_link }}">&gt;&gt; {% trans "Next page" %} &gt;&gt;</a>
149 149 </div>
150 150 {% endif %}
151 151 {% else %}
152 152 <div class="post">
153 153 {% trans 'No threads exist. Create the first one!' %}</div>
154 154 {% endif %}
155 155
156 156 <div class="post-form-w">
157 157 <script src="{% static 'js/panel.js' %}"></script>
158 158 <div class="post-form" data-hasher="{% static 'js/3party/sha256.js' %}"
159 159 data-pow-script="{% static 'js/proof_of_work.js' %}">
160 160 <div class="form-title">{% trans "Create new thread" %}</div>
161 161 <div class="swappable-form-full">
162 162 <form enctype="multipart/form-data" method="post" id="form">{% csrf_token %}
163 163 {{ form.as_div }}
164 164 <div class="form-submit">
165 165 <input type="submit" value="{% trans "Post" %}"/>
166 166 <button id="preview-button" type="button" onclick="return false;">{% trans 'Preview' %}</button>
167 167 </div>
168 168 </form>
169 169 </div>
170 170 <div>
171 171 {% trans 'Tags must be delimited by spaces. Text or image is required.' %}
172 172 {% with size=max_file_size|filesizeformat %}
173 173 {% blocktrans %}Max file size is {{ size }}.{% endblocktrans %}
174 174 {% endwith %}
175 175 {% blocktrans %}Max file number is {{ max_files }}.{% endblocktrans %}
176 176 </div>
177 177 <div id="preview-text"></div>
178 178 <div><a href="{% url "staticpage" name="help" %}">{% trans 'Text syntax' %}</a></div>
179 179 </div>
180 180 </div>
181 181
182 182 <script src="{% static 'js/form.js' %}"></script>
183 183 <script src="{% static 'js/3party/jquery.blockUI.js' %}"></script>
184 184 <script src="{% static 'js/thread_create.js' %}"></script>
185 185
186 186 {% endblock %}
187 187
188 188 {% block metapanel %}
189 189
190 190 <span class="metapanel">
191 191 {% trans "Pages:" %}
192 192 [
193 193 {% with dividers=paginator.get_dividers %}
194 194 {% for page in paginator.get_divided_range %}
195 195 {% if page in dividers %}
196 196 …,
197 197 {% endif %}
198 198 <a
199 199 {% ifequal page current_page.number %}
200 200 class="current_page"
201 201 {% endifequal %}
202 202 href="{% page_url paginator page %}">{{ page }}</a>{% if not forloop.last %},{% endif %}
203 203 {% endfor %}
204 204 {% endwith %}
205 205 ]
206 206 </span>
207 207
208 208 {% endblock %}
@@ -1,73 +1,52 b''
1 {% extends "boards/base.html" %}
1 {% extends "boards/paginated.html" %}
2 2
3 3 {% load i18n %}
4 4 {% load board %}
5 5 {% load static %}
6 6 {% load tz %}
7 7
8 8 {% block head %}
9 9 <meta name="robots" content="noindex">
10 10
11 11 <title>{{ site_name }} - {% trans "feed" %}</title>
12 12
13 13 {% if prev_page_link %}
14 14 <link rel="prev" href="{{ prev_page_link }}" />
15 15 {% endif %}
16 16 {% if next_page_link %}
17 17 <link rel="next" href="{{ next_page_link }}" />
18 18 {% endif %}
19 19
20 20 {% endblock %}
21 21
22 22 {% block content %}
23 23
24 24 {% get_current_language as LANGUAGE_CODE %}
25 25 {% get_current_timezone as TIME_ZONE %}
26 26
27 27 {% for query in queries %}
28 28 <div class="image-mode-tab">{{ query }}</div>
29 29 {% endfor %}
30 30
31 31 {% if posts %}
32 32 {% if prev_page_link %}
33 33 <div class="page_link">
34 34 <a href="{{ prev_page_link }}">&lt;&lt; {% trans "Previous page" %} &lt;&lt;</a>
35 35 </div>
36 36 {% endif %}
37 37
38 38 {% for post in posts %}
39 39 {% post_view post moderator=moderator truncated=True need_op_data=True %}
40 40 {% endfor %}
41 41
42 42 {% if next_page_link %}
43 43 <div class="page_link">
44 44 <a href="{{ next_page_link }}">&gt;&gt; {% trans "Next page" %} &gt;&gt;</a>
45 45 </div>
46 46 {% endif %}
47 47 {% else %}
48 48 <div class="post">
49 49 {% trans 'No posts exist. Create the first one!' %}</div>
50 50 {% endif %}
51 51 {% endblock %}
52 52
53 {% block metapanel %}
54
55 <span class="metapanel">
56 {% trans "Pages:" %}
57 [
58 {% with dividers=paginator.get_dividers %}
59 {% for page in paginator.get_divided_range %}
60 {% if page in dividers %}
61 …,
62 {% endif %}
63 <a
64 {% ifequal page current_page.number %}
65 class="current_page"
66 {% endifequal %}
67 href="{% page_url paginator page %}">{{ page }}</a>{% if not forloop.last %},{% endif %}
68 {% endfor %}
69 {% endwith %}
70 ]
71 </span>
72
73 {% endblock %}
@@ -1,42 +1,48 b''
1 {% extends 'boards/base.html' %}
1 {% extends 'boards/paginated.html' %}
2 2
3 3 {% load board %}
4 4 {% load i18n %}
5 5
6 6 {% block head %}
7 7 <title>{% trans 'Search' %} - {{ site_name }}</title>
8 8 <meta name="robots" content="noindex">
9
10 {% if prev_page_link %}
11 <link rel="prev" href="{{ prev_page_link }}" />
12 {% endif %}
13 {% if next_page_link %}
14 <link rel="next" href="{{ next_page_link }}" />
15 {% endif %}
9 16 {% endblock %}
10 17
11 18 {% block content %}
12 19 <div class="post-form-w">
13 20 <div class="post-form">
14 21 <form method="get" action="">
15 22 {{ form.as_div }}
16 23 <div class="form-submit">
17 24 <input type="submit" value="{% trans 'Ok' %}">
18 25 </div>
19 26 </form>
20 27 </div>
21 28 </div>
22 29
23 {% if page %}
24 {% if page.has_previous %}
30 {% if current_page %}
31 {% if prev_page_link %}
25 32 <div class="page_link">
26 <a href="?query={{ query }}&amp;page={{ page.previous_page_number }}">{% trans "Previous page" %}
27 </a>
33 <a href="{{ prev_page_link }}">&lt;&lt; {% trans "Previous page" %} &lt;&lt;</a>
28 34 </div>
29 35 {% endif %}
30 36
31 {% for result in page.object_list %}
37 {% for result in current_page.object_list %}
32 38 {% post_view result truncated=True need_op_data=True %}
33 39 {% endfor %}
34 40
35 {% if page.has_next %}
41 {% if next_page_link %}
36 42 <div class="page_link">
37 <a href="?query={{ query }}&amp;page={{ page.next_page_number }}">{% trans "Next page" %}
38 </a>
43 <a href="{{ next_page_link }}">&gt;&gt; {% trans "Next page" %} &gt;&gt;</a>
39 44 </div>
40 45 {% endif %}
41 46 {% endif %}
42 47 {% endblock %}
48
@@ -1,46 +1,49 b''
1 1 from django.shortcuts import render
2 2 from django.views.generic import View
3 3 from django.db.models import Q
4 from django.core.urlresolvers import reverse
4 5
5 6 from boards.abstracts.paginator import get_paginator
6 7 from boards.forms import SearchForm, PlainErrorList
7 8 from boards.models import Post
9 from boards.views.mixins import PaginatedMixin
8 10
9 11
10 12 MIN_QUERY_LENGTH = 3
11 13 RESULTS_PER_PAGE = 10
12 14
13 15 FORM_QUERY = 'query'
14 16
15 17 CONTEXT_QUERY = 'query'
16 18 CONTEXT_FORM = 'form'
17 19 CONTEXT_PAGE = 'page'
18 20
19 21 REQUEST_PAGE = 'page'
20 22
21 23 __author__ = 'neko259'
22 24
23 25 TEMPLATE = 'search/search.html'
24 26
25 27
26 class BoardSearchView(View):
28 class BoardSearchView(View, PaginatedMixin):
27 29 def get(self, request):
28 30 params = dict()
29 31
30 32 form = SearchForm(request.GET, error_class=PlainErrorList)
31 33 params[CONTEXT_FORM] = form
32 34
33 35 if form.is_valid():
34 36 query = form.cleaned_data[FORM_QUERY]
35 37 if len(query) >= MIN_QUERY_LENGTH:
36 38 results = Post.objects.filter(Q(text__icontains=query)
37 39 | Q(title__icontains=query) | Q(opening=True,
38 40 thread__tags__aliases__name__icontains=query)).order_by('-id').distinct()
39 41 paginator = get_paginator(results, RESULTS_PER_PAGE)
42 paginator.set_url(reverse('search'), request.GET.dict())
40 43
41 44 page = int(request.GET.get(REQUEST_PAGE, '1'))
42 45
43 params[CONTEXT_PAGE] = paginator.page(page)
44 46 params[CONTEXT_QUERY] = query
47 params.update(self.get_page_context(paginator, page))
45 48
46 49 return render(request, TEMPLATE, params)
General Comments 0
You need to be logged in to leave comments. Login now