@login_required
@permission_required('accounts.access_moderators_section')
def view_logs(request):

    # Exclude logs about the logged in user (moderator)
    logs = ModerationLogMsg.objects.exclude(
        pertains_to=request.user
    ).order_by(
        '-msg_datetime'
    ).select_related(
        'pertains_to',
        'logged_by',
    )

    form = FilterLogsForm()

    # TODO: Get logged in user's timezone
    # TODO: Apply activate() to logged in user's timezone
    # TODO: Get user's preferred timezone

    local_tz = timezone.get_current_timezone()
    today = timezone.now().astimezone(local_tz)

    if request.method == 'GET':
        form = FilterLogsForm(request.GET)

        if form.is_valid():

            msg_type = form.cleaned_data['msg_type']
            period = form.cleaned_data['period']

            if period == 'TODAY':
                start, end = get_date_limits(start_date=today)

            elif period == 'YESTERDAY':
                yesterday = today - timezone.timedelta(days=1)
                start, end = get_date_limits(start_date=yesterday)

            elif period == 'THIS_WEEK':
                start_date = today - timezone.timedelta(days=7)
                end_date = today

                start, end = get_date_limits(start_date, end_date)

            elif period == 'CUSTOM':
                start_date = form.cleaned_data['start_date']
                end_date = form.cleaned_data['end_date']

                start, end = get_date_limits(start_date, end_date)

            # Filter Logs
            if msg_type != 'ALL':
                logs = logs.filter(msg_type=msg_type)

            if period != 'ALL':
                logs = logs.filter(msg_datetime__gte=start,
                                   msg_datetime__lte=end)

    context = {
        'form': form,
        'logs': logs,
    }

    return render(request, 'moderation/logs.html', context)
dataset/ETHPy150Open nlhkabu/connect/connect/moderation/views.py/view_logs/original