Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add options to start with fresh database #17

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()