Exemplo n.º 1
0
def loadAccessControl(request):
    values = {}
    if request.method == "POST":
	data = json.loads(request.raw_post_data)
	datastore_owner = data.get(u'datastore_owner')
	app_id = data.get(u'app_id')
	lab_id = data.get(u'lab_id')

	profile = Profile.objects.get(uuid = datastore_owner)

	probes = {'activity_probe': False, 'sms_probe': False, 'call_log_probe': False, 
            	  'bluetooth_probe': False, 'wifi_probe': False, 'simple_location_probe': False,
                  'screen_probe': False, 'running_applications_probe': False, 
		  'hardware_info_probe': False, 'app_usage_probe': False}

	for probe_object in Settings.objects.all():
	    probes['activity_probe'] = probes['activity_probe'] or probe_object.activity_probe
	    probes['sms_probe'] = probes['sms_probe'] or probe_object.sms_probe
	    probes['call_log_probe'] = probes['call_log_probe'] or probe_object.call_log_probe
	    probes['bluetooth_probe'] = probes['bluetooth_probe'] or probe_object.bluetooth_probe
	    probes['wifi_probe'] = probes['wifi_probe'] or probe_object.wifi_probe
	    probes['simple_location_probe'] = probes['simple_location_probe'] or probe_object.simple_location_probe
	    probes['screen_probe'] = probes['screen_probe'] or probe_object.screen_probe
	    probes['running_applications_probe'] = probes['running_applications_probe'] or probe_object.running_applications_probe
	    probes['hardware_info_probe'] = probes['hardware_info_probe'] or probe_object.hardware_info_probe
	    probes['app_usage_probe'] = probes['app_usage_probe'] or probe_object.app_usage_probe
	
	settings = []
	try:
	    setting_object = Settings.objects.get(datastore_owner = profile, app_id = app_id, lab_id = lab_id)
	except Settings.DoesNotExist:
	    setting_object = None

	if setting_object is not None:
            setting = {}

	    setting['activity_probe'] = setting_object.activity_probe
	    setting['sms_probe'] = setting_object.sms_probe
            setting['call_log_probe'] = setting_object.call_log_probe
	    setting['bluetooth_probe'] = setting_object.bluetooth_probe
	    setting['wifi_probe'] = setting_object.wifi_probe
	    setting['simple_location_probe'] = setting_object.simple_location_probe
	    setting['screen_probe'] = setting_object.screen_probe
	    setting['running_applications_probe'] = setting_object.running_applications_probe
	    setting['hardware_info_probe'] = setting_object.hardware_info_probe
	    setting['app_usage_probe'] = setting_object.app_usage_probe
	    setting['context_label_id'] = setting_object.context_label_id
            settings.append(setting)

	context_objects = []
	contexts = []
        context_objects = list(Context.objects.all().filter(datastore_owner = profile))

	if len(context_objects) == 0:
	    context = Context.objects.create(datastore_owner = profile, context_label = 'MIT')
            context.context_duration_start = '10 : 0'
            context.context_duration_end = '18 : 0'
            context.context_duration_days = '[0, 1, 1, 1, 1, 1, 0]'
	    context.context_places = '[lat/lng: (42.3591326,-71.093201)]'
            context.save()
	    context_objects.append(context)

            context = Context.objects.create(datastore_owner = profile, context_label = 'Alltime-Everywhere')
            context.context_duration_start = '0 : 0'
            context.context_duration_end = '23 : 59'
            context.context_duration_days = '[1, 1, 1, 1, 1, 1, 1]'
            context.context_places = ''
            context.save()
            context_objects.append(context)

	for context_object in context_objects:
	    context = {}
	    context['id'] = context_object.id
	    context['context_label'] = context_object.context_label
	    context['context_duration_start'] = context_object.context_duration_start
	    context['context_duration_end'] = context_object.context_duration_end
	    context['context_duration_days'] = context_object.context_duration_days
	    context['context_places'] = context_object.context_places
	    contexts.append(context)

	data_aggregation = False
        try:
            optin_object = Optin.objects.get(datastore_owner = profile, app_id = app_id, lab_id = lab_id)
        except Optin.DoesNotExist:
            optin_object = None
	
	if optin_object:
	    data_aggregation = optin_object.data_aggregation

	return HttpResponse(json.dumps({
        "settings": settings, 
        "contexts": contexts,
	"probes": probes,
	"data_aggregation": data_aggregation}),
    content_type="application/json")
