def update_project(project_id, name, description, is_private=True, related_fields=[], tags=[], related_tasks=[], done_indices=[]): """ Create a new project :param name: str :param description: str :param user_ID: ObjectId :param is_private: boolean :return: a new created project object """ project = project_business.get_by_id(project_id) ow = ownership_business.get_ownership_by_owned_item(project, 'project') ownership_business.update_by_id(ow['id'], private=is_private) project_business.update_by_id(project_id, name=name, description=description, update_time=datetime.utcnow(), related_fields=related_fields, tags=tags, related_tasks=related_tasks, done_indices=done_indices)
def fork(project_id, new_user_ID): """ fork project :param project_id: :param new_user_ID: :return: """ # get project project = project_business.get_by_id(project_id) # get ownership, and check privacy ownership = ownership_business.get_ownership_by_owned_item( project, 'project') if ownership.private is True: raise NameError('forked project is private, fork failed') if ownership.user.user_ID == new_user_ID: raise NameError('you are forking your self project') # get user object user = UserBusiness.get_by_user_ID(new_user_ID) # copy and save project project_cp = project_business.copy(project) # create ownership relation ownership_business.add(user, True, project=project_cp) # copy staging data sets sds_array = staging_data_set_business.get_by_project_id(project_id, False) for sds in sds_array: staging_data_service.copy_staging_data_set(sds, project_cp) # copy jobs and save jobs = project.jobs jobs_cp = [] for job in jobs: # get source sds if hasattr(job, 'staging_data_set') and job.staging_data_set: sds_cp = staging_data_set_business.get_by_name_and_project( job.staging_data_set.name, job.staging_data_set.project) # sds_cp = staging_data_service.copy_staging_data_set( # job.staging_data_set, project_cp) else: sds_cp = None # copy job job_cp = job_business.copy_job(job, project_cp, sds_cp) if not job_cp: continue jobs_cp.append(job_cp) # copy result staging data set by job and bind to project try: # get result sds result_sds = staging_data_set_business.get_by_job_id(job['id']) # bind job to sds staging_data_set_business.update_job_by_name_and_project( result_sds.name, result_sds.project, job_cp) # staging_data_service.copy_staging_data_set(result_sds, project_cp, # belonged_job=job_cp) except DoesNotExist: pass project_business.update_by_id(project_cp['id'], jobs=jobs_cp) project_cp.reload() return project_cp