Exemple #1
0
def alerts(request):
    print 'inside alerts view method'
    context = RequestContext(request)

    device_list_side_nav = get_device_list_and_count(request)
    context.update(device_list_side_nav)

    if request.user.groups.filter(name__iexact='admin').exists():

        usr = UserFullName.objects.filter(username=request.user)[0]
        _registered_alerts = [
            ob.as_json() for ob in Alerts.objects.filter(
                building__in=request.user.userprofile.authorized_buildings())
        ]
        _alerts = [ob.as_json() for ob in AlertTypes.objects.all()]
        _alert_pr = [ob.as_json() for ob in PriorityLevels.objects.all()]
        _n_type = [ob.as_json() for ob in NotificationChannels.objects.all()]
        active_al = get_notifications()
        data = {
            'registered_alerts': _registered_alerts,
            'alerts': _alerts,
            'priority': _alert_pr,
            'n_type': _n_type,
            'user_full_name': usr,
            'active_al': active_al
        }
        data.update(get_device_list_and_count(request))
        return render(request, 'alerts/alarms.html', data)
    else:
        return HttpResponseRedirect('/home/')
Exemple #2
0
def application_individual(request, app_agent_id):
    user_building = request.user.userprofile.authorized_buildings()
    try:
        running_app = ApplicationRunning.objects.get(app_agent_id=app_agent_id)
        app_type = running_app.app_type
    except ApplicationRunning.DoesNotExist:
        print "Invalid application id"
        raise Http404
    if app_type.app_name == 'iblc':
        return_data = illuminance_based_control(user_building, app_agent_id)
        return_data.update(get_device_list_and_count(request))
        return render(request, 'applications/illuminance_light_control.html',
                      return_data)
    elif app_type.app_name == 'dr_test':
        return_data = demand_response_test(app_agent_id)
        return_data.update(get_device_list_and_count(request))
        return render(request, 'applications/demand_response_test.html',
                      return_data)
    elif app_type.app_name == 'fault_detection':
        return_data = fault_detection_info(app_agent_id)
        return_data.update(get_device_list_and_count(request))
        return render(request, 'applications/fault_detection.html',
                      return_data)
    elif app_type.app_name == 'thermostat_control':
        return_data = thermostat_control_info(user_building, app_agent_id)
        return_data.update(get_device_list_and_count(request))
        return render(request, 'applications/thermostat_control.html',
                      return_data)
    elif app_type.app_name in ['plugload_scheduler', 'lighting_scheduler']:
        app_data = running_app.app_data
        device_mac = app_data['device_agent_id'].split('_')[-1]
        return redirect('view-device-schedule', device_mac)
Exemple #3
0
def notifications(request):
    print "Notifications page load"
    context = RequestContext(request)

    device_list_side_nav = get_device_list_and_count(request)
    context.update(device_list_side_nav)

    if request.user.groups.filter(name__iexact='admin').exists():
        Notification.objects.filter(seen=False).update(seen=True)
        all_notifications = Notification.objects.all().order_by(
            '-dt_triggered')
        if len(
                all_notifications
        ) > 100:  #TODO limit of how many old notifications to save in Postgresql
            Notification.objects.filter(
                dt_triggered__lt=all_notifications[99].dt_triggered).delete()
        notifications = get_notifications(seen=True)

        usr = UserFullName.objects.filter(username=request.user)[0]
        data = {"notifications": notifications}
        data.update(get_device_list_and_count(request))
        # print context
        return render(request, 'alerts/notifications.html', data)
    else:
        return HttpResponseRedirect('/home/')
Exemple #4
0
def gateway_devices(request):
    context = RequestContext(request)
    buildings = request.user.userprofile.authorized_buildings()
    device_list_side_nav = get_device_list_and_count(request)
    context.update(device_list_side_nav)
    if request.user.groups.filter(name='Admin').exists():
        data = {"building_list": buildings}
        data.update(get_device_list_and_count(request))
        return render(request, 'dashboard/gateway_devices.html', data)

    else:
        return HttpResponseRedirect('/home/')
