Exemple #1
0
def approve_experiment(modeladmin, request, queryset):
    for obj in queryset:
        # define default response
        response = {"err": "", "data": ""}
        # return if GET request
        if request.method == 'GET':
            response['err'] = {'no': 'err0', 'msg': 'sorry no gets'}
            return HttpResponseRedirect('/error/')

        dev_ids = obj.dev.all()
        app_ids = obj.app.all()
        transact = Transaction()
        transact.eid = obj
        transact.user = User.objects.get(id__in=obj.user.all)
        transact.total = len(dev_ids) * len(app_ids)
        transact.progress = 0

    #Check Data Validation
    for dev_id in dev_ids:
        for app_id in app_ids:
            #check FailureAlready(F1)
            if DeviceApplication.objects.filter(dev=dev_id).filter(app=app_id):
                response['err'] = {
                    'no': 'err1',
                    'msg': 'The application is already installed'
                }
                return json_response_from(response)

    #insert the data from POST method
    for dev_id in dev_ids:
        for app_id in app_ids:
            transact.save()
            t_id = transact.id
            trndevapp = TransactionDevApp()
            trndevapp.tid = Transaction.objects.get(id=t_id)
            trndevapp.dev = dev_id
            trndevapp.app = app_id
            trndevapp.action = 'I'
            trndevapp.result = "N"  # N is N/A
            trndevapp.save()
            Device.objects.filter(id=dev_id.id).update(active="D")

    msg = "new_manifest"
    for dev_id in dev_ids:
        Device.objects.get(id=dev_id.id).send_message(
            payload=json({"message": msg}))

    eprofile = ExperimentProfile.objects.get(experiment=obj)
    eprofile.starttime = datetime.now()
    print obj.period
    endtime = datetime.now() + timedelta(int(obj.period))
    print endtime
    eprofile.endtime = endtime
    eprofile.save()
    queryset.update(active=1)
Exemple #2
0
def approve_experiment(modeladmin, request, queryset):
    for obj in queryset:
        # define default response
        response = {"err": "", "data": ""}
        # return if GET request
        if request.method == "GET":
            response["err"] = {"no": "err0", "msg": "sorry no gets"}
            return HttpResponseRedirect("/error/")

        dev_ids = obj.dev.all()
        app_ids = obj.app.all()
        transact = Transaction()
        transact.eid = obj
        transact.user = User.objects.get(id__in=obj.user.all)
        transact.total = len(dev_ids) * len(app_ids)
        transact.progress = 0

    # Check Data Validation
    for dev_id in dev_ids:
        for app_id in app_ids:
            # check FailureAlready(F1)
            if DeviceApplication.objects.filter(dev=dev_id).filter(app=app_id):
                response["err"] = {"no": "err1", "msg": "The application is already installed"}
                return json_response_from(response)

    # insert the data from POST method
    for dev_id in dev_ids:
        for app_id in app_ids:
            transact.save()
            t_id = transact.id
            trndevapp = TransactionDevApp()
            trndevapp.tid = Transaction.objects.get(id=t_id)
            trndevapp.dev = dev_id
            trndevapp.app = app_id
            trndevapp.action = "I"
            trndevapp.result = "N"  # N is N/A
            trndevapp.save()
            Device.objects.filter(id=dev_id.id).update(active="D")

    msg = "new_manifest"
    for dev_id in dev_ids:
        Device.objects.get(id=dev_id.id).send_message(payload=json({"message": msg}))

    eprofile = ExperimentProfile.objects.get(experiment=obj)
    eprofile.starttime = datetime.now()
    print obj.period
    endtime = datetime.now() + timedelta(int(obj.period))
    print endtime
    eprofile.endtime = endtime
    eprofile.save()
    queryset.update(active=1)
Exemple #3
0
def c2dm(request, deviceId):
    # define default response
    response = {"err": "", "data": ""}
    # return if GET request
    if request.method == 'GET':
        response['err'] = {'no': 'err0', 'msg': 'sorry no gets'}
    else:
        msg = request.POST['c2dm_msg']
        # get device
        try:
            dev = Device.objects.get(id=deviceId)
            # msg = "new_manifest"
            #TODO: Implement other messages.
            response = dev.send_message(payload=json({"message": msg}))
        except Device.DoesNotExist:
            response['err'] = {'no': 'err1', 'msg': 'invalid device'}
        return json_response_from(response)
Exemple #4
0
def c2dm(request, deviceId):
  # define default response
  response = { "err": "", "data": "" }
  # return if GET request
  if request.method == 'GET':
    response['err'] = {
      'no' : 'err0',
      'msg': 'sorry no gets'
    }
  else:	
    msg = request.POST['c2dm_msg']
    # get device
    try:
      dev = Device.objects.get(id=deviceId)
      # msg = "new_manifest"
      #TODO: Implement other messages.
      response = dev.send_message(payload=json({"message": msg}))
    except Device.DoesNotExist: 
      response['err'] = {
        'no' : 'err1',
        'msg': 'invalid device'
      }
    return json_response_from(response)		
