-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
404 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from django.conf import settings | ||
from django.core.management.base import BaseCommand | ||
|
||
from utils.models import RORImport | ||
from core.models import Organization | ||
from utils.logger import get_logger | ||
|
||
|
||
logger = get_logger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
Fetches ROR data and generates Organization records. | ||
""" | ||
|
||
help = "Fetches ROR data and generates Organization records." | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
'--test_full_import', | ||
help='By default, the command only runs 100 records when DEBUG=True.' | ||
'Pass --test_full_import to import the entire dump in development.', | ||
action='store_true', | ||
) | ||
return super().add_arguments(parser) | ||
|
||
def handle(self, *args, **options): | ||
ror_import = RORImport.objects.create() | ||
ror_import.get_records() | ||
|
||
# The import is necessary. | ||
# Check we have the right copy of the data dump. | ||
if ror_import.ongoing or settings.DEBUG: | ||
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: | ||
test_full_import = options.get('test_full_import', False) | ||
Organization.import_ror_batch( | ||
ror_import, | ||
test_full_import=test_full_import, | ||
) | ||
|
||
# The process did not error out, so it can be considered a success. | ||
if ror_import.ongoing: | ||
ror_import.status = ror_import.RORImportStatus.SUCCESSFUL | ||
ror_import.save() | ||
|
||
logger.info(ror_import.status) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Generated by Django 4.2.14 on 2024-07-26 20:51 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('utils', '0034_rename_toaddress_addressee'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='RORImport', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('started', models.DateTimeField(auto_now_add=True)), | ||
('stopped', models.DateTimeField(blank=True, null=True)), | ||
('status', models.CharField(choices=[('ongoing', 'Ongoing'), ('unnecessary', 'Unnecessary'), ('successful', 'Successful'), ('failed', 'Failed')], default='ongoing')), | ||
('records', models.JSONField(default=dict)), | ||
], | ||
options={ | ||
'verbose_name': 'ROR import', | ||
'verbose_name_plural': 'ROR imports', | ||
'get_latest_by': 'started', | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='RORImportError', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('message', models.TextField(blank=True)), | ||
('ror_import', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='utils.rorimport')), | ||
], | ||
), | ||
] |
Oops, something went wrong.