Example #1
0
def log_html(request, pk):
    log = _get_log(request, pk)

    if not log.pages.count():
        task_data = log.data.get('tasks')
        return render(request, 'discord_logview/loading.html', context={
            'task_ids': list(zip(task_data, task_messages[-len(task_data):])),
            'iso': pendulum.now().isoformat()
        })

    data = {'uuid': log.uuid}
    page = data['page'] = request.GET.get('page')
    msgs = [msg for msgs in [p.messages for p in log.pages.order_by('index')] for msg in msgs]
    data = _paginate_logs(msgs, data)
    if page:
        if not request.is_ajax():
            return redirect('log-html', pk=pk)
        return render(request, 'discord_logview/messages.html', context={'log': LiteLogRenderer(data)})

    if log.expires:
        if log.expires < pendulum.now():
            log.delete()
            raise Http404
        messages.info(request,
                      f'This log will expire on <time datetime="{log.expires.isoformat()}">'
                      f'{log.expires.strftime("%A, %B %d, %Y at %H:%M:%S UTC")}</time>')

    data = {**data, 'created': log.created, 'users': log.users, 'raw_content': log.content, 'raw_type': log.type,
            'type': all_types.get(log.type), 'user_id': None,
            'delete_token': signer.dumps(f'log.{pk}.{pendulum.now().isoformat()}') if log.owner == request.user
            else None,
            'total_messages': len(msgs)}

    return render(request, 'discord_logview/logs.html', context={'log': LogRenderer(data)})
Example #2
0
def log_html(request, pk):
    log = _get_log(request, pk)
    if not isinstance(log, Log):
        return log

    data = {'uuid': log.uuid, 'created': log.created, 'users': log.users, 'raw_content': log.content,
            'raw_type': log.type, 'type': all_types.get(log.type), 'user_id': None,
            'delete_token': signer.dumps(f'log.{pk}') if log.owner == request.user else None}

    log_pages = log.pages.order_by('index')
    if log_pages.count() > 1:
        data['chunked'] = True
    msgs = [msg for msgs in [p.messages for p in log_pages] for msg in msgs]
    data['total_messages'] = len(msgs)
    page = request.GET.get('page')
    if not request.is_ajax() and page:
        return redirect('log-html', pk=pk)

    paginator = Paginator(msgs, 100)
    try:
        msg_page = paginator.page(page)
    except PageNotAnInteger:
        msg_page = paginator.page(1)
    except EmptyPage:
        msg_page = paginator.page(paginator.num_pages)
    data['page'] = msg_page
    data['messages'] = msg_page.object_list
    return render(request, 'discord_logview/logs.html', context={'log': LogRenderer(data)})
Example #3
0
def log_preview(request, pk):
    data = request.session.get(pk)
    if not data:
        raise Http404('That log could not be found!')

    data = {'uuid': data['uuid'], 'created': pendulum.now(), 'users': data['data']['users'],
            'messages': data['data']['messages'], 'raw_content': data['content'], 'raw_type': data['type'],
            'type': all_types.get(data['type']), 'user_id': None, 'is_preview': True,
            'delete_token': signer.dumps(f'preview.{pk}')}

    msgs = data['messages']
    data['total_messages'] = len(msgs)
    page = request.GET.get('page')
    if not request.is_ajax() and page:
        return redirect('log-preview', pk=pk)

    paginator = Paginator(msgs, 100)
    if paginator.num_pages > 1:
        data['chunked'] = True
    try:
        msg_page = paginator.page(page)
    except PageNotAnInteger:
        msg_page = paginator.page(1)
    except EmptyPage:
        msg_page = paginator.page(paginator.num_pages)
    data['page'] = msg_page
    data['messages'] = msg_page.object_list
    messages.add_message(request, messages.INFO, 'This is a preview of what your log would look like. This URL cannot '
                                                 'be shared. If you like what you see, simply click the save icon. '
                                                 'If not, click the trash icon.')
    return render(request, 'discord_logview/logs.html', context={'log': LogRenderer(data)})
Example #4
0
def log_export(request, pk):
    log = _get_log(request, pk)

    data = {'uuid': log.uuid, 'created': log.created, 'users': log.users, 'raw_content': log.content,
            'raw_type': log.type, 'type': all_types.get(log.type), 'user_id': None}

    msgs = [msg for msgs in [p.messages for p in log.pages.order_by('index')] for msg in msgs]
    data['total_messages'] = len(msgs)
    data['messages'] = msgs
    return render(request, 'discord_logview/logs.html', context={'log': LogRenderer(data), 'export': True})
Example #5
0
def log_preview_export(request, pk):
    data = request.session.get(pk)
    if not data:
        raise Http404('That log could not be found!')

    data = {'uuid': data['uuid'], 'created': pendulum.now(), 'users': data['data']['users'],
            'messages': data['data']['messages'], 'raw_content': data['content'], 'raw_type': data['type'],
            'type': all_types.get(data['type']), 'user_id': None}

    data['total_messages'] = len(data['messages'])
    return render(request, 'discord_logview/logs.html', context={'log': LogRenderer(data), 'export': True})
Example #6
0
    msgs = session_data['data']['messages']
    data = _paginate_logs(msgs, data)
    if page:
        if not request.is_ajax():
            return redirect('log-preview-html', pk=pk)
        return render(request, 'discord_logview/messages.html', context={'log': LiteLogRenderer(data)})

    data = {**data, 'created': pendulum.now(), 'users': session_data['data']['users'],
            'raw_content': session_data['content'], 'raw_type': session_data['type'],
            'type': all_types.get(session_data['type']), 'user_id': None, 'is_preview': True,
            'delete_token': signer.dumps(f'preview.{pk}.{pendulum.now().isoformat()}'), 'total_messages': len(msgs)}

    messages.add_message(request, messages.INFO, 'This is a preview of what your log would look like. This URL cannot '
                                                 'be shared. If you like what you see, simply click the save icon. '
                                                 'If not, click the trash icon.')
    return render(request, 'discord_logview/logs.html', context={'log': LogRenderer(data)})


@login_required
def log_preview_save(request, pk):
    if not (data := request.session.get(pk)):
        raise Http404
    if Log.objects.filter(pk=pk).exists():
        log = Log.objects.get(pk=pk)
    else:
        log = save_preview(data, owner=request.user)
    del request.session[pk]
    return redirect('log-html', pk=log.pk)


@login_required