Esempio n. 1
0
def add_preprint_doi_created(apps, schema_editor):
    """
    Sets preprint_doi_created equal to date_published for existing published preprints.
    """
    null_preprint_doi_created = PreprintService.objects.filter(
        preprint_doi_created__isnull=True, date_published__isnull=False)
    preprints_count = null_preprint_doi_created.count()
    current_preprint = 0
    logger.info(
        '{} published preprints found with preprint_doi_created is null.'.
        format(preprints_count))

    with disable_auto_now_fields(PreprintService):
        for preprint in null_preprint_doi_created:
            current_preprint += 1
            if preprint.get_identifier('doi'):
                preprint.preprint_doi_created = preprint.date_published
                preprint.save()
                logger.info(
                    'Preprint ID {}, {}/{} preprint_doi_created field populated.'
                    .format(preprint._id, current_preprint, preprints_count))
            else:
                logger.info(
                    'Preprint ID {}, {}/{} skipped because a DOI has not been created.'
                    .format(preprint._id, current_preprint, preprints_count))
Esempio n. 2
0
def add_preprint_doi_created(state, schema):
    """
    Sets preprint_doi_created equal to date_published for existing published preprints.
    """
    PreprintService = state.get_model('osf', 'preprintservice')
    null_preprint_doi_created = PreprintService.objects.filter(
        preprint_doi_created__isnull=True, date_published__isnull=False)
    preprints_count = null_preprint_doi_created.count()
    current_preprint = 0
    logger.info(
        '{} published preprints found with preprint_doi_created is null.'.
        format(preprints_count))
    ContentType = state.get_model('contenttypes', 'ContentType')
    Identifier = state.get_model('osf', 'identifier')

    with disable_auto_now_fields(models=[PreprintService]):
        for preprint in null_preprint_doi_created:
            current_preprint += 1
            content_type = ContentType.objects.get_for_model(preprint)
            if Identifier.objects.filter(object_id=preprint.id,
                                         category='doi',
                                         content_type=content_type).exists():
                preprint.preprint_doi_created = preprint.date_published
                preprint.save()
                logger.info(
                    'Preprint ID {}, {}/{} preprint_doi_created field populated.'
                    .format(preprint.id, current_preprint, preprints_count))
            else:
                logger.info(
                    'Preprint ID {}, {}/{} skipped because a DOI has not been created.'
                    .format(preprint.id, current_preprint, preprints_count))
def unmigrate_user_guid_array_from_m2m(state, schema):
    Comment = state.get_model('osf', 'comment')
    with disable_auto_now_fields(models=[Comment]):
        for comment in Comment.objects.exclude(
                ever_mentioned__isnull=False).all():
            comment._ever_mentioned = list(
                comment.ever_mentioned.values_list('guids___id', flat=True))
            comment.save()
 def submission_stale(self, preprint, journal_one, submitter):
     with disable_auto_now_fields(models=[ChronosSubmission]):
         submission = ChronosSubmission(
             submitter=submitter, journal=journal_one, preprint=preprint, status=2,
             raw_response='', publication_id='fake-publication-id-stale',
         )
         submission.modified = timezone.now() - settings.CHRONOS_SUBMISSION_UPDATE_TIME - timedelta(days=1)
         submission.save()
         return submission
Esempio n. 5
0
    def test_auto_now_does_not_modify_non_auto_now_fields(self, node):
        old_created = node.created
        assert Node._meta.get_field('created').auto_now is False

        with disable_auto_now_fields(models=[Node]):
            node.description = 'new cool description!!'
        node.save()

        assert node.created == old_created
        assert Node._meta.get_field('created').auto_now is False
