data cleaning commands
parent
0cb15ca999
commit
6507c392f7
|
@ -0,0 +1,22 @@
|
|||
from django.core.management.base import BaseCommand
|
||||
from django.db.models import Count
|
||||
|
||||
from regluit.core.models import Work, WasWork
|
||||
from regluit.core.bookloader import merge_works
|
||||
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
'''remove works and editions without titles'''
|
||||
help = "remove works and editions without titles"
|
||||
|
||||
def handle(self, **options):
|
||||
orphans = Work.objects.annotate(num_editions=Count('editions')).filter(num_editions=0)
|
||||
for work in orphans:
|
||||
self.stdout.write('cleaning %s' % work.title)
|
||||
parent = None
|
||||
for parent in WasWork.objects.filter(was=work.id):
|
||||
# remerge into parent
|
||||
merge_works(parent.work, work)
|
||||
if not parent:
|
||||
work.delete()
|
|
@ -0,0 +1,17 @@
|
|||
from django.core.management.base import BaseCommand
|
||||
from django.db.models import Sum
|
||||
|
||||
from regluit.core.models import Work
|
||||
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
'''remove works and editions without titles'''
|
||||
help = "remove works and editions without titles"
|
||||
|
||||
def handle(self, **options):
|
||||
qs = Work.objects.annotate(num_free=Sum('editions__ebooks__active')).filter(num_free__gt=0)
|
||||
for free in qs.filter(is_free=False):
|
||||
self.stdout.write('freeing %s' % free.title)
|
||||
free.is_free = True
|
||||
free.save()
|
Loading…
Reference in New Issue