Exemple #5
0
def gateway_status(request):
    context = RequestContext(request)
    buildings = request.user.userprofile.authorized_buildings()
    device_list_side_nav = get_device_list_and_count(request)
    context.update(device_list_side_nav)
    if request.user.groups.filter(name='Admin').exists():
        gateways = IOTGateway.objects.filter(building__in=buildings)
        data = {"gateways": gateways}
        data.update(get_device_list_and_count(request))
        print gateways
        return render(request, 'dashboard/gateway_status.html', data)

    else:
        return HttpResponseRedirect('/home/')
Exemple #6
0
def lighting_schedule(request, mac):
    print 'Inside Set Schedule method in Schedule app'
    context = RequestContext(request)
    user_group = request.user.groups.all().values_list('name', flat=True)
    if 'Admin' in user_group or 'Zone Manager' in user_group:
        print type(mac)
        mac = mac.encode('ascii', 'ignore')
        print type(mac)

        device_metadata = [ob.device_control_page_info() for ob in DeviceMetadata.objects.filter(mac_address=mac)]
        print device_metadata
        device_id = device_metadata[0]['agent_id']
        device_model = device_metadata[0]['device_model']
        device_status = [ob.data_as_json() for ob in Devicedata.objects.filter(agent_id=device_id)]
        device_node = device_status[0]['node_id']
        device_nickname = device_status[0]['nickname']
        node_nickname = device_status[0]['node_nickname']

        device_list_side_nav = get_device_list_and_count(request)
        context.update(device_list_side_nav)
        _data = {}
        active_schedule = []
        disabled_range = __.DISABLED_VALUES_LIGHTING

        #Check if schedule file for this device exists
        try:
            sch_data = schedule_data.objects.get(agent_id=device_id)
            _json_data = sch_data.schedule
            if device_id in _json_data['lighting']:
                print 'device id present'
                _data = _json_data['lighting'][device_id]['schedulers']

                active_schedule = _json_data['lighting'][device_id]['active']
                active_schedule = [str(x) for x in active_schedule]
                disabled_range = get_disabled_date_ranges(_data, __.DISABLED_VALUES_LIGHTING)
                _data = json.dumps(_data)
                _data = json.loads(_data, object_hook=_decode_dict)
        except ObjectDoesNotExist:
            _json_data = {"lighting": {
            device_id: {
                "active": ['everyday', 'holiday'],
                "inactive": [],
                "schedulers": __.LIGHTING_DEFAULT_SCHEDULE
                }}}

            schedule_data(agent_id=device_id, schedule=_json_data).save()
            _data = _json_data['lighting'][device_id]['schedulers']

            active_schedule = ['everyday', 'holiday']
            disabled_range = get_disabled_date_ranges(_data, __.DISABLED_VALUES_LIGHTING)

        return_data = {'device_id': device_id, 'device_zone': device_node, 'zone_nickname': node_nickname, 'mac_address': mac,
         'device_nickname': device_nickname, 'schedule': _data,
         'disabled_ranges': disabled_range, 'active_schedule': active_schedule}

        return_data.update(device_list_side_nav)

        return render(request, 'schedule/lighting_schedule.html', return_data)
    else:
        return HttpResponseRedirect('/home/')
Exemple #7
0
def oauth_main_page(request):
    if request.method == 'GET':
        device_list_side_nav = get_device_list_and_count(request)
        return_data = device_list_side_nav
        token_info = oauthToken.objects.all()
        return_data.update({'tokens': token_info})
        return render(request, "oauth/takeme2oauth.html", return_data)
Exemple #8
0
def bemoss_home(request):
    req_context = RequestContext(request)
    username = request.user

    #template_loader = template_loader.get_template('dashboard/dashboard.html')
    return render(request, 'dashboard/dashboard.html',
                  get_device_list_and_count(request))
