Ejemplo n.º 1
0
def thread(request, short_id, page=None, gotoreply=None, sort_by_top=False,
           template_name='comment/new_base_thread.django.html'):
    from apps.monster.models import MONSTER_GROUP

    if not request.user.is_authenticated() and template_name == 'comment/new_base_thread.django.html' and not features.thread_new(request):
        return logged_out_thread_view(request, short_id, page=page, gotoreply=gotoreply)

    view_data = CommentViewData(request, short_id, page=page, gotoreply=gotoreply)

    if '/p/' + short_id == request.user.kv.post_pending_signup_url.get():
        request.user.kv.post_pending_signup_url.delete()

    ctx = view_data.thread_context()

    ctx['request'] = request

    # monstermash posts redirect to monstermash app
    if ctx['op_comment'].category == MONSTER_GROUP and not ctx['viewer_is_staff']:
        return HttpResponseRedirect('/monster/{0}'.format(ctx['op_comment'].short_id()))

    # all hidden group posts are invisible to normal users
    if ctx['op_comment'].category in settings.HIDDEN_GROUPS and not ctx['viewer_is_staff']:
        return Http404()

    # If we hit the size threshold, record metric that the user is viewing a large thread
    if ctx['large_thread_view']:
        Metrics.large_thread_view.record(request)

    ctx['remix_invite_share_view'] = 'rmi' in request.GET
    if ctx['remix_invite_share_view']:
        ctx['fb_metadata']['title'] = "Come Remix With Me!"
        if ctx['op_comment'].title:
            ctx['fb_metadata']['description'] = """I just started a thread on Canvas, "{0}". Click the link to add your remix to the thread!""".format(op_comment.title)
        else:
            ctx['fb_metadata']['description'] = "I just started a thread on Canvas. Click the link to add your remix to the thread!"

    # Inviting experiment
    ctx['is_in_invite_remixers_v2'] = False

    ctx.update({
        'request': request,
        'sort_by_top': sort_by_top,
    })

    if request.is_mobile:
        return r2r_jinja("mobile/thread.html", ctx)

    if features.thread_new(request):
        ctx['has_top_remixes'] = bool(len(ctx['top_remixes']))
        if sort_by_top:
            ctx['replies'] = ctx['top_remixes']
            ctx['has_top_remixes'] = True

        return r2r_jinja('threads_new/thread.html', ctx, request)

    return r2r(template_name, ctx)
Ejemplo n.º 2
0
def logged_out_thread_view(request, short_id, page=None, gotoreply=None):
    view_data = CommentViewData(request, short_id, page=page, gotoreply=gotoreply)

    ctx = view_data.thread_context()

    if request.is_mobile:
        return r2r_jinja('mobile/thread.html', ctx)

    fact.record('flow_start', request, {})

    return render_to_response('threads/new_thread.django.html', ctx, context_instance=RequestContext(request))
Ejemplo n.º 3
0
def api_monster_details(request, short_id, payload={}):
    view_data = CommentViewData(request, short_id)
    main_comment = view_data.op_comment
    replies = [Comment.details_by_id(cid) for cid in view_data.reply_ids]
    has_replies = len(replies) > 0

    (
        (main_comment,),
        replies
    ) = CachedCall.many_multicall(
        [main_comment],
        replies,
    )

    treplies = []
    made_bottom = False
    for reply in replies:
        cur = reply.to_client()
        if reply.real_author == request.user.username:
            cur['current_user_authored'] = made_bottom = True
        treplies.append(cur)

    ctx = {
        'top': main_comment,
        'bottoms': treplies,
        'current_user_made_bottom': made_bottom,
        'current_user_made_top': main_comment.real_author == request.user.username,
        'start_content': Content.all_objects.get(id=Content.SMALL_DRAW_FROM_SCRATCH_PK).details(),
    }

    return ctx
Ejemplo n.º 4
0
def share_detail(request, *args, **kwargs):
    if request.user.is_authenticated():
        view_data = CommentViewData(request, *args, **kwargs)
        return HttpResponseRedirect(view_data.linked_comment().url)

    return apps.threads.views.logged_out_thread_view(request, *args, **kwargs)
Ejemplo n.º 5
0
def share_detail(request, *args, **kwargs):
    if request.user.is_authenticated():
        view_data = CommentViewData(request, *args, **kwargs)
        return HttpResponseRedirect(view_data.linked_comment().url)

    return apps.threads.views.logged_out_thread_view(request, *args, **kwargs)
Ejemplo n.º 6
0
def view(request, short_id, option=None):
    from apps.monster.jinja_tags import monster_image_tile

    view_data = CommentViewData(request, short_id)
    main_comment = view_data.op_comment
    replies = [Comment.details_by_id(cid) for cid in view_data.reply_ids]
    has_replies = len(replies) > 0
    complete_link = option and (option == 'complete')
    if complete_link and request.user.is_anonymous():
        fact.record('monster_start_flow', request, {'monster_id': short_id})
    reply_id = None

    if option:
        try:
            reply_id = int(option)
        except ValueError:
            pass

    (
        (main_comment,),
        replies
    ) = CachedCall.many_multicall(
        [main_comment],
        replies,
    )

    replies = [reply for reply in replies if not reply.is_collapsed]

    monster_part = MonsterPart.get_by_comment(main_comment)
    main_comment_details = main_comment
    main_comment = TileDetails(main_comment)

    made_bottom = False
    made_top = main_comment.comment.real_author == request.user.username

    linked_monster_footer_image = ""
    current_monster_index = 0

    for i in range(len(replies)):
        reply = replies[i]
        if reply_id is not None and reply.id == int(reply_id):
            current_monster_index = i
        elif reply.real_author == request.user.username and reply_id is None:
            current_monster_index = i
            made_bottom = True

    try:
        if (has_replies
                and replies[current_monster_index].reply_content
                and replies[current_monster_index].reply_content.footer):
            linked_monster_footer_image = replies[current_monster_index].reply_content.footer['name']
    except (AttributeError, IndexError):
        pass

    made_part = made_top or made_bottom

    if made_part:
        CompletedMonsterSet(request.user).sadd(main_comment.comment.id)

    can_make_bottom = (not made_part) and complete_link
    can_invite = made_top

    # incomplete monster without an invite link, send to monster index
    if not has_replies and not complete_link and not can_invite:
        return HttpResponseRedirect('/monster')

    ctx = {
        'can_invite': can_invite,
        'can_make_bottom': can_make_bottom,
        'current_monster_index': current_monster_index,
        'domain': settings.DOMAIN,
        'made_bottom': made_bottom,
        'made_part': made_part,
        'made_top': made_top,
        'main_comment': main_comment,
        'monster_content': main_comment.comment.reply_content,
        'og_image_url': linked_monster_footer_image.replace("https", "http", 1),
        'monster_group': MONSTER_GROUP,
        'monster_name': main_comment.comment.title,
        'replies': MonsterTileDetails.from_shared_op_details_with_viewer_stickers(request.user, main_comment_details, replies),
        'request': request,
        'short_id': main_comment.comment.short_id(),
        'start_content': Content.all_objects.get(id=Content.SMALL_DRAW_FROM_SCRATCH_PK).details(),
    }

    return r2r_jinja('monster/view.html', ctx)