def create_subjects_recursive(custom_provider, root_text, exclude_texts, parent=None): logger.info('Duplicating BePress subject {} on {}'.format(root_text, custom_provider._id)) bepress_subj = Subject.objects.get(provider=BEPRESS_PROVIDER, text=root_text) custom_subj = Subject(text=root_text, parent=parent, bepress_subject=bepress_subj, provider=custom_provider) custom_subj.save() # This is not a problem now, as all excluded subjects are leafs, but it could be problematic if non-leafs had their children excluded. # It could also be problematic if they didn't, if any of those children are used by existing preprints. # TODO: Determine correct resolution for child_text in bepress_subj.children.exclude(text__in=exclude_texts).values_list('text', flat=True): create_subjects_recursive(custom_provider, child_text, exclude_texts, parent=custom_subj)
def create_subjects_recursive(custom_provider, root_text, exclude_texts, parent=None): logger.info('Duplicating BePress subject {} on {}'.format(root_text, custom_provider._id)) bepress_subj = Subject.objects.get(provider=BEPRESS_PROVIDER, text=root_text) custom_subj = Subject(text=root_text, parent=parent, bepress_subject=bepress_subj, provider=custom_provider) custom_subj.save() # This is not a problem now, as all excluded subjects are leafs, but it could be problematic if non-leafs had their children excluded. # It could also be problematic if they didn't, if any of those children are used by existing preprints. # TODO: Determine correct resolution for child_text in bepress_subj.children.exclude(text__in=exclude_texts).values_list('text', flat=True): create_subjects_recursive(custom_provider, child_text, exclude_texts, parent=custom_subj)
def map_custom_subject(custom_provider, name, parent, mapping): logger.info('Attempting to create subject {} on {} from {} with {}'.format(name, custom_provider._id, mapping, 'parent {}'.format(parent) if parent else 'no parent')) if parent: parent_subject = Subject.objects.filter(provider=custom_provider, text=parent).first() else: parent_subject = None bepress_subject = Subject.objects.get(provider=BEPRESS_PROVIDER, text=mapping) if parent and not parent_subject: return False custom_subject = Subject(provider=custom_provider, text=name, parent=parent_subject, bepress_subject=bepress_subject) custom_subject.save() return True
def map_custom_subject(custom_provider, name, parent, mapping): logger.info('Attempting to create subject {} on {} from {} with {}'.format(name, custom_provider._id, mapping, 'parent {}'.format(parent) if parent else 'no parent')) if parent: parent_subject = Subject.objects.filter(provider=custom_provider, text=parent).first() else: parent_subject = None bepress_subject = Subject.objects.get(provider=BEPRESS_PROVIDER, text=mapping) if parent and not parent_subject: return False custom_subject = Subject(provider=custom_provider, text=name, parent=parent_subject, bepress_subject=bepress_subject) custom_subject.save() return True
def add_subjects_to_paleorxiv(): paleoarix = PreprintProvider.objects.get(_id='paleorxiv') bepress_subject = Subject.objects.get(text='Paleontology', provider___id='osf') life_sciences = Subject.objects.get(text='Earth and Life Sciences', provider=paleoarix) ichnology = Subject(text='Ichnology', provider=paleoarix, parent=life_sciences, bepress_subject=bepress_subject) ichnology.save() taphonomy = Subject(text='Taphonomy', provider=paleoarix, parent=life_sciences, bepress_subject=bepress_subject) taphonomy.save() paleoarix.save()