Beispiel #1
0
def status(request):
    if not checkRequestParams(request, ['apiKey', 'hitType']):
        return HttpResponse('Bad params')

    params = request.POST
    try:
        proto = ProtoHit.objects.get(hit_type_id=params['hitType'])
        return HttpResponse(str(proto.sandbox).lower())
    except ProtoHit.DoesNotExist:
        return HttpResponse('ProtoHit.DoesNotExist')

    return HttpResponse('OK')
Beispiel #2
0
def status(request):
    if not checkRequestParams(request, ['apiKey', 'hitType']):
        return HttpResponse('Bad params')
    
    params = request.POST
    try:
        proto = ProtoHit.objects.get(hit_type_id=params['hitType'])
        return HttpResponse(str(proto.sandbox).lower())
    except ProtoHit.DoesNotExist:
        return HttpResponse('ProtoHit.DoesNotExist')
    
    return HttpResponse('OK')
Beispiel #3
0
def toggle_sandbox(request):
    if not checkRequestParams(request, ['apiKey', 'id', 'value']):
        return HttpResponse('Bad params')
    
    params = request.POST
    try:
        proto = ProtoHit.objects.get(id = int(params['id']))
        proto.sandbox = bool(params.value)
        proto.save()
        return HttpResponse('OK')
    except ProtoHIT.DoesNotExist:
        return HttpResponse('ProtoHIT.DoesNotExist')
Beispiel #4
0
def toggle_sandbox(request):
    if not checkRequestParams(request, ['apiKey', 'id', 'value']):
        return HttpResponse('Bad params')

    params = request.POST
    try:
        proto = ProtoHit.objects.get(id=int(params['id']))
        proto.sandbox = bool(params.value)
        proto.save()
        return HttpResponse('OK')
    except ProtoHIT.DoesNotExist:
        return HttpResponse('ProtoHIT.DoesNotExist')
Beispiel #5
0
def unfinish(request):
    # mark a reservation as "un"-finished... typically for debugging
    if not checkRequestParams(request, ['apiKey', 'id']):
        return HttpResponse('Bad params')
    
    params = request.POST
    try:
        resv = WorkReservation.objects.get(id = int(params['id']))
        resv.done = False
        resv.save()
        return HttpResponse('OK')
    except WorkReservation.DoesNotExist:
        return HttpResponse('WorkReservation.DoesNotExist')
Beispiel #6
0
def finish(request):
    # mark a reservation as successfully finished
    if not checkRequestParams(request, ['apiKey', 'id']):
        return HttpResponse('Bad params')
    
    params = request.POST
    try:
        resv = WorkReservation.objects.get(id = int(params['id']))
        resv.done = True
        resv.save()
        return HttpResponse('OK')
    except WorkReservation.DoesNotExist:
        return HttpResponse('WorkReservation.DoesNotExist')
Beispiel #7
0
def finish(request):
    # mark a reservation as successfully finished
    if not checkRequestParams(request, ['apiKey', 'id']):
        return HttpResponse('Bad params')

    params = request.POST
    try:
        resv = WorkReservation.objects.get(id=int(params['id']))
        resv.done = True
        resv.save()
        return HttpResponse('OK')
    except WorkReservation.DoesNotExist:
        return HttpResponse('WorkReservation.DoesNotExist')
Beispiel #8
0
def unfinish(request):
    # mark a reservation as "un"-finished... typically for debugging
    if not checkRequestParams(request, ['apiKey', 'id']):
        return HttpResponse('Bad params')

    params = request.POST
    try:
        resv = WorkReservation.objects.get(id=int(params['id']))
        resv.done = False
        resv.save()
        return HttpResponse('OK')
    except WorkReservation.DoesNotExist:
        return HttpResponse('WorkReservation.DoesNotExist')
Beispiel #9
0
def list(request):
    # query this server to get info about all reservations being serviced
    if not checkRequestParams(request, ['apiKey']):
        return HttpResponse('Bad params')
    
    resvs = []
    
    for resv in WorkReservation.objects.order_by('-id')[:25]:
        resvs.append(resv.objectify)
    
    #resvs.reverse() # all of this interesting ordering stuff is so the newest 25 reservations are at the top
    data = json.dumps(resvs)
    
    return HttpResponse(data)
Beispiel #10
0
def cancel(request):
    # prematurely cancel a reservation.  perhaps because an end user stopped the app
    if not checkRequestParams(request, ['apiKey', 'id']):
        return HttpResponse('Bad params')

    params = request.POST
    try:
        resv = WorkReservation.objects.get(id=int(params['id']))
        resv.done = True
        resv.save()
        return HttpResponse('OK')
    except WorkReservation.DoesNotExist:
        return HttpResponse('WorkReservation.DoesNotExist')
    return HttpResponse('OK')
Beispiel #11
0
def cancel(request):
    # prematurely cancel a reservation.  perhaps because an end user stopped the app
    if not checkRequestParams(request, ['apiKey', 'id']):
        return HttpResponse('Bad params')
    
    params = request.POST
    try:
        resv = WorkReservation.objects.get(id=int(params['id']))
        resv.done = True
        resv.save()
        return HttpResponse('OK')
    except WorkReservation.DoesNotExist:
        return HttpResponse('WorkReservation.DoesNotExist')
    return HttpResponse('OK')
