##// END OF EJS Templates
Added thread autoupdate. Currently has some bugs, not ready for merge with the main branch
neko259 -
r361:001d821b thread_autoupdate
parent child Browse files
Show More
@@ -0,0 +1,37 b''
1 var THREAD_UPDATE_DELAY = 10000;
2
3 var loading = false;
4
5 function updateThread() {
6 if (loading) {
7 return;
8 }
9
10 loading = true;
11
12 var threadPosts = $('div.thread').children('.post');
13
14 var lastPost = threadPosts.last();
15 var threadId = threadPosts.first().attr('id');
16 var lastPostId = lastPost.attr('id');
17
18 var diffUrl = '/api/diff_thread/' + threadId + '/' + lastPostId + '/';
19 $.getJSON(diffUrl)
20 .success(function(data) {
21 var addedPosts = data.added;
22
23 for (var i = 0; i < addedPosts.length; i++) {
24 var postText = addedPosts[i];
25
26 var post = $(postText).hide();
27 post.appendTo(lastPost.parent()).show('slow');
28 addRefLinkPreview(post[0]);
29
30 lastPost = post;
31 }
32
33 loading = false;
34 });
35 }
36
37 setInterval(updateThread, THREAD_UPDATE_DELAY);
@@ -28,7 +28,7 b' function showPostPreview(e) {'
28 var pNum = $(this).text().match(/\d+/);
28 var pNum = $(this).text().match(/\d+/);
29
29
30 if (pNum.length == 0) {
30 if (pNum.length == 0) {
31 return;
31 return;
32 }
32 }
33
33
34 //position
34 //position
@@ -72,19 +72,19 b' function showPostPreview(e) {'
72 //ajax api
72 //ajax api
73 else {
73 else {
74 $.ajax({
74 $.ajax({
75 url: '/api/post/' + pNum
75 url: '/api/post/' + pNum + '/'
76 })
76 })
77 .success(function(data) {
77 .success(function(data) {
78 // TODO get a json, not post itself
78 // TODO get a json, not post itself
79 var postdata = $(data).wrap("<div/>").parent().html();
79 var postdata = $(data).wrap("<div/>").parent().html();
80
80
81 //make preview
81 //make preview
82 mkPreview(cln, postdata);
82 mkPreview(cln, postdata);
83
83
84 })
84 })
85 .error(function() {
85 .error(function() {
86 cln.innerHTML = gettext('Post not found');
86 cln.innerHTML = gettext('Post not found');
87 });
87 });
88 }
88 }
89
89
90 $del(doc.getElementById(cln.id));
90 $del(doc.getElementById(cln.id));
@@ -1,14 +1,19 b''
1 {% load i18n %}
1 {% load i18n %}
2 {% load board %}
2 {% load board %}
3
3
4 <div class="post" id="{{ post.id }}">
4 {% if can_bump %}
5 <div class="post" id="{{ post.id }}">
6 {% else %}
7 <div class="post dead_post" id="{{ post.id }}">
8 {% endif %}
9
5 {% if post.image %}
10 {% if post.image %}
6 <div class="image">
11 <div class="image">
7 <a
12 <a
8 class="thumb"
13 class="thumb"
9 href="{{ post.image.url }}"><img
14 href="{{ post.image.url }}"><img
10 src="{{ post.image.url_200x150 }}"
15 src="{{ post.image.url_200x150 }}"
11 alt="{% trans 'Post image' %}"v
16 alt="{% trans 'Post image' %}"
12 data-width="{{ post.image_width }}"
17 data-width="{{ post.image_width }}"
13 data-height="{{ post.image_height }}"/>
18 data-height="{{ post.image_height }}"/>
14 </a>
19 </a>
@@ -18,8 +23,10 b''
18 <div class="post-info">
23 <div class="post-info">
19 <span class="title">{{ post.title }}</span>
24 <span class="title">{{ post.title }}</span>
20 <a class="post_id" href="#{{ post.id }}">
25 <a class="post_id" href="#{{ post.id }}">
21 (#{{ post.id }})</a>
26 ({{ post.id }})</a>
22 [{{ post.pub_time }}]
27 [{{ post.pub_time }}]
28 [<a href="#" onclick="javascript:addQuickReply('{{ post.id }}')
29 ; return false;">&gt;&gt;</a>]
23
30
24 {% if moderator %}
31 {% if moderator %}
25 <span class="moderator_info">
32 <span class="moderator_info">
@@ -34,22 +41,24 b''
34 {% autoescape off %}
41 {% autoescape off %}
35 {{ post.text.rendered }}
42 {{ post.text.rendered }}
36 {% endautoescape %}
43 {% endautoescape %}
37 <div class="refmap">
44 {% if post.is_referenced %}
38 {% trans "Replies" %}:
45 <div class="refmap">
39 {% for ref_post in post.get_sorted_referenced_posts %}
46 {% trans "Replies" %}:
40 <a href="{% post_url ref_post.id %}">&gt;&gt;{{ ref_post.id }}</a
47 {% for ref_post in post.get_sorted_referenced_posts %}
41 >{% if not forloop.last %},{% endif %}
48 <a href="{% post_url ref_post.id %}">&gt;&gt;{{ ref_post.id }}</a
42 {% endfor %}
49 >{% if not forloop.last %},{% endif %}
43 </div>
50 {% endfor %}
51 </div>
52 {% endif %}
44 </div>
53 </div>
45 {% if post.tags.exists %}
54 {% if post.tags.exists %}
46 <div class="metadata">
55 <div class="metadata">
47 <span class="tags">{% trans 'Tags' %}:
56 <span class="tags">{% trans 'Tags' %}:
48 {% for tag in post.tags.all %}
57 {% for tag in post.tags.all %}
49 <a class="tag" href="{% url 'tag' tag.name %}">
58 <a class="tag" href="{% url 'tag' tag.name %}">
50 {{ tag.name }}</a>
59 {{ tag.name }}</a>
51 {% endfor %}
60 {% endfor %}
52 </span>
61 </span>
53 </div>
62 </div>
54 {% endif %}
63 {% endif %}
55 </div> No newline at end of file
64 </div>
@@ -13,9 +13,10 b''
13 {% block content %}
13 {% block content %}
14 {% get_current_language as LANGUAGE_CODE %}
14 {% get_current_language as LANGUAGE_CODE %}
15
15
16 <script src="{% static 'js/thread_update.js' %}"></script>
16 <script src="{% static 'js/thread.js' %}"></script>
17 <script src="{% static 'js/thread.js' %}"></script>
17
18
18 {% if posts %}
19 {% if posts %}
19 {% cache 600 thread_view posts.0.last_edit_time moderator LANGUAGE_CODE %}
20 {% cache 600 thread_view posts.0.last_edit_time moderator LANGUAGE_CODE %}
20 {% if bumpable %}
21 {% if bumpable %}
21 <div class="bar-bg">
22 <div class="bar-bg">
@@ -27,7 +28,7 b''
27 </div>
28 </div>
28 {% endif %}
29 {% endif %}
29 <div class="thread">
30 <div class="thread">
30 {% for post in posts %}
31 {% for post in posts %}
31 {% if bumpable %}
32 {% if bumpable %}
32 <div class="post" id="{{ post.id }}">
33 <div class="post" id="{{ post.id }}">
33 {% else %}
34 {% else %}
@@ -67,7 +68,7 b''
67 {% autoescape off %}
68 {% autoescape off %}
68 {{ post.text.rendered }}
69 {{ post.text.rendered }}
69 {% endautoescape %}
70 {% endautoescape %}
70 {% if post.is_referenced %}
71 {% if post.is_referenced %}
71 <div class="refmap">
72 <div class="refmap">
72 {% trans "Replies" %}:
73 {% trans "Replies" %}:
73 {% for ref_post in post.get_sorted_referenced_posts %}
74 {% for ref_post in post.get_sorted_referenced_posts %}
@@ -89,15 +90,15 b''
89 </div>
90 </div>
90 {% endif %}
91 {% endif %}
91 </div>
92 </div>
92 {% endfor %}
93 {% endfor %}
93 </div>
94 </div>
94 {% endcache %}
95 {% endcache %}
95 {% endif %}
96 {% endif %}
96
97
97 <form id="form" enctype="multipart/form-data" method="post"
98 <form id="form" enctype="multipart/form-data" method="post"
98 >{% csrf_token %}
99 >{% csrf_token %}
99 <div class="post-form-w">
100 <div class="post-form-w">
100 <div class="form-title">{% trans "Reply to thread" %} #{{ posts.0.id }}</div>
101 <div class="form-title">{% trans "Reply to thread" %} #{{ posts.0.id }}</div>
101 <div class="post-form">
102 <div class="post-form">
102 <div class="form-row">
103 <div class="form-row">
103 <div class="form-label">{% trans 'Title' %}</div>
104 <div class="form-label">{% trans 'Title' %}</div>
@@ -53,4 +53,6 b" urlpatterns = patterns('',"
53
53
54 # API
54 # API
55 url(r'^api/post/(?P<post_id>\w+)/$', views.get_post, name="get_post"),
55 url(r'^api/post/(?P<post_id>\w+)/$', views.get_post, name="get_post"),
56 url(r'^api/diff_thread/(?P<thread_id>\w+)/(?P<last_post_id>\w+)/$',
57 views.api_get_threaddiff, name="get_thread_diff"),
56 )
58 )
@@ -1,4 +1,5 b''
1 import hashlib
1 import hashlib
2 import json
2 import string
3 import string
3 from django.core import serializers
4 from django.core import serializers
4 from django.core.urlresolvers import reverse
5 from django.core.urlresolvers import reverse
@@ -408,13 +409,28 b' def api_get_post(request, post_id):'
408 return HttpResponse(content=json)
409 return HttpResponse(content=json)
409
410
410
411
412 def api_get_threaddiff(request, thread_id, last_post_id):
413 thread = get_object_or_404(Post, id=thread_id)
414 posts = Post.objects.filter(thread=thread, id__gt=last_post_id)
415
416 json_data = {
417 'added': []
418 }
419 for post in posts:
420 json_data['added'].append(get_post(request, post.id).content.strip())
421
422 return HttpResponse(content=json.dumps(json_data))
423
424
411 def get_post(request, post_id):
425 def get_post(request, post_id):
412 """Get the html of a post. Used for popups."""
426 """Get the html of a post. Used for popups."""
413
427
414 post = get_object_or_404(Post, id=post_id)
428 post = get_object_or_404(Post, id=post_id)
429 thread = post.thread
415
430
416 context = RequestContext(request)
431 context = RequestContext(request)
417 context["post"] = post
432 context["post"] = post
433 context["can_bump"] = thread.can_bump()
418
434
419 return render(request, 'boards/post.html', context)
435 return render(request, 'boards/post.html', context)
420
436
General Comments 0
You need to be logged in to leave comments. Login now