def get_model_or_404(self, instance_id): if not fields.is_valid_id(instance_id): raise WrongParameterException("Malformed ID.") instance = self.model.get(instance_id) if instance is None: abort(404) return instance
def update_data(self, data): if "episode_id" in data and data["episode_id"] in ["all", "main"]: data["episode_id"] = None if "task_type_id" in data and \ not fields.is_valid_id(data["task_type_id"]): data["task_type_id"] = None return data
def get(self): args = self.get_args([ ("after", None, False), ("before", None, False), ("only_files", False, False), ("page_size", 100, False), ("project_id", None, False), ]) permissions.check_manager_permissions() before = self.parse_date_parameter(args["before"]) after = self.parse_date_parameter(args["after"]) page_size = args["page_size"] only_files = args["only_files"] == "true" project_id = args.get("project_id", None) if project_id is not None and not fields.is_valid_id(project_id): raise WrongParameterException( "The project_id parameter is not a valid id") else: return events_service.get_last_events( after=after, before=before, page_size=page_size, only_files=only_files, project_id=project_id, )
def get_model_or_404(self, instance_id): if not fields.is_valid_id(instance_id): raise WrongParameterException("Malformed ID.") instance = self.model.get_by(id=instance_id) if instance is None: raise EntityLinkNotFoundException return instance
def get(self): args = self.get_args([ ("after", None, False), ("before", None, False), ("only_files", False, False), ("page_size", 100, False), ("project_id", None, False), ]) permissions.check_manager_permissions() before = None after = None if args["before"] is not None: try: before = fields.get_date_object( args["before"], "%Y-%m-%dT%H:%M:%S" ) except Exception: try: before = fields.get_date_object(args["before"], "%Y-%m-%d") except Exception: raise WrongParameterException( "Wrong date format for before argument." "Expected format: 2020-01-05T13:23:10 or 2020-01-05" ) if args["after"] is not None: try: after = fields.get_date_object( args["after"], "%Y-%m-%dT%H:%M:%S" ) except Exception: try: after = fields.get_date_object(args["after"], "%Y-%m-%d") except Exception: raise WrongParameterException( "Wrong date format for after argument." "Expected format: 2020-01-05T13:23:10 or 2020-01-05" ) page_size = args["page_size"] only_files = args["only_files"] == "true" project_id = args.get("project_id", None) if project_id is not None and not fields.is_valid_id(project_id): raise WrongParameterException( "The project_id parameter is not a valid id" ) else: return events_service.get_last_events( after=after, before=before, page_size=page_size, only_files=only_files, project_id=project_id )
def remove_tasks(project_id, task_ids): """ Remove fully given tasks and related for given project. The project id filter is there to facilitate right management. """ task_ids = [task_id for task_id in task_ids if fields.is_valid_id(task_id)] tasks = (Task.query.filter(Project.id == project_id).filter( Task.id.in_(task_ids))) for task in tasks: remove_task(task.id, force=True) return task_ids