Exemplo n.º 2
0
def loadAccessControl(request):
    values = {}
    if request.method == "POST":
        data = json.loads(request.raw_post_data)
        datastore_owner = data.get(u'datastore_owner')
        app_id = data.get(u'app_id')
        lab_id = data.get(u'lab_id')

        print(data)
        profile = Profile.objects.get(uuid=datastore_owner)

        settings = []
        try:
            setting_object = Settings.objects.get(datastore_owner=profile,
                                                  app_id=app_id,
                                                  lab_id=lab_id)
        except Settings.DoesNotExist:
            setting_object = None

        if setting_object is not None:
            setting = {}

            setting['activity_probe'] = setting_object.activity_probe
            setting['sms_probe'] = setting_object.sms_probe
            setting['call_log_probe'] = setting_object.call_log_probe
            setting['bluetooth_probe'] = setting_object.bluetooth_probe
            setting['wifi_probe'] = setting_object.wifi_probe
            setting[
                'simple_location_probe'] = setting_object.simple_location_probe
            setting['screen_probe'] = setting_object.screen_probe
            setting[
                'running_applications_probe'] = setting_object.running_applications_probe
            setting['hardware_info_probe'] = setting_object.hardware_info_probe
            setting['app_usage_probe'] = setting_object.app_usage_probe
            setting['context_label_id'] = setting_object.context_label_id
            settings.append(setting)

        context_objects = []
        contexts = []
        context_objects = list(
            Context.objects.all().filter(datastore_owner=profile))

        if len(context_objects) == 0:
            context = Context.objects.create(datastore_owner=profile,
                                             context_label='MIT')
            context.context_duration_start = '10 : 0'
            context.context_duration_end = '18 : 0'
            context.context_duration_days = '[0, 1, 1, 1, 1, 1, 0]'
            context.context_places = ''
            context.save()
            context_objects.append(context)

        print context_objects
        for context_object in context_objects:
            context = {}
            context['id'] = context_object.id
            print(context_object.id)
            context['context_label'] = context_object.context_label
            context[
                'context_duration_start'] = context_object.context_duration_start
            context[
                'context_duration_end'] = context_object.context_duration_end
            context[
                'context_duration_days'] = context_object.context_duration_days
            context['context_places'] = context_object.context_places
            contexts.append(context)

        return HttpResponse(json.dumps({
            "settings": settings,
            "contexts": contexts
        }),
                            content_type="application/json")
Exemplo n.º 3
0
def loadAccessControl(request):
    values = {}
    if request.method == "POST":
	data = json.loads(request.raw_post_data)
	datastore_owner = data.get(u'datastore_owner')
	app_id = data.get(u'app_id')
	lab_id = data.get(u'lab_id')

	print(data)
	profile = Profile.objects.get(uuid = datastore_owner)

	settings = []
	try:
	    setting_object = Settings.objects.get(datastore_owner = profile, app_id = app_id, lab_id = lab_id)
	except Settings.DoesNotExist:
	    setting_object = None

	if setting_object is not None:
            setting = {}

	    setting['activity_probe'] = setting_object.activity_probe
	    setting['sms_probe'] = setting_object.sms_probe
            setting['call_log_probe'] = setting_object.call_log_probe
	    setting['bluetooth_probe'] = setting_object.bluetooth_probe
	    setting['wifi_probe'] = setting_object.wifi_probe
	    setting['simple_location_probe'] = setting_object.simple_location_probe
	    setting['screen_probe'] = setting_object.screen_probe
	    setting['running_applications_probe'] = setting_object.running_applications_probe
	    setting['hardware_info_probe'] = setting_object.hardware_info_probe
	    setting['app_usage_probe'] = setting_object.app_usage_probe
	    setting['context_label_id'] = setting_object.context_label_id
            settings.append(setting)

	context_objects = []
	contexts = []
        context_objects = list(Context.objects.all().filter(datastore_owner = profile))

	if len(context_objects) == 0:
	    context = Context.objects.create(datastore_owner = profile, context_label = 'MIT')
            context.context_duration_start = '10 : 0'
            context.context_duration_end = '18 : 0'
            context.context_duration_days = '[0, 1, 1, 1, 1, 1, 0]'
	    context.context_places = ''
            context.save()
	    context_objects.append(context)

	print context_objects
	for context_object in context_objects:
	    context = {}
	    context['id'] = context_object.id
	    print(context_object.id)
	    context['context_label'] = context_object.context_label
	    context['context_duration_start'] = context_object.context_duration_start
	    context['context_duration_end'] = context_object.context_duration_end
	    context['context_duration_days'] = context_object.context_duration_days
	    context['context_places'] = context_object.context_places
	    contexts.append(context)

	return HttpResponse(json.dumps({
        "settings": settings, 
        "contexts": contexts}),
    content_type="application/json")