Beispiel #1
0
def get_browse_tiles(viewer, nav):
    from apps.monster.models import MONSTER_GROUP, MonsterTileDetails

    #TODO an optimization - TileDetails gets the last reply itself even though get_front_comments already did.
    comments = get_front_comments(viewer, nav)

    if nav.category and nav.category.name == MONSTER_GROUP:
        materialize = lambda comments: MonsterTileDetails.from_queryset_with_viewer_stickers(viewer, comments)
    else:
        materialize = lambda comments: TileDetails.from_queryset_with_viewer_stickers(viewer, comments)

    tiles = materialize(comments)

    # Remove hidden threads.
    if viewer.is_authenticated():
        tiles = viewer.redis.hidden_threads.filter_comments(tiles, comment_key=lambda tile: tile.comment)

    return tiles
Beispiel #2
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)