Skip to content

Commit

Permalink
feat #3168 Adjustments from manual testing
Browse files Browse the repository at this point in the history
  • Loading branch information
joemull committed Jan 27, 2025
1 parent 069c497 commit 5dbbf18
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Migration(migrations.Migration):
('ror', models.URLField(blank=True, help_text='Research Organization Registry identifier (URL)', validators=[core.models.validate_ror], verbose_name='ROR')),
('ror_status', models.CharField(blank=True, choices=[('active', 'Active'), ('inactive', 'Inactive'), ('withdrawn', 'Withdrawn'), ('unknown', 'Unknown')], default='unknown', max_length=10)),
('ror_record_timestamp', models.CharField(blank=True, help_text='The admin.last_modified.date string from ROR data', max_length=10)),
('website', models.CharField(blank=True, max_length=500)),
('website', models.CharField(blank=True, max_length=2000)),
('locations', models.ManyToManyField(blank=True, null=True, to='core.location')),
],
options={'ordering': ['ror_display__value']},
Expand Down
6 changes: 4 additions & 2 deletions src/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2048,7 +2048,7 @@ class RORStatus(models.TextChoices):
)
website = models.CharField(
blank=True,
max_length=500,
max_length=2000,
)
locations = models.ManyToManyField(
'Location',
Expand Down Expand Up @@ -2303,14 +2303,16 @@ def import_ror_batch(cls, ror_import, limit=0):
json_string = zip_ref.read(file_info).decode(encoding="utf-8")
data = json.loads(json_string)
data = ror_import.filter_new_records(data, organizations)
if len(data) == 0:
ror_import.status = ror_import.RORImportStatus.UNNECESSARY
if limit:
data = data[:limit]
description = f"Importing {len(data)} ROR records"
for item in tqdm.tqdm(data, desc=description):
try:
cls.create_from_ror_record(item)
except Exception as error:
message = f'{error}\n{json.dumps(item)}'
message = f'{type(error)}: {error}\n{json.dumps(item)}'
RORImportError.objects.create(
ror_import=ror_import,
message=message,
Expand Down
7 changes: 5 additions & 2 deletions src/utils/management/commands/import_ror_data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.conf import settings
from django.core.management.base import BaseCommand
from django.utils import timezone

from utils.models import RORImport
from core.models import Organization
Expand Down Expand Up @@ -39,19 +40,21 @@ def handle(self, *args, **options):

# The import is necessary.
# Check we have the right copy of the data dump.
if ror_import.ongoing or settings.DEBUG:
if ror_import.ongoing:
if not ror_import.previous_import:
ror_import.download_data()
elif ror_import.previous_import.zip_path != ror_import.zip_path:
ror_import.download_data()

# The data is all downloaded and ready to import.
if ror_import.ongoing or settings.DEBUG:
if ror_import.ongoing:
Organization.import_ror_batch(
ror_import,
limit=limit,
)

ror_import.stopped = timezone.now()
ror_import.save()
# The process did not error out, so it can be considered a success.
if ror_import.ongoing:
ror_import.status = ror_import.RORImportStatus.SUCCESSFUL
Expand Down
2 changes: 1 addition & 1 deletion src/utils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def get_records(self):
self.records = response.json()
self.save()
if not self.new_download_needed:
self.status = self.RORImportStatus.UNNECESSARY
self.status = self.RORImportStatus.ONGOING
self.save()
except requests.RequestException as error:
self.fail(error)
Expand Down

0 comments on commit 5dbbf18

Please sign in to comment.