def __clone_directory_tree(self, filter_criteria_util, cloned_dir_layout, original_directories, parent_cloned_directory): for each_original_directory in original_directories: cloned_directory = Directory(name=each_original_directory.name) cloned_directory.dir_layout = cloned_dir_layout cloned_directory.parent = parent_cloned_directory if (each_original_directory.banner_file is not None and len(each_original_directory.banner_file.name) > 0 and os.path.exists(each_original_directory.banner_file.path)): dup_banner = ContentFile( each_original_directory.banner_file.read()) dup_banner.name = each_original_directory.original_file_name cloned_directory.banner_file = dup_banner cloned_directory.save() cloned_directory.individual_files.set( list(each_original_directory.individual_files.all())) cloned_directory.creators.set( list(each_original_directory.creators.all())) cloned_directory.coverages.set( list(each_original_directory.coverages.all())) cloned_directory.subjects.set( list(each_original_directory.subjects.all())) cloned_directory.keywords.set( list(each_original_directory.keywords.all())) cloned_directory.workareas.set( list(each_original_directory.workareas.all())) cloned_directory.languages.set( list(each_original_directory.languages.all())) cloned_directory.catalogers.set( list(each_original_directory.catalogers.all())) cloned_directory.save() self.__clone_directory_tree( filter_criteria_util, cloned_dir_layout, each_original_directory.subdirectories.all(), cloned_directory)
def create(self, validated_data): validated_data_copy = dict(validated_data) del validated_data_copy['individual_files'] del validated_data_copy['creators'] del validated_data_copy['coverages'] del validated_data_copy['subjects'] del validated_data_copy['keywords'] del validated_data_copy['workareas'] del validated_data_copy['languages'] del validated_data_copy['catalogers'] directory = Directory(**validated_data_copy) self.__create_update(directory) directory.individual_files.set(validated_data['individual_files']) directory.creators.set(validated_data['creators']) directory.coverages.set(validated_data['coverages']) directory.subjects.set(validated_data['subjects']) directory.keywords.set(validated_data['keywords']) directory.workareas.set(validated_data['workareas']) directory.languages.set(validated_data['languages']) directory.catalogers.set(validated_data['catalogers']) return directory
def create(self, validated_data): validated_data_copy = dict(validated_data) del validated_data_copy['individual_files'] del validated_data_copy['creators'] del validated_data_copy['subjects'] del validated_data_copy['keywords'] del validated_data_copy['languages'] del validated_data_copy['audiences'] del validated_data_copy['resourcetypes'] del validated_data_copy['catalogers'] del validated_data_copy['collections'] directory = Directory(**validated_data_copy) self.__create_update(directory) directory.individual_files.set(validated_data['individual_files']) directory.creators.set(validated_data['creators']) directory.subjects.set(validated_data['subjects']) directory.keywords.set(validated_data['keywords']) directory.languages.set(validated_data['languages']) directory.audiences.set(validated_data['audiences']) directory.resourcetypes.set(validated_data['resourcetypes']) directory.catalogers.set(validated_data['catalogers']) directory.catalogers.set(validated_data['collections']) return directory
def setUp(self): self.dir_layout = DirectoryLayout.objects.create( name="foo", description="bar", banner_file=SimpleUploadedFile("sample_file", "File Contents".encode())) self.coverages = Coverage.objects.bulk_create([ Coverage(name="cov1", description="desc cov1"), Coverage(name="cov2", description="desc cov2"), Coverage(name="cov3", description="desc cov3"), ]) self.creators = Creator.objects.bulk_create([ Creator(name="Creator 1", description="desc Creator 1"), Creator(name="Creator 2", description="desc Creator 2"), Creator(name="Creator 3", description="desc Creator 3"), ]) self.subjects = Subject.objects.bulk_create([ Subject(name="subject 1", description="desc subject 1"), Subject(name="subject 2", description="desc subject 2"), Subject(name="subject 3", description="desc subject 3"), ]) self.keywords = Keyword.objects.bulk_create([ Keyword(name="keyword 1", description="desc keyword 1"), Keyword(name="keyword 2", description="desc keyword 2"), Keyword(name="keyword 3", description="desc keyword 3"), ]) self.workareas = Workarea.objects.bulk_create([ Workarea(name="workarea 1", description="desc workarea 1"), Workarea(name="workarea 2", description="desc workarea 2"), Workarea(name="workarea 3", description="desc workarea 3"), ]) self.languages = Language.objects.bulk_create([ Language(name="language 1", description="desc language 1"), Language(name="language 2", description="desc language 2"), Language(name="language 3", description="desc language 3"), ]) self.catalogers = Cataloger.objects.bulk_create([ Cataloger(name="cataloger 1", description="desc cataloger 1"), Cataloger(name="cataloger 2", description="desc cataloger 2"), Cataloger(name="cataloger 3", description="desc cataloger 3"), ]) content_1 = Content(name="content file 1", description="content file 1 desc", content_file=SimpleUploadedFile( "file_1", "Contents of file 1".encode()), updated_time=date.today()) content_1.content_file_uploaded = True content_1.save() content_2 = Content(name="content file 2", description="content file 2 desc", content_file=SimpleUploadedFile( "file_2", "Contents of file 2".encode()), updated_time=date.today()) content_2.content_file_uploaded = True content_2.save() self.contents = [content_1, content_2] dir_1 = Directory( name="parent dir 1", dir_layout=self.dir_layout, banner_file=SimpleUploadedFile( "top_dir1_banner_file", "dir 1 banner file content".encode()), creators_need_all=True, coverages_need_all=True, subjects_need_all=True, keywords_need_all=True, workareas_need_all=True, languages_need_all=True, catalogers_need_all=True, ) dir_1.save() dir_1.individual_files.set([content_1]) dir_1.coverages.set([self.coverages[0]]) dir_1.creators.set([self.creators[0]]) dir_1.subjects.set([self.subjects[0]]) dir_1.keywords.set([self.keywords[0]]) dir_1.workareas.set([self.workareas[0]]) dir_1.languages.set([self.languages[0]]) dir_1.catalogers.set([self.catalogers[0]]) dir_2 = Directory( name="parent dir 2", dir_layout=self.dir_layout, banner_file=SimpleUploadedFile( "top_dir2_banner_file", "dir 2 banner file content".encode()), creators_need_all=True, coverages_need_all=True, subjects_need_all=False, keywords_need_all=True, workareas_need_all=False, languages_need_all=True, catalogers_need_all=True, ) dir_2.save() dir_2.individual_files.set([content_1, content_2]) dir_2.coverages.set([self.coverages[1]]) dir_2.creators.set([self.creators[1]]) dir_2.subjects.set([self.subjects[1]]) dir_2.keywords.set([self.keywords[1]]) dir_2.workareas.set([self.workareas[1]]) dir_2.languages.set([self.languages[1]]) dir_2.catalogers.set([self.catalogers[0]]) dir_3 = Directory( name="child dir", dir_layout=self.dir_layout, banner_file=SimpleUploadedFile( "child_banner_file", "dir 3 banner file content".encode()), creators_need_all=True, coverages_need_all=False, subjects_need_all=True, keywords_need_all=True, workareas_need_all=True, languages_need_all=False, catalogers_need_all=False, ) dir_3.save() dir_3.individual_files.set([content_2]) dir_3.coverages.set([self.coverages[0], self.coverages[1]]) dir_3.creators.set([self.creators[0], self.creators[1]]) dir_3.subjects.set([self.subjects[0], self.subjects[1]]) dir_3.keywords.set([self.keywords[0], self.keywords[1]]) dir_3.workareas.set([self.workareas[0], self.workareas[1]]) dir_3.languages.set([self.languages[0], self.languages[1]]) dir_3.catalogers.set([self.catalogers[0], self.catalogers[1]]) dir_4 = Directory( name="inner child dir", dir_layout=self.dir_layout, banner_file=SimpleUploadedFile( "inner_child_banner_file", "dir 4 banner file content".encode()), creators_need_all=False, coverages_need_all=True, subjects_need_all=True, keywords_need_all=False, workareas_need_all=False, languages_need_all=False, catalogers_need_all=True, ) dir_4.save() self.directories = [dir_1, dir_2, dir_3, dir_4]