def plan(account_id, plan_id): try: dao = PlanDao(content, account_id) plan = dao.retrieve(plan_id) return dao.get_schema().dumps(plan, indent=2), 200 except Exception as e: raise InvalidUsage(str(e))
def update_plan_cdl(account_id, plan_id): try: dao = PlanDao(content, account_id) plan = dao.retrieve(plan_id) plan.cdl = request.data dao.save(plan) return plan.cdl, 200 except Exception as e: raise InvalidUsage(str(e))
def plan_kml(account_id, plan_id): dao = PlanDao(content, account_id) plan = dao.retrieve(plan_id) fin = preprocess(StringIO(plan.cdl)) analyser = CdlFileAnalyser() cdl_file = analyser.analyse(fin) kml = cdlfile_to_KML(cdl_file, plan_id) return kml, 200, { 'Content-Type': 'application/vnd.google-earth.kml+xml; charset=utf-8' }
def plan_update(account_id, plan_id): try: dao = PlanDao(content, account_id) plan = dao.retrieve(plan_id) plan = dao.from_json(request.data) if plan_id != plan.plan_id: raise Exception("Cannot change the plan ID") dao.save(plan) except Exception as e: raise InvalidUsage(str(e)) return dao.get_schema().dumps(plan, indent=2), 200
def setUp(self): os.system("rm -rf ./test_content/*") self.account_dao = AccountDao(Path("./test_content")) account = self.account_dao.load({ 'identifier': 1, 'name': 'Trilogy Partners', 'email': '*****@*****.**' }) self.account_dao.create(account) self.vessel_dao = VesselDao(Path("./test_content"), account.identifier) trilogy = self.vessel_dao.load({ 'account_id': 1, 'identifier': 'trilogy', 'name': 'SV Trilogy', 'flag': 'Australian', 'rego': '806176', 'speed_kts': 7.6, }) self.vessel_dao.create(trilogy) x = self.vessel_dao.retrieve('trilogy') self.plan_dao = PlanDao(Path("./test_content"), account.identifier)
def get_plan_cdl(account_id, plan_id): dao = PlanDao(content, account_id) plan = dao.retrieve(plan_id) return plan.cdl, 200
def plan_add(account_id): dao = PlanDao(content, account_id) plan = dao.from_json(request.data) dao.create(plan) plan = dao.retrieve(plan.plan_id) return dao.get_schema().dumps(plan, indent=2), 200
def plan_list(account_id): dao = PlanDao(content, account_id) plans = dao.find_all() return dao.get_schema().dumps(plans, many=True, indent=2), 200