def get(self, id, **kwargs): user = kwargs['user'] plan = self.plan_repository.find(id) if not plan: abort(404, message="No plan with that id exists") if plan.user.id != user.id and not query(plan.shared_users).contains(user, lambda lhs, rhs: lhs.id == rhs.id): abort(404, message="No plan with that id exists") if 'include_polyline' in request.args and request.args['include_polyline']: polyline = get_polyline(plan) plan_dict = plan.as_dict() plan_dict['polylines'] = polyline return plan_dict return plan
def post(self, id, **kwargs): user = kwargs['user'] plan = query(self.plan_repository.get(user=user, id=id) ).single_or_default(default=None) if plan is None: abort(404, message="No plan with that id was found") self.plan_repository.clear_plan(plan) populate_sample_plan(plan) result = self.plan_repository.add_or_update(plan) if not result.success: on_error(error_message="Could not randomize plan", result=result) self.plan_repository.save_changes() polyline = get_polyline(plan) plan_dict = plan.as_dict() plan_dict['polylines'] = polyline return plan_dict
def post(self, **kwargs): user = kwargs['user'] json = request.json if 'categories' not in json or len(json['categories']) == 0: on_error(error_message="Categories were not provided") if 'plan' not in json: on_error(error_message="Plan details were not provided") categories = self.category_repository.get_from_list(json['categories']) plan = json['plan'] plan = Plan.from_json(plan, user) self.plan_repository.expunge(plan) result, failed_categories = populate_sample_plan(plan, categories) if not result: return failed_categories, 400 polyline = get_polyline(plan) plan_dict = plan.as_dict() plan_dict['polylines'] = polyline return plan_dict