예제 #1
0
def eventLog(request, page=0, pageLength=50):

    # Choose events within the given page, if any
    events = LogEvent.objects.all().order_by('-id')
    items = len(events)
    start = page * pageLength
    end = start + pageLength
    start = max(0, min(start, items))
    end = max(0, min(end, items))
    paging = pagingContext(page, pageLength, items, 'eventLog')

    # Build context dictionary for event log template
    data = {'events': events[start:end], 'paging': paging}

    return render(request, 'eventLog.html', data)
예제 #2
0
def index(request,
          page=0,
          pageLength=25,
          greens=False,
          username=None,
          error=''):

    # Get tests pending approval
    pending = Test.objects.filter(approved=False)
    pending = pending.exclude(finished=True)
    pending = pending.exclude(deleted=True)
    pending = pending.order_by('-creation')

    # Get tests currently running
    active = Test.objects.filter(approved=True)
    active = active.exclude(finished=True)
    active = active.exclude(deleted=True)
    active = active.order_by('-priority', '-currentllr')

    # Get the completed tests (sliced later)
    completed = Test.objects.filter(finished=True)
    completed = completed.exclude(deleted=True)
    completed = completed.order_by('-updated')

    # Pull data from active machines
    target = datetime.datetime.utcnow().replace(
        tzinfo=utc) - datetime.timedelta(minutes=10)
    machines = Machine.objects.filter(updated__gte=target)
    if username != None: machines = machines.filter(owner=username)

    # Extract stat information from workers
    machineCount = len(machines)
    threadCount = sum(machine.threads for machine in machines)
    npsTotal = sum(machine.threads * machine.mnps for machine in machines)
    workerData = "{0} Machines {1} Threads {2} MNPS".format(
        machineCount, threadCount, round(npsTotal, 2))

    # Index is wrapped for just viewing passed tests
    if greens == True:
        pending = active = []
        completed = completed.filter(passed=True)
        source = 'greens'

    # Index is wrapped just to view one user
    elif username != None:
        pending = pending.filter(author=username)
        active = active.filter(author=username)
        completed = completed.filter(author=username)
        source = "viewUser/{0}".format(username)

    # Index is normal, not wrapped for any views
    else:
        source = "index"

    # Choose tests within the given page, if any
    items = len(completed)
    start = page * pageLength
    end = start + pageLength
    start = max(0, min(start, items))
    end = max(0, min(end, items))
    paging = pagingContext(page, pageLength, items, source)

    # Build context dictionary for index template
    data = {
        'error': error,
        'pending': pending,
        'active': active,
        'completed': completed[start:end],
        'status': workerData,
        'greens': greens,
        'paging': paging,
    }

    return render(request, 'index.html', data)