Exemple #9
0
def zone_device_listing(request, node_id, device_type):
    context = RequestContext(request)
    username = request.user
    dev_list = get_device_list_and_count(request)
    node_id = node_id.lower()
    device_type = device_type

    if node_id == 'all':
        request_node = 'ALL NODES'
    elif node_id in dev_list['node_names']:
        request_node = dev_list['node_names'][node_id]
    else:
        return HttpResponse('Bad node name')

    if device_type not in dev_list['device_list']['all']['all'].keys():
        return HttpResponse('No such device exists')

    data = {
        'request_node_id': node_id,
        'request_deviceType': device_type,
        'request_node': request_node
    }

    data.update(dev_list)
    return render(request, 'dashboard/devices.html', data)
Exemple #10
0
def discover_devices(request):
    if request.user.groups.filter(name__iexact = 'admin').exists():
        context = RequestContext(request)
        try:
            discovery_status = Miscellaneous.objects.get(key='auto_discovery')
            print discovery_status.value
        except Miscellaneous.DoesNotExist:
            discovery_status = {'value':'not_started'}

        hvac = SupportedDevices.objects.filter(device_type_id=1)
        lt_loads = SupportedDevices.objects.filter(device_type_id=2)
        plugloads = SupportedDevices.objects.filter(device_type_id=3)
        sensors = SupportedDevices.objects.filter(device_type_id=4)
        power_meters = SupportedDevices.objects.filter(device_type_id=5)
        DER=SupportedDevices.objects.filter(device_type_id=6)
        camera=SupportedDevices.objects.filter(device_type_id=7)
        print lt_loads
        print hvac
        print power_meters
        print plugloads
        print sensors
        print DER

        device_list_side_nav = get_device_list_and_count(request)
        return_data = dict()
        return_data.update(device_list_side_nav)
        devices = {'hvac': hvac, 'lt_loads':lt_loads, 'plugloads':plugloads, 'sensors':sensors, 'power_meters':power_meters, "DER": DER, "camera":camera}
        return_data.update(devices)
        return_data.update({'discovery_status':discovery_status})

        return render(request,'discovery/manual_discovery.html', return_data
                                  )
    else:
        return HttpResponseRedirect('/home/')
Exemple #11
0
def password_manager(request):
    context = RequestContext(request)
    PasswordManagerFormSet = modelformset_factory(PasswordsManager, PasswordManagerForm)
    user_building = request.user.userprofile.authorized_buildings()[0] #use the first building as assigned building. #TODO add a building dropdown in the UI to let the user chose the building
    if request.method == 'POST':
        formset = PasswordManagerFormSet(request.POST)
        for form in formset:
            if form.is_valid():
                if form.cleaned_data:
                        form.cleaned_data['password'] = encrypt_value(form.cleaned_data['password']).encode('utf8')
                        password_data = form.save(commit=False)
                        password_data.last_modified = datetime.now()
                        password_data.building = user_building
                        password_data.save()
        password_manager_data = [ob.data_passwords_manager() for ob in PasswordsManager.objects.filter(building__in=request.user.userprofile.authorized_buildings())]
        formset = PasswordManagerFormSet(queryset=PasswordsManager.objects.filter(building__in=request.user.userprofile.authorized_buildings()))
    else:
        password_manager_data = [ob.data_passwords_manager() for ob in PasswordsManager.objects.filter(building__in=request.user.userprofile.authorized_buildings())]
        formset = PasswordManagerFormSet(queryset=PasswordsManager.objects.filter(building__in=request.user.userprofile.authorized_buildings()))
        # Allows initial pre-existing data to be rendered into the form.
        # When saving, previously saved data need to be treated as old data and ignored.
        # formset = PasswordManagerFormSet(initial=[ob.data_passwords_manager() for ob in
        # PasswordsManager.objects.all()])
    if request.user.is_superuser or request.user.groups.filter(name__iexact = 'admin'):
        data =  {'formset': formset, 'pwd_data': password_manager_data}
        data.update(get_device_list_and_count(request))
        return render(request,'discovery/password_manager.html',data)
    else:
        return HttpResponseRedirect('/home/')
