-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: migrate management commands from
apis-webpage
to apis-rdf-core
This commit introduces a manangement command that was part of the `webpage` module but is better suited to be part of `apis_core`.
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from django.core.management.base import BaseCommand, CommandError | ||
from apis_core.apis_relations.models import Property | ||
from apis_ontology.models import construct_properties | ||
|
||
|
||
class Command(BaseCommand): | ||
help = ( | ||
"Create and label relationships between entities by running " | ||
"the construct_properties() function in your app's models.py file." | ||
) | ||
|
||
def handle(self, *args, **options): | ||
try: | ||
construct_properties() | ||
self.stdout.write( | ||
self.style.SUCCESS("Successfully ran construct_properties()") | ||
) | ||
except Exception as e: | ||
raise CommandError( | ||
f"construct_properties() raised the " f"following error(s):\n{e}" | ||
) | ||
|
||
try: | ||
props = Property.objects.all() | ||
except Property.DoesNotExist: | ||
raise CommandError("No entity relationships exist.") | ||
|
||
if len(props) > 0: | ||
# TODO would ideally verify existence/validity of relevant fields | ||
# as relationship names alone are useless w/o subj/obj references; | ||
# below msg. purposefully only mentions "labels". | ||
self.stdout.write("The following labels now exist:") | ||
for p in props: | ||
self.stdout.write(self.style.SUCCESS(f"{p.name}"), ending="") | ||
self.stdout.write(f" ... {p.name_reverse}") | ||
else: | ||
# construct_properties() starts out by deleting all existing | ||
# Property objects | ||
self.stdout.write( | ||
self.style.ERROR("No entity relationships found nor created.") | ||
) |