Exemple #5
0
def create(request):
  # define default response
  response = { "err": "", "data": "" }
  # return if GET request
  if request.method == 'GET':
    response['err'] = {
      'no' : 'err0',
      'msg': 'sorry no gets'
    }
    return HttpResponseRedirect('/error/')
  # params checking
  if not (request.POST.has_key('dev') and request.POST.has_key('app') \
          and request.POST.has_key('action')):
    response['error'] = {
      'no' : 'err1',
      'msg': 'missing mandatory params'
    }
    return json_response_from(response)

  dev_ids = request.POST.getlist('dev')
  app_ids = request.POST.getlist('app')
  transact = Transaction()
  transact.user = User.objects.get(id=request.POST['user'])
  transact.total = len(dev_ids) * len(app_ids)
  transact.progress = 0
  #transact.end = null

  #Check Data Validation
  for dev_id in dev_ids:
    for app_id in app_ids:
      #check FailureAlready(F1)
      if DeviceApplication.objects.filter(dev=dev_id).filter(app=app_id):
        if request.POST['action'] == "I":
          response['err'] = {
            'no' : 'err1',
            'msg': 'The application is already installed'
          }
          return json_response_from(response)
      #check FailureNoSuchApplication(F2)
      else:
        if request.POST['action'] == "U":  
          response['err'] = {
            'no' : 'err1',
            'msg': 'The phone does not have the application to uninstall'
          }
          return json_response_from(response)
    
  #insert the data from POST method
  for dev_id in dev_ids:
    for app_id in app_ids:
      transact.save()
      t_id = transact.id
      trndevapp = TransactionDevApp()
      trndevapp.tid = Transaction.objects.get(id=t_id)
      trndevapp.dev = Device.objects.get(id=dev_id)
      trndevapp.app = Application.objects.get(id=app_id)
      trndevapp.action = request.POST['action']
      trndevapp.result = "N" # N is N/A
      trndevapp.save()
      Device.objects.filter(id=dev_id).update(active="D")
#      Application.objects.filter(id=app_id).update(active="D")
  #send "new_manifest" message to phones via C2DM
  msg = "new_manifest"
  for dev_id in dev_ids:
    Device.objects.get(id=dev_id).send_message(payload=json({"message": msg}))
  return HttpResponseRedirect('/transaction/' + str(t_id) + '/1/')
  
  return json_response_from(response)
Exemple #6
0
def create(request):
    # define default response
    response = {"err": "", "data": ""}
    # return if GET request
    if request.method == 'GET':
        response['err'] = {'no': 'err0', 'msg': 'sorry no gets'}
        return HttpResponseRedirect('/error/')
    # params checking
    if not (request.POST.has_key('dev') and request.POST.has_key('app') \
            and request.POST.has_key('action')):
        response['error'] = {'no': 'err1', 'msg': 'missing mandatory params'}
        return json_response_from(response)

    dev_ids = request.POST.getlist('dev')
    app_ids = request.POST.getlist('app')
    transact = Transaction()
    transact.user = User.objects.get(id=request.POST['user'])
    transact.total = len(dev_ids) * len(app_ids)
    transact.progress = 0
    #transact.end = null

    #Check Data Validation
    for dev_id in dev_ids:
        for app_id in app_ids:
            #check FailureAlready(F1)
            if DeviceApplication.objects.filter(dev=dev_id).filter(app=app_id):
                if request.POST['action'] == "I":
                    response['err'] = {
                        'no': 'err1',
                        'msg': 'The application is already installed'
                    }
                    return json_response_from(response)
            #check FailureNoSuchApplication(F2)
            else:
                if request.POST['action'] == "U":
                    response['err'] = {
                        'no':
                        'err1',
                        'msg':
                        'The phone does not have the application to uninstall'
                    }
                    return json_response_from(response)

    #insert the data from POST method
    for dev_id in dev_ids:
        for app_id in app_ids:
            transact.save()
            t_id = transact.id
            trndevapp = TransactionDevApp()
            trndevapp.tid = Transaction.objects.get(id=t_id)
            trndevapp.dev = Device.objects.get(id=dev_id)
            trndevapp.app = Application.objects.get(id=app_id)
            trndevapp.action = request.POST['action']
            trndevapp.result = "N"  # N is N/A
            trndevapp.save()
            Device.objects.filter(id=dev_id).update(active="D")


#      Application.objects.filter(id=app_id).update(active="D")
#send "new_manifest" message to phones via C2DM
    msg = "new_manifest"
    for dev_id in dev_ids:
        Device.objects.get(id=dev_id).send_message(
            payload=json({"message": msg}))
    return HttpResponseRedirect('/transaction/' + str(t_id) + '/1/')

    return json_response_from(response)