Skip to content

Commit

Permalink
Merge pull request #17 from CentreForDigitalHumanities/feature/refres…
Browse files Browse the repository at this point in the history
…h-db

Add options to start with fresh database
  • Loading branch information
ar-jan authored Dec 21, 2023
2 parents 995c21f + 1844bab commit c2fe164
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lidiabrowser/lidia/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,15 @@ class Meta:
def __str__(self):
lidiaterm = self.lidiaterm.term if self.lidiaterm else None
return f"{self.articleterm}/{lidiaterm}"


def delete_all() -> None:
"""Delete all objects in lidia app."""

Publication.objects.all().delete()
Language.objects.all().delete()
BaseAnnotation.objects.all().delete()
ArticleTerm.objects.all().delete()
LidiaTerm.objects.all().delete()
Category.objects.all().delete()
TermGroup.objects.all().delete()
12 changes: 11 additions & 1 deletion lidiabrowser/sync/management/commands/populate.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
from django.core.management.base import BaseCommand
from django.core.management.base import BaseCommand, CommandParser

from sync.populate import populate
from lidia.models import delete_all


class Command(BaseCommand):
help = "Parse raw sync content and populate LIDIA models"

def add_arguments(self, parser: CommandParser) -> None:
parser.add_argument(
"--refresh",
action="store_true",
help="First remove annotations from database to solve any sync problems"
)

def handle(self, *args, **options):
if options["refresh"]:
delete_all()
populate()
12 changes: 11 additions & 1 deletion lidiabrowser/sync/management/commands/sync.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
from django.core.management.base import BaseCommand
from django.core.management.base import BaseCommand, CommandParser

from sync.zoterosync import sync
from sync.models import delete_all


class Command(BaseCommand):
help = "Synchronize with data on the Zotero server"

def add_arguments(self, parser: CommandParser) -> None:
parser.add_argument(
"--refresh",
action="store_true",
help="First remove sync information from database to solve any sync problems"
)

def handle(self, *args, **options):
if options["refresh"]:
delete_all()
sync()
7 changes: 7 additions & 0 deletions lidiabrowser/sync/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ class Sync(models.Model):

def __str__(self):
return f"Library #{self.library_id}"


def delete_all() -> None:
"""Delete all objects in sync app."""
Publication.objects.all().delete()
Annotation.objects.all().delete()
Sync.objects.all().delete()

0 comments on commit c2fe164

Please sign in to comment.