Exemple #12
0
def devicedata_view(request, mac):
    if request.method == 'GET':
        device_info = DeviceMetadata.objects.get(mac_address=mac)
        template = SupportedDevices.objects.filter(
            device_model=device_info.device_model).values(
                'html_template')[0]['html_template']
        context = RequestContext(request)
        username = request.session.get('user')
        agent_id = device_info.agent_id
        _data = _helper.get_page_load_data(agent_id)
        device_list_side_nav = get_device_list_and_count(request)
        if device_info.vendor_name == "foscam":
            all_addresses = device_info.address
            local = all_addresses.split(",")[0]
            if local == all_addresses:
                remote = local
            else:
                remote = all_addresses.split(",")[1]

            device_info.local = local
            device_info.remote = remote
            device_info.comment = decrypt_value(device_info.password)

        weather_info = get_weather_info()
        return_data = {
            'device_info': device_info,
            'device_data': _data,
            'weather_info': weather_info
        }
        return_data.update(device_list_side_nav)
        context.update({'return_data': return_data})

        return render(request, template, return_data)
Exemple #13
0
def zone_device_listing(request, building_id, device_type):
    context = RequestContext(request)
    username = request.user
    dev_list = get_device_list_and_count(request)
    building_id = building_id.lower()
    device_type = device_type

    try:
        if building_id == 'all':
            request_building = 'ALL BUILDINGS'
        elif int(building_id) in dev_list['building_names']:
            request_building = dev_list['building_names'][int(building_id)]
        else:
            return HttpResponse('Bad building name')
    except TypeError:  #because building_id is not integer or 'all'
        return HttpResponse('Bad building name')

    if device_type not in dev_list['device_list']['all']['all'].keys():
        return HttpResponse('No such device exists')

    data = {
        'request_building_id': int(building_id),
        'request_deviceType': device_type,
        'request_building': request_building
    }

    data.update(dev_list)
    return render(request, 'dashboard/devices.html', data)
Exemple #14
0
def network_status(request):
    print 'Network status page load'
    context = RequestContext(request)

    if request.user.groups.all()[0].name.lower() == 'admin':
        return render(request, 'dashboard/network_status.html', get_device_list_and_count(request))
    else:
        return HttpResponseRedirect('/home/')
Exemple #15
0
def token_delete(request, sp, building_id):
    # TODO: Change the HTML file of this function, current model exist critical vulnerability
    token = oauthToken.objects.filter(service_provider=sp,
                                      building_id=building_id)
    token.delete()
    device_list_side_nav = get_device_list_and_count(request)
    return_data = device_list_side_nav
    return redirect('/oauth')
Exemple #16
0
def returnChartsPage(request, context,mac,data_variables,page,get_weather=False):
    '''
    :param context: var obtained from RequestContext(request)
    :param mac: Device mac ID (table id)
    :param data_variables: Dict. Variables in the database that is to be retrieved as value, and varaibles in html as keys
    :param page: The html page to be returned to
    :param device_type: The device type class
    :return: the rendered html page
    '''
    agent_id = get_agent_id_from_mac(mac)
    try:
        if not get_weather:
            varlist, rs = retrieve(agent_id)
        else:
            data = retrieve(agent_id, weather_agent=settings.weather_agent)
            if data is not None:
                varlist, rs=data
            else:
                varlist, rs = retrieve(agent_id)
    except Exception as er:
        print er
        print 'Cassandra data reading error'
        return {}

    device_list_side_nav = get_device_list_and_count(request)

    data_dict = {}
    objects = [ob for ob in DeviceMetadata.objects.filter(mac_address=mac)]
    try:
        device_nickname = objects[0].nickname
        node_name = objects[0].node.node_name
        data_dict = {'mac': mac, 'nickname': device_nickname, 'node_name': node_name}
    except Exception as er:
        print er
        print 'get device status failed'

    for key,val in data_variables.items():
        try:
            data_dict[key] = parse_resultset(varlist,val,rs)
        except (KeyError, ValueError) as er:
            print er
            continue

    context.update(get_device_list_and_count(request))
    data_dict.update(device_list_side_nav)
    return render(request, page,data_dict)
