-
-
Notifications
You must be signed in to change notification settings - Fork 80
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
4 changed files
with
49 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""A command to load OWASP Nest data.""" | ||
|
||
import contextlib | ||
|
||
from algoliasearch_django import register, unregister | ||
from algoliasearch_django.registration import RegistrationError | ||
from django.apps import apps | ||
from django.core.management import call_command | ||
from django.core.management.base import BaseCommand | ||
from django.db import transaction | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Load OWASP Nest data." | ||
|
||
def handle(self, *_args, **_options): | ||
nest_apps = ("github", "owasp") | ||
|
||
# Disable indexing | ||
for nest_app in nest_apps: | ||
for model in apps.get_app_config(nest_app).get_models(): | ||
with contextlib.suppress(RegistrationError): | ||
unregister(model) | ||
|
||
# Run loaddata | ||
with transaction.atomic(): | ||
call_command("loaddata", "data/nest.json", "-v", "3") | ||
|
||
# Enable indexing | ||
for nest_app in nest_apps: | ||
for model in apps.get_app_config(nest_app).get_models(): | ||
with contextlib.suppress(RegistrationError): | ||
register(model) |
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 |
---|---|---|
@@ -1,32 +1,18 @@ | ||
"""A command to purge OWASP Nest data.""" | ||
|
||
from django.apps import apps | ||
from django.core.management.base import BaseCommand | ||
from django.db import connection | ||
|
||
from apps.github.models import Issue, Label, Organization, Release, Repository, User | ||
from apps.owasp.models import Chapter, Committee, Event, Project | ||
|
||
BATCH_SIZE = 10 | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Purge OWASP Nest data." | ||
|
||
def handle(self, *_args, **options): | ||
with connection.cursor() as cursor: | ||
models = ( | ||
Chapter, | ||
Committee, | ||
Event, | ||
Issue, | ||
Label, | ||
Organization, | ||
Project, | ||
Release, | ||
Repository, | ||
User, | ||
) | ||
nest_apps = ("github", "owasp") | ||
|
||
for model in models: | ||
cursor.execute(f"TRUNCATE TABLE {model._meta.db_table} CASCADE") # noqa: SLF001 | ||
print(f"Purged GitHub {model._meta.verbose_name_plural}") # noqa: SLF001 | ||
with connection.cursor() as cursor: | ||
for nest_app in nest_apps: | ||
for model in apps.get_app_config(nest_app).get_models(): | ||
cursor.execute(f"TRUNCATE TABLE {model._meta.db_table} CASCADE") # noqa: SLF001 | ||
print(f"Purged GitHub {model._meta.verbose_name_plural}") # noqa: SLF001 |
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