def index(request): if request.method == 'GET': try: lsArea = Area.objects.filter(level = '2') lsProperty = DeviceProperties.objects.all() context={'lsArea':lsArea,'lsProperty':lsProperty} context.update(csrf(request)) except Exception as ex: context={} print(ex) finally: return render_to_response("add-device.html", context,RequestContext(request)) elif request.method == 'POST': formType= request.POST['type'] if formType == "addDevice": context={} try: _code = request.POST['txtCode'].strip() _name = request.POST['txtName'].strip() _mac = request.POST['txtMAC'].strip() _area_id = request.POST['slArea'].strip() _address = request.POST['txtAddress'].strip() _fullName = request.POST['txtFullName'].strip() _lat = request.POST['txtLat'].strip() _lng = request.POST['txtLng'].strip() area = Area.objects.get(id = _area_id) # device = Device() device.name = _name device.address = _fullName device.short_address = _address device.mac_add = _mac device.area = area device.code = _code device.lat = float(_lat) device.lng = float(_lng) device.save() lsDeviceProperties = DeviceProperties.objects.all() for deviceProperties in lsDeviceProperties: temp = deviceProperties deviceInfor = DeviceInfor() deviceInfor.device = device deviceInfor.value = float('0') if request.POST.get(str(temp.code)): deviceInfor.status = '1' else : deviceInfor.status = '0' deviceInfor.device_pro = temp deviceInfor.save() return HttpResponseRedirect('/device-list') except Exception as ex: print(ex)
def index(request): if request.method == 'GET': lsDeviceProperty = DeviceProperties.objects.all() context = {'lsDeviceProperty': lsDeviceProperty} context.update(csrf(request)) return render_to_response("device-property.html", context, RequestContext(request)) elif request.method == 'POST': formType = request.POST['type'] if formType == 'addDeviceProperty': _code = request.POST['txtCode'] _name = request.POST['txtName'] _type = request.POST['slType'] _description = request.POST['txtDescription'] _min = float(request.POST['txtMin']) _max = float(request.POST['txtMax']) _minAlarm = float(request.POST['txtMinAlarm']) _maxAlarm = float(request.POST['txtMaxAlarm']) _symbol = request.POST['txtSymbol'] dp = DeviceProperties() dp.code = _code dp.name = _name dp.type = _type dp.description = _description dp.min = _min dp.max = _max dp.min_alarm = _minAlarm dp.max_alarm = _maxAlarm dp.symbol = _symbol if request.POST.get('cbRequire'): dp.require = '1' else: dp.require = '0' dp.save() lsDevice = Device.objects.all() for device in lsDevice: deviceInfo = DeviceInfor() deviceInfo.device = device deviceInfo.device_pro = dp deviceInfo.status = '0' deviceInfo.value = float('0') deviceInfo.save() return HttpResponseRedirect('/device-property') elif formType == 'editDeviceProperty': print('edit') return HttpResponseRedirect('/device-property')
def add_railway(request): context = {} if request.method == "GET": lsArea = Area.objects.filter(level="2") lsProperty = DeviceProperties.objects.filter(p_type="2") lsSensorDirection = DeviceProperties.objects.filter(p_type="2", m_type="3") lsDeviceType = DeviceType.objects.all() lsRailwayDirection = ApParam.objects.filter(type="RAILWAY_DIRECTION") departments = Group.objects.all() routes = Route.objects.all() users = User.objects.all().order_by("username") context = { "lsSensorDirection": lsSensorDirection, "lsArea": lsArea, "lsProperty": lsProperty, "lsRailwayDirection": lsRailwayDirection, "lsDeviceType": lsDeviceType, "departments": departments, "users": users, "routes": routes, } context.update(csrf(request)) elif request.method == "POST": try: _code = request.POST["txtCode"].strip() _name = request.POST["txtJourney"].strip() _route = request.POST["slRoute"].strip() _ManagementUnit = request.POST["slManagementUnit"].strip() _UserUnit = request.POST["slUserUnit"].strip() _manager = request.POST["txtManager"].strip() _phoneNumber = request.POST["txtPhoneNumber"].strip() _note = request.POST["txtNote"].strip() _mac = request.POST["txtMAC"].strip() _area_id = request.POST["slArea"].strip() _address = request.POST["txtAddress"].strip() _fullName = request.POST["txtFullName"].strip() _lat = request.POST["txtLat"].strip() _lng = request.POST["txtLng"].strip() _deviceType = request.POST["slDeviceType"].strip() device_type = DeviceType.objects.get(id=_deviceType) area = Area.objects.get(id=_area_id) group = Group.objects.get(id=_ManagementUnit) user = User.objects.get(id=_UserUnit) route = Route.objects.get(id=_route) device = Device() device.name = _name device.address = _fullName device.short_address = _address device.mac_add = _mac device.area = area device.code = _code device.lat = float(_lat) device.lng = float(_lng) device.description = _note device.owner_name = _manager device.owner_phone = _phoneNumber device.group = group device.user = user device.route = route device.type = "4" _order = Device.objects.filter(route=route).aggregate(Max("order"))["order__max"] device.order = _order + 1 device.device_type = device_type if _deviceType == "3": _railwayDirection = request.POST["slRailwayDirection"].strip() _sensorDirection = request.POST["slSensorDirection"].strip() sensorDirection = DeviceProperties.objects.get(id=_sensorDirection) device.railway_direction = _railwayDirection device.sensor_direction = sensorDirection device.sensor_direction_code = sensorDirection.code device.save() lsDeviceProperties = DeviceProperties.objects.filter(p_type="2") for deviceProperties in lsDeviceProperties: temp = deviceProperties deviceInfor = DeviceInfor() deviceInfor.device = device deviceInfor.value = float("0") if request.POST.get(str(temp.code)): deviceInfor.status = "1" else: deviceInfor.status = "0" deviceInfor.device_pro = temp deviceInfor.save() return HttpResponseRedirect("/railway/list/") except Exception as ex: print(ex) context.update({"has_error": str(ex)}) return render_to_response("railway/add-railway.html", context, RequestContext(request))
def add_railway(request): context={} if request.method == 'GET': lsArea = Area.objects.filter(level = '2') lsProperty = DeviceProperties.objects.filter(p_type='2') lsSensorDirection = DeviceProperties.objects.filter(p_type='2',m_type='3') lsDeviceType = DeviceType.objects.all() lsRailwayDirection = ApParam.objects.filter(type='RAILWAY_DIRECTION') departments =Group.objects.all() routes =Route.objects.all() users =User.objects.all().order_by("username") context={ 'lsSensorDirection':lsSensorDirection,'lsArea':lsArea,'lsProperty':lsProperty, 'lsRailwayDirection':lsRailwayDirection, 'lsDeviceType':lsDeviceType, 'departments':departments,'users':users,'routes':routes } context.update(csrf(request)) elif request.method == 'POST': try: _code = request.POST['txtCode'].strip() _name = request.POST['txtJourney'].strip() _route =request.POST['slRoute'].strip() _ManagementUnit =request.POST['slManagementUnit'].strip() _UserUnit =request.POST['slUserUnit'].strip() _manager =request.POST['txtManager'].strip() _phoneNumber =request.POST['txtPhoneNumber'].strip() _note =request.POST['txtNote'].strip() _mac = request.POST['txtMAC'].strip() _area_id = request.POST['slArea'].strip() _address = request.POST['txtAddress'].strip() _fullName = request.POST['txtFullName'].strip() _lat = request.POST['txtLat'].strip() _lng = request.POST['txtLng'].strip() _deviceType = request.POST['slDeviceType'].strip() device_type = DeviceType.objects.get(id=_deviceType) area = Area.objects.get(id = _area_id) group =Group.objects.get(id=_ManagementUnit) user =User.objects.get(id=_UserUnit) route =Route.objects.get(id=_route) device = Device() device.name = _name device.address = _fullName device.short_address = _address device.mac_add = _mac device.area = area device.code = _code device.lat = float(_lat) device.lng = float(_lng) device.description = _note device.owner_name=_manager device.owner_phone=_phoneNumber device.group= group device.user=user device.route =route device.type ='4' _order = Device.objects.filter(route=route).aggregate(Max('order'))['order__max'] device.order = _order + 1 device.device_type = device_type if _deviceType == '3': _railwayDirection = request.POST['slRailwayDirection'].strip() _sensorDirection = request.POST['slSensorDirection'].strip() sensorDirection = DeviceProperties.objects.get(id = _sensorDirection) device.railway_direction = _railwayDirection device.sensor_direction = sensorDirection device.sensor_direction_code = sensorDirection.code device.save() lsDeviceProperties = DeviceProperties.objects.filter(p_type='2') for deviceProperties in lsDeviceProperties: temp = deviceProperties deviceInfor = DeviceInfor() deviceInfor.device = device deviceInfor.value = float('0') if request.POST.get(str(temp.code)): deviceInfor.status = '1' else : deviceInfor.status = '0' deviceInfor.device_pro = temp deviceInfor.save() return HttpResponseRedirect('/railway/list/') except Exception as ex: print(ex) context.update({'has_error':str(ex)}) return render_to_response("railway/add-railway.html", context, RequestContext(request))