Exemple #17
0
def device_status(request):
    print 'Device status page load'
    context = RequestContext(request)

    if request.user.groups.filter(name__iexact = 'admin').exists():
        return render(request, 'dashboard/device_status.html', get_device_list_and_count(request))
    else:
        return HttpResponseRedirect('/home/')
Exemple #18
0
def buildinginfos_display(request):
    print 'Device status page load'
    context = RequestContext(request)

    if request.user.groups.filter(name__iexact='admin').exists():
        return render(request, 'buildinginfos/building_info.html',
                      get_device_list_and_count(request))
    else:
        return HttpResponseRedirect('/home/')
Exemple #19
0
def node_status(request):
    context = RequestContext(request)

    if True or request.user.get_profile().group.name.lower() == 'admin':

        return render(request, 'dashboard/node_discovery.html',
                      get_device_list_and_count(request))
    else:
        return HttpResponseRedirect('/home/')
Exemple #20
0
def application_individual(request, app_agent_id):
    try:
        running_app = ApplicationRunning.objects.get(app_agent_id=app_agent_id)
        app_type = running_app.app_type
    except ApplicationRunning.DoesNotExist:
        print "Invalid application id"
        raise Http404
    if app_type.app_name == 'iblc':
        return_data = illuminance_based_control(app_agent_id)
        return_data.update(get_device_list_and_count(request))
        return render(request, 'applications/illuminance_light_control.html', return_data)
    elif app_type.app_name == 'fault_detection':
        return_data = fault_detection_info(app_agent_id)
        return_data.update(get_device_list_and_count(request))
        return render(request, 'applications/fault_detection.html', return_data)
    elif app_type.app_name in ['plugload_scheduler','lighting_scheduler']:
        app_data = running_app.app_data
        device_mac = app_data['device_agent_id'].split('_')[-1]
        return redirect('view-device-schedule',device_mac)
Exemple #21
0
def application_main(request):
    # Display the main page of bemoss applications
    user_building = request.user.userprofile.authorized_buildings()
    apps = ApplicationRunning.objects.filter(building__in=user_building)
    return_data = {
        'apps': apps,
        'fault_detection_preinfo': fault_detection_preinfo(user_building),
        'thermostat_control_preinfo': thermostat_control_preinfo(user_building)
    }
    return_data.update(get_device_list_and_count(request))
    return render(request, 'applications/applications.html', return_data)
Exemple #22
0
def discover(request):
    print "Discovering devices"

    if True or request.user.get_profile().group.name.lower() == 'admin':
        req_context = RequestContext(request)
        username = request.user

        # template_loader = template_loader.get_template('dashboard/dashboard.html')
        return render(request, 'dashboard/discovery.html', get_device_list_and_count(request))

    else:
        return HttpResponseRedirect('/home/')
Exemple #23
0
def user_manager(request):
    context = RequestContext(request)
    zones = Building_Zone.objects.all()
    device_list_side_nav = get_device_list_and_count(request)
    context.update(device_list_side_nav)

    if request.user.groups.filter(name='Admin').exists():
        _users = User.objects.all()
        groups = Group.objects.all()
        userprofiles = UserProfile.objects.all()
        data = {
            "users": _users,
            'zones': zones,
            'groups': groups,
            'userprofiles': userprofiles
        }
        data.update(get_device_list_and_count(request))
        print _users
        return render(request, 'accounts/user_manager.html', data)

    else:
        return HttpResponseRedirect('/home/')
