Beispiel #1
0
def create_or_update_device(request):
    # define default response
    response = {"error": "", "data": ""}
    # return if GET request
    if request.method == 'GET':
        response['error'] = {'no': 'err0', 'msg': 'sorry no gets'}
        return json_response_from(response)
    # get params from POST
    params = request.POST
    # error checking
    if (params['device_id'] == "" or params['reg_id'] == ""
            or params['phone_no'] == ""):
        response['error'] = {'no': 'err1', 'msg': 'missing mandatory params'}

    # get device
    device = Device.objects.filter(meid=params['device_id'])
    # if device exists, update
    if device.count() == 1:
        device = device[0]
        # email
        #if ('email' in params and device.email != params['email']):
        #  device.email = params['email']
        # reg_id
        if ('reg_id' in params and device.reg_id != params['reg_id']):
            device.reg_id = params['reg_id']
        # update
        if ('update_interval' in params
                and device.update_interval != params['update_interval']):
            device.update_interval = params['update_interval']
        device.save()
    # device does not exist, insert
    else:
        device = Device(
            meid=params['device_id'],
            #    email  = "*****@*****.**", #params['email']
            reg_id=params['reg_id'],
            active="E")
        device.save()

        # create monitor interval in StatusMonitor class
        # statusmonitor = StatusMonitor(
        #                   name = 'monitorInterval',
        #                   value = '10',
        #                   units = 'min')
        # statusmonitor.save()
        deviceprofile = DeviceProfile()
        #deviceprofile.statusmonitor.add(statusmonitor)

        deviceprofile.dev = device
        if params['device_id'].startswith('A0000', 0, 5):
            deviceprofile.phone_no = params['phone_no']
        deviceprofile.save()

        # device
        response['data'] = device
    # render json response
    return json_response_from(response)
Beispiel #2
0
def create_or_update_device(request): 
  # define default response
  response = { "error": "", "data": "" }
  # return if GET request
  if request.method == 'GET':
    response['error'] = {
      'no' : 'err0',
      'msg': 'sorry no gets'
    }
    return json_response_from(response)
  # get params from POST
  params = request.POST
  # error checking
  if (params['device_id'] == "" or params['reg_id'] == "" or params['phone_no'] == ""):
    response['error'] = {
      'no' : 'err1',
      'msg': 'missing mandatory params'
    }
  
  # get device
  device = Device.objects.filter(meid=params['device_id'])
  # if device exists, update
  if device.count() == 1:
    device = device[0]
    # email
    #if ('email' in params and device.email != params['email']):
    #  device.email = params['email']
    # reg_id
    if ('reg_id' in params and device.reg_id != params['reg_id']):
      device.reg_id = params['reg_id']
    # update
    if ('update_interval' in params and device.update_interval != params['update_interval']):
      device.update_interval = params['update_interval']
    device.save()
  # device does not exist, insert
  else:
    device = Device(
        meid     = params['device_id'], 
    #    email  = "*****@*****.**", #params['email'] 
        reg_id = params['reg_id'],
        active = "E"
    )
    device.save()

    # create monitor interval in StatusMonitor class
    # statusmonitor = StatusMonitor(
    #                   name = 'monitorInterval',
    #                   value = '10',
    #                   units = 'min')
    # statusmonitor.save()
    deviceprofile = DeviceProfile()    
    #deviceprofile.statusmonitor.add(statusmonitor)

    deviceprofile.dev = device
    if params['device_id'].startswith('A0000', 0, 5):
      deviceprofile.phone_no = params['phone_no']
    deviceprofile.save()
    
    # device
    response['data'] = device
  # render json response
  return json_response_from(response)
Beispiel #3
0
def confirm_participant_register(request):
  # params checking
  if (request.POST['ub_id'] == '' and request.POST['email'] == '' \
         and request.POST['first_name'] =='' and request.POST['last_name'] ==''):
    participantregister = ParticipantRegister(
                         lib_number = request.POST['lib_number'],
                         meid       = request.POST['meid']
                         )
    print request.POST['lib_number']+" -- "+request.POST['meid']
    participantregister.save()
    return render_to_response(
    	'participant_register_form.html',
      {
      'success': True,
      },
      context_instance=RequestContext(request)
      )
  else:
    password = User.objects.make_random_password(length=10, allowed_chars='abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789')
    user = User.objects.create_user(request.POST['ub_id'], request.POST['email'], password)
    user.is_active = False
    user.first_name = request.POST['first_name']
    user.last_name = request.POST['last_name']
    user.save() 
	
    # Build the activation key for their account                                                                                                                    
    salt = hashlib.md5(str(random.random())).hexdigest()[:5]
    activation_key = hashlib.md5(salt+user.username).hexdigest()
    key_expires = datetime.today() + timedelta(2)
    userprofile = UserProfile(
                user = user,
                user_type = "P",
                activation_key=activation_key, 
                key_expires=key_expires
                )
    # Create and save their profile                                                                                                                                 
    userprofile.save()

    device = Device(
           meid = request.POST['meid'],
           hash_meid = hashlib.sha1(request.POST['meid']).hexdigest(),
           active = "E"
           )
    device_id = device.save()
    device.save()
  
    # create monitor interval in StatusMonitor class
    statusmonitor = StatusMonitor(
                  name = 'monitorInterval',
                  value = '10',
                  units = 'min')
    statusmonitor.save()
  
    # Create and save device profile
    deviceprofile = DeviceProfile()
    deviceprofile.dev = device
    deviceprofile.user = user
    deviceprofile.phone_no = request.POST['phone_number']
    deviceprofile.status = "W"
    #deviceprofile.purpose = ""
    if request.POST['meid'].startswith('A0000', 0, 5):
       deviceprofile.service_type = "4"
    else:
       deviceprofile.service_type = "3"
    deviceprofile.save()
    deviceprofile.statusmonitor.add(statusmonitor)
    deviceprofile.save()
    return render_to_response(
    	'participant_register_form.html',
      {
      'success': True,
      },
      context_instance=RequestContext(request)
      )