Esempio n. 6
0
    def test_auto_now_does_not_modify_non_auto_now_fields(self, node):
        old_created = node.created
        assert Node._meta.get_field('created').auto_now is False

        with disable_auto_now_fields(models=[Node]):
            node.description = 'new cool description!!'
        node.save()

        assert node.created == old_created
        assert Node._meta.get_field('created').auto_now is False
 def handle(self, *args, **options):
     dry_run = options.get('dry_run', False)
     src = options.get('source')
     dest = options.get('dest')
     if not dry_run:
         script_utils.add_file_logger(logger, __file__)
     with transaction.atomic():
         with disable_auto_now_fields():
             rebrand_provider(src, dest)
             delete_old_provider(src)
             reindex_share(dest, dry_run)
         if dry_run:
             raise RuntimeError('Dry Run -- Transaction rolled back')
 def submission_stale(self, preprint, journal_one, submitter):
     with disable_auto_now_fields(models=[ChronosSubmission]):
         submission = ChronosSubmission(
             submitter=submitter,
             journal=journal_one,
             preprint=preprint,
             status=2,
             raw_response='',
             publication_id='fake-publication-id-stale',
         )
         submission.modified = timezone.now(
         ) - settings.CHRONOS_SUBMISSION_UPDATE_TIME - timedelta(days=1)
         submission.save()
         return submission
Esempio n. 9
0
    def test_auto_now_all_models_not_updated(self, node):
        # update, save, confirm date changes
        original_date_modified = node.modified
        node.title = 'A'
        node.save()
        assert node.modified != original_date_modified

        # update and save within context manager, confirm date doesn't change (i.e. auto_now was set to False)
        new_date_modified = node.modified
        with disable_auto_now_fields():
            node.title = 'AB'
            node.save()
        assert node.modified == new_date_modified

        # update, save, confirm date changes (i.e. that auto_now was set back to True)
        node.title = 'ABC'
        node.save()
        assert node.modified != new_date_modified
Esempio n. 10
0
    def test_auto_now_all_models_not_updated(self, node):
        # update, save, confirm date changes
        original_date_modified = node.modified
        node.title = 'A'
        node.save()
        assert node.modified != original_date_modified

        # update and save within context manager, confirm date doesn't change (i.e. auto_now was set to False)
        new_date_modified = node.modified
        with disable_auto_now_fields():
            node.title = 'AB'
            node.save()
        assert node.modified == new_date_modified

        # update, save, confirm date changes (i.e. that auto_now was set back to True)
        node.title = 'ABC'
        node.save()
        assert node.modified != new_date_modified
def add_preprint_doi_created(state, schema):
    """
    Sets preprint_doi_created equal to date_published for existing published preprints.
    """
    PreprintService = state.get_model('osf', 'preprintservice')
    null_preprint_doi_created = PreprintService.objects.filter(preprint_doi_created__isnull=True, date_published__isnull=False)
    preprints_count = null_preprint_doi_created.count()
    current_preprint = 0
    logger.info('{} published preprints found with preprint_doi_created is null.'.format(preprints_count))
    ContentType = state.get_model('contenttypes', 'ContentType')
    Identifier = state.get_model('osf', 'identifier')

    with disable_auto_now_fields(models=[PreprintService]):
        for preprint in null_preprint_doi_created:
            current_preprint += 1
            content_type = ContentType.objects.get_for_model(preprint)
            if Identifier.objects.filter(object_id=preprint.id, category='doi', content_type=content_type).exists():
                preprint.preprint_doi_created = preprint.date_published
                preprint.save()
                logger.info('Preprint ID {}, {}/{} preprint_doi_created field populated.'.format(preprint.id, current_preprint, preprints_count))
            else:
                logger.info('Preprint ID {}, {}/{} skipped because a DOI has not been created.'.format(preprint.id, current_preprint, preprints_count))
def unmigrate_user_guid_array_from_m2m(state, schema):
    Comment = state.get_model('osf', 'comment')
    with disable_auto_now_fields(models=[Comment]):
        for comment in Comment.objects.exclude(ever_mentioned__isnull=False).all():
            comment._ever_mentioned = list(comment.ever_mentioned.values_list('guids___id', flat=True))
            comment.save()