Beispiel #12
0
def list(request):
    # query this server to get info about all reservations being serviced
    if not checkRequestParams(request, ['apiKey']):
        return HttpResponse('Bad params')

    resvs = []

    for resv in WorkReservation.objects.order_by('-id')[:25]:
        resvs.append(resv.objectify)

    #resvs.reverse() # all of this interesting ordering stuff is so the newest 25 reservations are at the top
    data = json.dumps(resvs)

    return HttpResponse(data)
Beispiel #13
0
def finishAll(request):
    # mark a reservation as successfully finished
    if not checkRequestParams(request, ['apiKey', 'hitType']):
        return HttpResponse('Bad params')
    
    params = request.POST
    
    if params['hitType'] == '':
        resvs = WorkReservation.objects.all()
    else:
        resvs = WorkReservation.objects.filter(proto__hit_type_id = params['hitType'])
            
    for resv in resvs:
        resv.done = True
        resv.save()
    return HttpResponse('OK')
Beispiel #14
0
def invoke(request):
    # supply an existing WorkReservation ID, and call it to action.
    # this will also happen automatically once the reservation's 'startTime' is reached
    if not checkRequestParams(request, ['apiKey', 'id']):
        return HttpResponse('Bad params')
    
    params = request.POST
    try:
        resv = WorkReservation.objects.get(id = int(params['id']))
        if 'foreignID' in params:
            resv.foreign_id = int(params['foreignID'])
        resv.invoked = True
        resv.save()
        
        return HttpResponse('OK')
    except WorkReservation.DoesNotExist:
        return HttpResponse('WorkReservation.DoesNotExist')
Beispiel #15
0
def toggle(request):
    if not checkRequestParams(request, ['apiKey', 'hitType', 'sandbox']):
        return HttpResponse('Bad params')

    params = request.POST
    try:
        proto = ProtoHit.objects.get(hit_type_id=params['hitType'])
        proto.sandbox = params['sandbox'] == 'true'
        print(params['sandbox'])
        print(proto.sandbox)
        proto.save()

        return HttpResponse('OK')
    except ProtoHit.DoesNotExist:
        return HttpResponse('ProtoHit.DoesNotExist')

    return HttpResponse('OK')
Beispiel #16
0
def toggle(request):
    if not checkRequestParams(request, ['apiKey', 'hitType', 'sandbox']):
        return HttpResponse('Bad params')
    
    params = request.POST
    try:
        proto = ProtoHit.objects.get(hit_type_id=params['hitType'])
        proto.sandbox = params['sandbox'] == 'true'
        print(params['sandbox'])
        print(proto.sandbox)
        proto.save()
        
        return HttpResponse('OK')
    except ProtoHit.DoesNotExist:
        return HttpResponse('ProtoHit.DoesNotExist')
    
    return HttpResponse('OK')
Beispiel #17
0
def invoke(request):
    # supply an existing WorkReservation ID, and call it to action.
    # this will also happen automatically once the reservation's 'startTime' is reached
    if not checkRequestParams(request, ['apiKey', 'id']):
        return HttpResponse('Bad params')

    params = request.POST
    try:
        resv = WorkReservation.objects.get(id=int(params['id']))
        if 'foreignID' in params:
            resv.foreign_id = int(params['foreignID'])
        resv.invoked = True
        resv.save()

        return HttpResponse('OK')
    except WorkReservation.DoesNotExist:
        return HttpResponse('WorkReservation.DoesNotExist')
Beispiel #18
0
def finishAll(request):
    # mark a reservation as successfully finished
    if not checkRequestParams(request, ['apiKey', 'hitType']):
        return HttpResponse('Bad params')

    params = request.POST

    if params['hitType'] == '':
        resvs = WorkReservation.objects.all()
    else:
        resvs = WorkReservation.objects.filter(
            proto__hit_type_id=params['hitType'])

    for resv in resvs:
        resv.done = True
        resv.save()
    return HttpResponse('OK')
Beispiel #19
0
def make(request):
   # initialize a WorkReservation, for some time in the future
   if not checkRequestParams(request, ['apiKey', 'hitType', 'foreignID', 'delay', 'numAssignments']):
       return HttpResponse('Bad params')
   
   params = request.POST
   try:
       proto = ProtoHit.objects.get(hit_type_id=params['hitType'])
       foreign_id = int(params['foreignID'])
       payload = params['payload'] if 'payload' in params else ''
       resv = WorkReservation(proto = proto, \
           foreign_id = foreign_id, \
           payload = payload, \
           start_time = unixtime(datetime.now() + timedelta(seconds = int(params['delay']))), \
           assignments = int(params['numAssignments']), \
           done = False, \
           invoked = False)
       resv.save()
       
       return HttpResponse(resv.id)
   except ProtoHit.DoesNotExist:
       return HttpResponse('ProtoHit.DoesNotExist')
Beispiel #20
0
def make(request):
    # initialize a WorkReservation, for some time in the future
    if not checkRequestParams(
            request,
        ['apiKey', 'hitType', 'foreignID', 'delay', 'numAssignments']):
        return HttpResponse('Bad params')

    params = request.POST
    try:
        proto = ProtoHit.objects.get(hit_type_id=params['hitType'])
        foreign_id = int(params['foreignID'])
        payload = params['payload'] if 'payload' in params else ''
        resv = WorkReservation(proto = proto, \
            foreign_id = foreign_id, \
            payload = payload, \
            start_time = unixtime(datetime.now() + timedelta(seconds = int(params['delay']))), \
            assignments = int(params['numAssignments']), \
            done = False, \
            invoked = False)
        resv.save()

        return HttpResponse(resv.id)
    except ProtoHit.DoesNotExist:
        return HttpResponse('ProtoHit.DoesNotExist')