Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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))
Exemplo n.º 3
0
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))