Пример #1
0
def _get_post_data(post_id, format_type=DIFF_TYPE_JSON, request=None, include_last_update=False):
    if format_type == DIFF_TYPE_HTML:
        return get_post(request, post_id).content.strip()
    elif format_type == DIFF_TYPE_JSON:
        post = get_object_or_404(Post, id=post_id)
        post_json = {"id": post.id, "title": post.title, "text": post.text.rendered}
        if post.image:
            post_json["image"] = post.image.url
            post_json["image_preview"] = post.image.url_200x150
        if include_last_update:
            post_json["bump_time"] = datetime_to_epoch(post.thread_new.bump_time)
        return post_json
Пример #2
0
def api_get_thread_posts(request, opening_post_id):
    """
    Gets the JSON array of thread posts
    """

    opening_post = get_object_or_404(Post, id=opening_post_id)
    thread = opening_post.get_thread()
    posts = thread.get_replies()

    json_data = {"posts": [], "last_update": None}
    json_post_list = []

    for post in posts:
        json_post_list.append(_get_post_data(post.id))
    json_data["last_update"] = datetime_to_epoch(thread.last_edit_time)
    json_data["posts"] = json_post_list

    return HttpResponse(content=json.dumps(json_data))
Пример #3
0
    def get(self, request, post_id, mode=MODE_NORMAL, form=None):
        opening_post = get_object_or_404(Post, id=post_id)

        # If this is not OP, don't show it as it is
        if not opening_post.is_opening():
            raise Http404

        if not form:
            form = PostForm(error_class=PlainErrorList)

        thread_to_show = opening_post.get_thread()

        context = self.get_context_data(request=request)

        context[PARAMETER_FORM] = form
        context["last_update"] = utils.datetime_to_epoch(
            thread_to_show.last_edit_time)
        context["thread"] = thread_to_show

        if MODE_NORMAL == mode:
            context['bumpable'] = thread_to_show.can_bump()
            if context['bumpable']:
                context['posts_left'] = neboard.settings.MAX_POSTS_PER_THREAD \
                        - thread_to_show.get_reply_count()
                context['bumplimit_progress'] = str(
                    float(context['posts_left']) /
                    neboard.settings.MAX_POSTS_PER_THREAD * 100)

            context['opening_post'] = opening_post

            document = 'boards/thread.html'
        elif MODE_GALLERY == mode:
            posts = thread_to_show.get_replies()
            context['posts'] = posts.filter(image_width__gt=0)

            document = 'boards/thread_gallery.html'
        else:
            raise Http404

        return render(request, document, context)
Пример #4
0
def api_get_threaddiff(request, thread_id, last_update_time):
    """
    Gets posts that were changed or added since time
    """

    thread = get_object_or_404(Post, id=thread_id).thread_new

    filter_time = datetime.fromtimestamp(float(last_update_time) / 1000000, timezone.get_current_timezone())

    json_data = {"added": [], "updated": [], "last_update": None}
    added_posts = Post.objects.filter(thread_new=thread, pub_time__gt=filter_time).order_by("pub_time")
    updated_posts = Post.objects.filter(thread_new=thread, pub_time__lte=filter_time, last_edit_time__gt=filter_time)

    diff_type = DIFF_TYPE_HTML
    if PARAMETER_DIFF_TYPE in request.GET:
        diff_type = request.GET[PARAMETER_DIFF_TYPE]

    for post in added_posts:
        json_data["added"].append(_get_post_data(post.id, diff_type, request))
    for post in updated_posts:
        json_data["updated"].append(_get_post_data(post.id, diff_type, request))
    json_data["last_update"] = datetime_to_epoch(thread.last_edit_time)

    return HttpResponse(content=json.dumps(json_data))