##// END OF EJS Templates
Added ability to open fav posts as a feed with parameter
neko259 -
r1469:a16adec6 default
parent child Browse files
Show More
@@ -1,89 +1,89 b''
1 1 {% load staticfiles %}
2 2 {% load i18n %}
3 3 {% load l10n %}
4 4 {% load static from staticfiles %}
5 5
6 6 <!DOCTYPE html>
7 7 <html>
8 8 <head>
9 9 <link rel="stylesheet" type="text/css" href="{% static 'css/base.css' %}" media="all"/>
10 10 <link rel="stylesheet" type="text/css" href="{% static 'css/3party/highlight.css' %}" media="all"/>
11 11 <link rel="stylesheet" type="text/css" href="{% static 'css/3party/jquery-ui.min.css' %}" media="all"/>
12 12 <link rel="stylesheet" type="text/css" href="{% static theme_css %}" media="all"/>
13 13
14 14 {% if rss_url %}
15 15 <link rel="alternate" type="application/rss+xml" href="{{ rss_url }}" title="{% trans 'Feed' %}"/>
16 16 {% endif %}
17 17
18 18 <link rel="icon" type="image/png"
19 19 href="{% static 'favicon.png' %}">
20 20
21 21 <meta name="viewport" content="width=device-width, initial-scale=1"/>
22 22 <meta charset="utf-8"/>
23 23
24 24 {% block head %}{% endblock %}
25 25 </head>
26 26 <body data-image-viewer="{{ image_viewer }}"
27 27 data-pow-difficulty="{{ pow_difficulty }}"
28 28 data-update-script="{% static 'js/updates.js' %}">
29 29 <script src="{% static 'js/jquery-2.0.1.min.js' %}"></script>
30 30
31 31 <div class="navigation_panel header">
32 32 <a class="link" href="{% url 'index' %}">{% trans "All threads" %}</a>
33 33 {% if tags_str %}
34 34 {% autoescape off %}
35 35 {{ tags_str }},
36 36 {% endautoescape %}
37 37 {% else %}
38 38 {% trans 'Add tags' %} β†’
39 39 {% endif %}
40 40 <a href="{% url 'tags' 'required'%}" title="{% trans 'Tag management' %}">{% trans "tags" %}</a>,
41 41 <a href="{% url 'search' %}" title="{% trans 'Search' %}">{% trans 'search' %}</a>,
42 42 <a href="{% url 'feed' %}" title="{% trans 'Feed' %}">{% trans 'feed' %}</a>,
43 43 <a href="{% url 'random' %}" title="{% trans 'Random images' %}">{% trans 'random' %}</a>{% if has_fav_threads %},
44 44
45 <a href="#" id="fav-panel-btn">{% trans 'favorites' %} <span id="new-fav-post-count" {% if not new_post_count %}style="display: none" {% endif %}>{{ new_post_count }}</span></a>
45 <a href="{% url 'feed' %}?favorites" id="fav-panel-btn">{% trans 'favorites' %} <span id="new-fav-post-count" {% if not new_post_count %}style="display: none" {% endif %}>{{ new_post_count }}</span></a>
46 46 {% endif %}
47 47
48 48 {% if usernames %}
49 49 <a class="right-link link" href="{% url 'notifications' %}" title="{% trans 'Notifications' %}">
50 50 {% trans 'Notifications' %}
51 51 {% ifnotequal new_notifications_count 0 %}
52 52 (<b>{{ new_notifications_count }}</b>)
53 53 {% endifnotequal %}
54 54 </a>
55 55 {% endif %}
56 56
57 57 <a class="right-link link" href="{% url 'settings' %}">{% trans 'Settings' %}</a>
58 58 </div>
59 59
60 60 <div id="fav-panel"><div class="post">{% trans "Loading..." %}</div></div>
61 61
62 62 {% block content %}{% endblock %}
63 63
64 64 <script src="{% static 'js/3party/jquery-ui.min.js' %}"></script>
65 65 <script src="{% static 'js/jquery.mousewheel.js' %}"></script>
66 66 <script src="{% static 'js/3party/highlight.min.js' %}"></script>
67 67
68 68 <script src="{% url 'js_info_dict' %}"></script>
69 69
70 70 <script src="{% static 'js/popup.js' %}"></script>
71 71 <script src="{% static 'js/image.js' %}"></script>
72 72 <script src="{% static 'js/refpopup.js' %}"></script>
73 73 <script src="{% static 'js/main.js' %}"></script>
74 74
75 75 <div class="navigation_panel footer">
76 76 {% block metapanel %}{% endblock %}
77 77 {% if rss_url %}
78 78 [<a href="{{ rss_url }}">RSS</a>]
79 79 {% endif %}
80 80 [<a href="{% url 'admin:index' %}">{% trans 'Admin' %}</a>]
81 81 [<a href="{% url 'index' %}?order=pub">{% trans 'New threads' %}</a>]
82 82 {% with ppd=posts_per_day|floatformat:2 %}
83 83 {% blocktrans %}Speed: {{ ppd }} posts per day{% endblocktrans %}
84 84 {% endwith %}
85 85 <a class="link" href="#top" id="up">{% trans 'Up' %}</a>
86 86 </div>
87 87
88 88 </body>
89 89 </html>
@@ -1,71 +1,70 b''
1 1 from django.core.urlresolvers import reverse
2 2 from django.shortcuts import render
3 3
4 4 from boards.abstracts.paginator import get_paginator
5 5 from boards.abstracts.settingsmanager import get_settings_manager
6 6 from boards.models import Post
7 7 from boards.views.base import BaseBoardView
8 8 from boards.views.posting_mixin import PostMixin
9 9
10 10 POSTS_PER_PAGE = 10
11 11
12 12 PARAMETER_CURRENT_PAGE = 'current_page'
13 13 PARAMETER_PAGINATOR = 'paginator'
14 14 PARAMETER_POSTS = 'posts'
15 PARAMETER_ADDITONAL_ATTRS = 'additional_attrs'
16 15
17 16 PARAMETER_PREV_LINK = 'prev_page_link'
18 17 PARAMETER_NEXT_LINK = 'next_page_link'
19 18
20 19 TEMPLATE = 'boards/feed.html'
21 20 DEFAULT_PAGE = 1
22 21
23 22
24 23 class FeedView(PostMixin, BaseBoardView):
25 24
26 25 def get(self, request):
27 26 page = request.GET.get('page', DEFAULT_PAGE)
28 27 tripcode = request.GET.get('tripcode', None)
28 favorites = 'favorites' in request.GET
29 29
30 30 params = self.get_context_data(request=request)
31 31
32 32 settings_manager = get_settings_manager(request)
33 33
34 34 posts = Post.objects.exclude(
35 35 threads__tags__in=settings_manager.get_hidden_tags()).order_by(
36 36 '-pub_time').prefetch_related('images', 'thread', 'threads')
37 37 if tripcode:
38 38 posts = posts.filter(tripcode=tripcode)
39 if favorites:
40 fav_thread_ops = Post.objects.filter(id__in=settings_manager.get_fav_threads().keys())
41 fav_threads = [op.get_thread() for op in fav_thread_ops]
42 posts = posts.filter(threads__in=fav_threads)
39 43
40 44 paginator = get_paginator(posts, POSTS_PER_PAGE)
41 45 paginator.current_page = int(page)
42 46
43 47 params[PARAMETER_POSTS] = paginator.page(page).object_list
44 48
45 additional_params = dict()
46 if tripcode:
47 additional_params['tripcode'] = tripcode
48 params[PARAMETER_ADDITONAL_ATTRS] = '&tripcode=' + tripcode
49
50 49 paginator.set_url(reverse('feed'), request.GET.dict())
51 50
52 51 self.get_page_context(paginator, params, page)
53 52
54 53 return render(request, TEMPLATE, params)
55 54
56 55 # TODO Dedup this into PagedMixin
57 56 def get_page_context(self, paginator, params, page):
58 57 """
59 58 Get pagination context variables
60 59 """
61 60
62 61 params[PARAMETER_PAGINATOR] = paginator
63 62 current_page = paginator.page(int(page))
64 63 params[PARAMETER_CURRENT_PAGE] = current_page
65 64 if current_page.has_previous():
66 65 params[PARAMETER_PREV_LINK] = paginator.get_page_url(
67 66 current_page.previous_page_number())
68 67 if current_page.has_next():
69 68 params[PARAMETER_NEXT_LINK] = paginator.get_page_url(
70 69 current_page.next_page_number())
71 70
General Comments 0
You need to be logged in to leave comments. Login now