Exemple #24
0
def devicedata_view(request, mac):
    if request.method == 'GET':

        try:
            device_info = DeviceMetadata.objects.get(mac_address=mac)
        except DeviceMetadata.DoesNotExist:
            return HttpResponse('Invalid Devices', status=404)
        if device_info.building not in request.user.userprofile.authorized_buildings(
        ):
            return HttpResponse('Unauthorized', status=401)

        template = SupportedDevices.objects.filter(
            device_model=device_info.device_model).values(
                'html_template')[0]['html_template']
        context = RequestContext(request)
        username = request.session.get('user')
        agent_id = device_info.agent_id
        #Request a device monitor
        vip_publish(sender="ui",
                    target='basicagent',
                    topic='onDemandMonitor',
                    message={'agent_id': agent_id})

        _data = _helper.get_page_load_data(agent_id)
        device_list_side_nav = get_device_list_and_count(request)
        if device_info.vendor_name == "Foscam":
            all_addresses = device_info.address
            local = 'http://' + all_addresses.split(",")[0]
            if local == all_addresses:
                remote = local
            else:
                remote = 'http://' + all_addresses.split(",")[1]

            device_info.local = local
            device_info.remote = remote
            device_info.comment = decrypt_value(
                device_info.config.get("password"))
        zip_code = device_info.building.zip_code
        weather_info = get_weather_info(zip_code)
        device_info.username = device_info.config.get(
            "username")  #put username and password directly into deviceinfo
        device_info.password = device_info.config.get("password")
        return_data = {
            'device_info': device_info,
            'device_data': _data,
            'weather_info': weather_info
        }
        return_data.update(device_list_side_nav)
        context.update({'return_data': return_data})
        return render(request, template, return_data)
Exemple #25
0
def application_main(request):
    # Display the main page of bemoss applications

    hvac_fault_apps = ApplicationRunning.objects.filter(app_type__app_name='fault_detection')
    used_thermostat_ids = []
    for app in hvac_fault_apps:
        used_thermostat_ids.append(app.app_data['thermostat'])

    available_thermostas = DeviceMetadata.objects.filter(approval_status='APR', device_type_id=1).exclude(agent_id__in=used_thermostat_ids)

    apps = ApplicationRunning.objects.all()
    return_data = {'apps': apps, 'available_thermostats':available_thermostas}
    return_data.update(get_device_list_and_count(request))
    return render(request, 'applications/applications.html', return_data)
Exemple #26
0
def devicedata_view(request, mac):
    if request.method == 'GET':
        device_info = DeviceMetadata.objects.get(mac_address=mac)
        template = SupportedDevices.objects.filter(device_model=device_info.device_model).values('html_template')[0]['html_template']
        context = RequestContext(request)
        username = request.session.get('user')
        agent_id = device_info.agent_id
        _data = _helper.get_page_load_data(agent_id)
        device_list_side_nav = get_device_list_and_count(request)

        weather_info = get_weather_info()
        return_data = {'device_info': device_info, 'device_data': _data, 'weather_info':weather_info}
        return_data.update(device_list_side_nav)
        context.update({'return_data': return_data})

        return render(request, template, return_data)
Exemple #27
0
def bemoss_settings(request):
    print 'BEMOSS Settings page load'
    context = RequestContext(request)

    holidays = [ob.as_json() for ob in Holiday.objects.all()]
    print holidays

    zip = Miscellaneous.objects.get(key='zipcode')
    b_location = zip.value

    device_list_side_nav = get_device_list_and_count(request)

    data = {'holidays': holidays, 'b_location': b_location}

    data.update(device_list_side_nav)

    if request.user.groups.filter(name__iexact='admin').exists():
        return render(request,'dashboard/bemoss_settings.html',data)
    else:
        return HttpResponseRedirect('/home/')
