Added bookmarkable new post URLs
This commit is contained in:
parent
5539f83783
commit
49b895a8a0
5 changed files with 29 additions and 30 deletions
|
@ -54,7 +54,7 @@
|
|||
{% endif %}
|
||||
<h3 {% if not topic|has_unreads:user %}class="topic_isread"{% endif %}>{% link topic %}</h3>
|
||||
<span class="byuser">{% trans "by" %} {{ topic.user.username }}</span>
|
||||
{% if topic|has_unreads:user %}<a href="{{ topic|forum_unread_link:user }}">{% trans "(New Posts)" %}</a>{% endif %}
|
||||
{% if topic|has_unreads:user %}<a href="{% url djangobb:topic_unread topic.id %}">{% trans "(New Posts)" %}</a>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
{% load forum_extras %}
|
||||
<ol class="topic list">{% for topic in topics %}{% with unread=topic|has_unreads:user %}
|
||||
<li class="{% if topic.sticky %}sticky {% endif %}{% if topic.closed %}closed {% endif %}{% if unread %}unread{% endif %}">
|
||||
<a class="item" href="{% if unread %}{{ topic|mobile_unread_link:user }}{% else %}{{ topic.get_mobile_url }}{% endif %}">
|
||||
<a class="item" href="{% if unread %}{% url djangobb:mobile_topic_unread topic.id %}{% else %}{{ topic.get_mobile_url }}{% endif %}">
|
||||
<strong>{{ topic.name }}</strong>
|
||||
<span>{% blocktrans count topic.reply_count as replies %}{{ replies }} reply{% plural %}{{ replies }} replies{% endblocktrans %}</span>
|
||||
</a>
|
||||
|
|
|
@ -137,33 +137,6 @@ def has_unreads(topic, user):
|
|||
return False
|
||||
return True
|
||||
|
||||
def forum_unread_object(topic, user):
|
||||
"""
|
||||
Returns the first unread post in a topic, or the topic if it post tracking does not exist for the given user.
|
||||
"""
|
||||
if user.posttracking is not None:
|
||||
topics = user.posttracking.topics;
|
||||
if isinstance(topics, dict):
|
||||
pk = topics.get(str(topic.id), 0)
|
||||
return Post.objects.filter(topic=topic, pk__gt=pk).order_by('pk')[0]
|
||||
last_read = user.posttracking.last_read
|
||||
if last_read is not None:
|
||||
posts = Post.objects.filter(Q(topic=topic) & (Q(created__gte=last_read) | Q(updated__gte=last_read))).order_by('pk')
|
||||
try:
|
||||
return posts[0]
|
||||
except Post.DoesNotExist:
|
||||
pass
|
||||
|
||||
return topic.posts.all()[0]
|
||||
|
||||
@register.filter
|
||||
def forum_unread_link(topic, user):
|
||||
return forum_unread_object(topic, user).get_absolute_url();
|
||||
|
||||
@register.filter
|
||||
def mobile_unread_link(topic, user):
|
||||
return forum_unread_object(topic, user).get_mobile_url();
|
||||
|
||||
@register.filter
|
||||
def forum_unreads(forum, user):
|
||||
"""
|
||||
|
|
|
@ -23,6 +23,7 @@ urlpatterns = patterns('',
|
|||
|
||||
# Topic
|
||||
url('^topic/(?P<topic_id>\d+)/$', forum_views.show_topic, name='topic'),
|
||||
url('^topic/(?P<topic_id>\d+)/unread/$', forum_views.show_unread_posts, name='topic_unread'),
|
||||
url('^topic/(?P<topic_id>\d+)/title/$', forum_views.get_topic_title, name='topic_title'),
|
||||
url(r'^(?P<forum_id>\d+)/topic/add/$', forum_views.add_topic, name='add_topic'),
|
||||
url('^topic/(?P<topic_id>\d+)/delete_posts/$', forum_views.delete_posts, name='delete_posts'),
|
||||
|
@ -67,6 +68,7 @@ if (forum_settings.LOFI_SUPPORT):
|
|||
url('^m/post/(?P<post_id>\d+)/$', forum_views.show_post, {'full':False}, name='mobile_post'),
|
||||
url('^m/post/(?P<post_id>\d+)/reply/$', forum_views.mobile_reply, name='mobile_reply'),
|
||||
url('^m/topic/(?P<topic_id>\d+)/$', forum_views.show_topic, {'full':False}, name='mobile_topic'),
|
||||
url('^m/topic/(?P<topic_id>\d+)/unread/$', forum_views.show_unread_posts, {'full':False}, name='mobile_topic_unread'),
|
||||
)
|
||||
|
||||
# REPUTATION Extension
|
||||
|
|
|
@ -15,7 +15,7 @@ from django.core.urlresolvers import reverse
|
|||
from django.db import transaction
|
||||
from django.db.models import Q, F
|
||||
from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponseForbidden
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
from django.shortcuts import get_object_or_404, render, redirect
|
||||
from django.utils.encoding import smart_str
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.utils import timezone
|
||||
|
@ -491,6 +491,30 @@ def show_topic(request, topic_id, full=True):
|
|||
'reply_form': reply_form,
|
||||
})
|
||||
|
||||
def show_unread_posts(request, topic_id, full=True):
|
||||
post = None
|
||||
user = request.user
|
||||
topic = get_object_or_404(Topic, pk=topic_id)
|
||||
if user.posttracking is not None:
|
||||
topics = user.posttracking.topics;
|
||||
if isinstance(topics, dict):
|
||||
pk = topics.get(str(topic_id), 0)
|
||||
try:
|
||||
post = Post.objects.filter(topic=topic, pk__gt=pk).order_by('pk')[0]
|
||||
except IndexError:
|
||||
pass
|
||||
else:
|
||||
last_read = user.posttracking.last_read
|
||||
if last_read is not None:
|
||||
posts = Post.objects.filter(Q(topic=topic) & (Q(created__gte=last_read) | Q(updated__gte=last_read))).order_by('pk')
|
||||
try:
|
||||
post = posts[0]
|
||||
except Post.DoesNotExist:
|
||||
pass
|
||||
if post is None:
|
||||
post = topic.last_post
|
||||
|
||||
return redirect(post.get_absolute_url() if full else post.get_mobile_url());
|
||||
|
||||
@login_required
|
||||
@transaction.commit_on_success
|
||||
|
|
Reference in a new issue