Show More
@@ -47,6 +47,8 b' class PostManager(models.Manager):' | |||||
47 |
|
47 | |||
48 | def create_post(self, title, text, image=None, thread=None, |
|
48 | def create_post(self, title, text, image=None, thread=None, | |
49 | ip=NO_IP, tags=None, user=None): |
|
49 | ip=NO_IP, tags=None, user=None): | |
|
50 | posting_time = timezone.now() | |||
|
51 | ||||
50 | post = self.create(title=title, |
|
52 | post = self.create(title=title, | |
51 | text=text, |
|
53 | text=text, | |
52 | pub_time=timezone.now(), |
|
54 | pub_time=timezone.now(), | |
@@ -54,8 +56,8 b' class PostManager(models.Manager):' | |||||
54 | image=image, |
|
56 | image=image, | |
55 | poster_ip=ip, |
|
57 | poster_ip=ip, | |
56 | poster_user_agent=UNKNOWN_UA, |
|
58 | poster_user_agent=UNKNOWN_UA, | |
57 |
last_edit_time=ti |
|
59 | last_edit_time=posting_time, | |
58 |
bump_time=ti |
|
60 | bump_time=posting_time, | |
59 | user=user) |
|
61 | user=user) | |
60 |
|
62 | |||
61 | if tags: |
|
63 | if tags: | |
@@ -66,7 +68,7 b' class PostManager(models.Manager):' | |||||
66 | if thread: |
|
68 | if thread: | |
67 | thread.replies.add(post) |
|
69 | thread.replies.add(post) | |
68 | thread.bump() |
|
70 | thread.bump() | |
69 |
thread.last_edit_time = ti |
|
71 | thread.last_edit_time = posting_time | |
70 | thread.save() |
|
72 | thread.save() | |
71 |
|
73 | |||
72 | #cache_key = thread.get_cache_key() |
|
74 | #cache_key = thread.get_cache_key() |
@@ -2,6 +2,7 b' import hashlib' | |||||
2 | import json |
|
2 | import json | |
3 | import string |
|
3 | import string | |
4 | import time |
|
4 | import time | |
|
5 | import calendar | |||
5 |
|
6 | |||
6 | from datetime import datetime |
|
7 | from datetime import datetime | |
7 |
|
8 | |||
@@ -215,9 +216,7 b' def thread(request, post_id):' | |||||
215 | context['bumplimit_progress'] = str( |
|
216 | context['bumplimit_progress'] = str( | |
216 | float(context['posts_left']) / |
|
217 | float(context['posts_left']) / | |
217 | neboard.settings.MAX_POSTS_PER_THREAD * 100) |
|
218 | neboard.settings.MAX_POSTS_PER_THREAD * 100) | |
218 | # TODO This last update time may not be accurate cause some posts can be |
|
219 | context["last_update"] = _datetime_to_epoch(posts[0].last_edit_time) | |
219 | # changed or added after this point. See the diff method. |
|
|||
220 | context["last_update"] = int(time.time() * 1000) |
|
|||
221 |
|
220 | |||
222 | return render(request, 'boards/thread.html', context) |
|
221 | return render(request, 'boards/thread.html', context) | |
223 |
|
222 | |||
@@ -253,23 +252,23 b' def settings(request):' | |||||
253 | is_moderator = user.is_moderator() |
|
252 | is_moderator = user.is_moderator() | |
254 |
|
253 | |||
255 | if request.method == 'POST': |
|
254 | if request.method == 'POST': | |
256 |
|
|
255 | with transaction.commit_on_success(): | |
257 |
|
|
256 | if is_moderator: | |
258 |
|
|
257 | form = ModeratorSettingsForm(request.POST, | |
259 | error_class=PlainErrorList) |
|
258 | error_class=PlainErrorList) | |
260 |
|
|
259 | else: | |
261 |
|
|
260 | form = SettingsForm(request.POST, error_class=PlainErrorList) | |
262 |
|
261 | |||
263 |
|
|
262 | if form.is_valid(): | |
264 |
|
|
263 | selected_theme = form.cleaned_data['theme'] | |
265 |
|
264 | |||
266 |
|
|
265 | user.save_setting('theme', selected_theme) | |
267 |
|
266 | |||
268 |
|
|
267 | if is_moderator: | |
269 |
|
|
268 | moderate = form.cleaned_data['moderate'] | |
270 |
|
|
269 | user.save_setting(SETTING_MODERATE, moderate) | |
271 |
|
270 | |||
272 |
|
|
271 | return redirect(settings) | |
273 | else: |
|
272 | else: | |
274 | selected_theme = _get_theme(request) |
|
273 | selected_theme = _get_theme(request) | |
275 |
|
274 | |||
@@ -326,7 +325,7 b' def delete(request, post_id):' | |||||
326 | if user.is_moderator(): |
|
325 | if user.is_moderator(): | |
327 | # TODO Show confirmation page before deletion |
|
326 | # TODO Show confirmation page before deletion | |
328 | Post.objects.delete_post(post) |
|
327 | Post.objects.delete_post(post) | |
329 |
|
328 | |||
330 | if not post.thread: |
|
329 | if not post.thread: | |
331 | return _redirect_to_next(request) |
|
330 | return _redirect_to_next(request) | |
332 | else: |
|
331 | else: | |
@@ -417,25 +416,27 b' def api_get_post(request, post_id):' | |||||
417 |
|
416 | |||
418 |
|
417 | |||
419 | def api_get_threaddiff(request, thread_id, last_update_time): |
|
418 | def api_get_threaddiff(request, thread_id, last_update_time): | |
|
419 | """Get posts that were changed or added since time""" | |||
|
420 | ||||
420 | thread = get_object_or_404(Post, id=thread_id) |
|
421 | thread = get_object_or_404(Post, id=thread_id) | |
421 |
|
422 | |||
422 |
filter_time = datetime.fromtimestamp(float(last_update_time) / 1000 |
|
423 | filter_time = datetime.fromtimestamp(float(last_update_time) / 1000, | |
|
424 | timezone.get_current_timezone()) | |||
423 |
|
425 | |||
424 | # TODO Set the last update date more properly, cause new posts can be |
|
|||
425 | # changed after this point. Perhaps we need to get it from the thread last |
|
|||
426 | # update time at the point of filtering, or as the latest post update time. |
|
|||
427 | json_data = { |
|
426 | json_data = { | |
428 | 'added': [], |
|
427 | 'added': [], | |
429 | 'updated': [], |
|
428 | 'updated': [], | |
430 |
'last_update' |
|
429 | 'last_update': None, | |
431 | } |
|
430 | } | |
432 | added_posts = Post.objects.filter(thread=thread, pub_time__gt=filter_time) |
|
431 | added_posts = Post.objects.filter(thread=thread, pub_time__gt=filter_time) | |
433 | updated_posts = Post.objects.filter(thread=thread, |
|
432 | updated_posts = Post.objects.filter(thread=thread, | |
434 | pub_time__lt=filter_time, last_edit_time__gt=filter_time) |
|
433 | pub_time__lt=filter_time, | |
|
434 | last_edit_time__gt=filter_time) | |||
435 | for post in added_posts: |
|
435 | for post in added_posts: | |
436 | json_data['added'].append(get_post(request, post.id).content.strip()) |
|
436 | json_data['added'].append(get_post(request, post.id).content.strip()) | |
437 | for post in updated_posts: |
|
437 | for post in updated_posts: | |
438 | json_data['updated'].append(get_post(request, post.id).content.strip()) |
|
438 | json_data['updated'].append(get_post(request, post.id).content.strip()) | |
|
439 | json_data['last_update'] = _datetime_to_epoch(thread.last_edit_time) | |||
439 |
|
440 | |||
440 | return HttpResponse(content=json.dumps(json_data)) |
|
441 | return HttpResponse(content=json.dumps(json_data)) | |
441 |
|
442 | |||
@@ -554,3 +555,9 b' def _remove_invalid_links(text):' | |||||
554 | text = string.replace(text, '>>' + id, id) |
|
555 | text = string.replace(text, '>>' + id, id) | |
555 |
|
556 | |||
556 | return text |
|
557 | return text | |
|
558 | ||||
|
559 | ||||
|
560 | def _datetime_to_epoch(datetime): | |||
|
561 | return int(time.mktime(timezone.localtime( | |||
|
562 | datetime,timezone.get_current_timezone()).timetuple()) | |||
|
563 | * 1000 + datetime.microsecond) No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now