def create_machine(): db.db.session.add(models.Machine(name=flask.request.values['name'])) db.db.session.commit() machine = db.db.session.query(models.Machine).order_by( models.Machine.id.desc()).first() return flask.jsonify({ 'status_code': 200, 'msg': 'machine {} added'.format(machine.name) })
def setUp(self): models.Base.metadata.create_all(engine) cloud = models.Cloud(name='private_cloud', description='a private cloud') session.add(cloud) session.add( models.Machine(hostname='zeus', description='application server', cloud=cloud, operating_system='Arch 64')) session.add( models.Machine(hostname='apollo', description='database server', cloud=cloud, operating_system='Arch 64')) session.add( models.Machine(hostname='hermes', description='messaging server', cloud=cloud, operating_system='Ubuntu 13.10 64')) session.commit() self.to_db_string = "sqlite:////test_to_db.db"
def dailyReportEdit(request, reportId): dailyReport = models.DailyReport.objects.get(id=reportId) dailyReport.base = models.Base(id=request.POST['base']) dailyReport.reportUser = models.Person.objects.get(id=request.POST['reportUser']) pwd = request.POST['pwd'] if pwd != dailyReport.operator.pwd: return HttpResponse("密码错误") dailyReport.operator = models.Person(id=request.POST['operator']) dailyReport.machine = models.Machine(id=request.POST['machine']) dailyReport.oil = request.POST['oil'] dailyReport.startTime = request.POST['startTime'] dailyReport.endTime = request.POST['endTime'] dailyReport.workTime = request.POST['workTime'] dailyReport.workTotal = request.POST['workTotal'] dailyReport.waterCar = request.POST['waterCar'] dailyReport.waterSize = request.POST['waterSize'] dailyReport.tag = request.POST['tag'] html = dailyReport.save() return HttpResponse(html)
def dailyReportAdd(request): reportDate = request.POST['reportDate'] base = models.Base(id=request.POST['base']) reportUser = models.Person.objects.get(id=request.POST['reportUser']) pwd = request.POST['pwd'] if pwd != reportUser.pwd: return HttpResponse("密码错误") operator = models.Person(id=request.POST['operator']) machine = models.Machine(id=request.POST['machine']) oil = request.POST['oil'] startTime = request.POST['startTime'] endTime = request.POST['endTime'] workTime = request.POST['workTime'] workTotal = request.POST['workTotal'] waterCar = request.POST['waterCar'] waterSize = request.POST['waterSize'] tag = request.POST['tag'] dailyReport = models.DailyReport(reportDate=reportDate, base=base, reportUser=reportUser, operator=operator, machine=machine, oil=oil , startTime=startTime, endTime=endTime, workTime=workTime, workTotal=workTotal, waterCar=waterCar, waterSize=waterSize, tag=tag) html = dailyReport.save() return HttpResponse(html)
def mockMachine(self, name='Chainsaw', machine_type='test_machine'): machine = models.Machine(name=name,type=machine_type) machine.put() return machine