Exemple #28
0
def showSchedule(request,device_id):
    # return HttpResponse('No schedule yet for: ' + str(device_id) )

    user_group = request.user.groups.all().values_list('name', flat=True)
    if not ('Admin' in user_group or 'Zone Manager' in user_group):
        return HttpResponse("Need to be Admin or Zone-manager", status=401)

    mac = device_id.encode('ascii', 'ignore')
    device_info = DeviceMetadata.objects.get(mac_address=device_id)
    schedule_data, schedule_meta = get_schedule_data(device_id)
    device_list_side_nav = get_device_list_and_count(request, user=request.user)
    device_metadata = [ob.device_control_page_info() for ob in DeviceMetadata.objects.filter(mac_address=mac)]
    # print device_metadata
    device_id = device_metadata[0]['agent_id']
    device_model = device_metadata[0]['device_model']

    device_status = [ob.as_json() for ob in Devicedata.objects.filter(agent_id=device_id)]
    device_node = device_status[0]['node_id']
    device_nickname = device_status[0]['nickname']
    node_nickname = device_status[0]['node_nickname']

    disabled_range = get_disabled_date_ranges(schedule_data['schedulers'])
    schedule_json = json.dumps(schedule_data['schedulers'],encoding='ascii')
    schedule = schedule_data['schedulers']
    return_data = {'device_id': device_id, 'device_zone': device_node, 'zone_nickname': node_nickname,
                   'mac_address': mac,
                   'device_nickname': device_nickname, 'schedule': schedule,
                   'schedule_json': json.dumps(schedule),
                   'disabled_ranges': json.dumps(disabled_range), 'active_schedule': str(schedule_data['active']),
                   'schedule_meta': schedule_meta}
    return_data.update(device_list_side_nav)
    if device_info.device_type.device_type == 'HVAC':
        return render(request, 'schedule/thermostat_schedule.html', return_data)
    elif device_info.device_type.device_type == 'Lighting':
        return render(request, 'schedule/lighting_schedule.html', return_data)
    elif device_info.device_type.device_type == 'Plugload':
        return render(request, 'schedule/plugload_schedule.html', return_data)
Exemple #29
0
def returnChartsPage(request,
                     context,
                     mac,
                     data_variables,
                     page,
                     get_weather=False):
    '''
    :param context: var obtained from RequestContext(request)
    :param mac: Device mac ID (table id)
    :param data_variables: Dict. Variables in the database that is to be retrieved as value, and varaibles in html as keys
    :param page: The html page to be returned to
    :param device_type: The device type class
    :return: the rendered html page
    '''
    agent_id = get_agent_id_from_mac(mac)
    device = DeviceMetadata.objects.get(agent_id=agent_id)
    weather_agent = 'BEMO_WUG' + device.building.zip_code + '_' + str(
        device.building.building_id)
    weather_table = "B" + str(device.building.building_id) + "_bemossweather"

    tablename = getTableName(device.building.building_id, device.device_model)

    try:
        if not get_weather:
            varlist, rs = retrieve(agent_id, tablename=tablename)
        else:
            data = retrieve(agent_id,
                            weather_agent=weather_agent,
                            tablename=tablename,
                            weather_table=weather_table)
            if data is not None:
                varlist, rs = data
            else:
                varlist, rs = retrieve(agent_id, tablename=tablename)
    except Exception as er:
        print er
        print 'Cassandra data reading error'
        return HttpResponse("Database fail", status=404)

    device_list_side_nav = get_device_list_and_count(request)

    data_dict = {}
    objects = [ob for ob in DeviceMetadata.objects.filter(mac_address=mac)]
    try:
        device_nickname = objects[0].nickname
        node_name = objects[0].node.node_name
        data_dict = {
            'mac': mac,
            'nickname': device_nickname,
            'node_name': node_name
        }
    except Exception as er:
        print er
        print 'get device status failed'

    for key, val in data_variables.items():
        try:
            data_dict[key] = parse_resultset(varlist, val, rs)
        except (KeyError, ValueError) as er:
            print er
            continue

    context.update(get_device_list_and_count(request))
    data_dict.update(device_list_side_nav)
    return render(request, page, data_dict)