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