Merge branch 'master' of github.com:Gluejar/regluit
commit
ce1ebfa0ea
|
@ -7,18 +7,33 @@ This script goes through all singleton works and attempts to add_related. 'xx' w
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from django.db.models import Count
|
from django.db.models import Count
|
||||||
from regluit.core import models, bookloader
|
from regluit.core import models, bookloader
|
||||||
|
from itertools import islice
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = "add and merge editions for singleton works"
|
help = "add and merge editions for singleton works"
|
||||||
args = "<language>"
|
args = "<language> <max>"
|
||||||
|
|
||||||
def handle(self, language, **options):
|
|
||||||
|
def handle(self, language, max, **options):
|
||||||
print "Number of singleton Works with language = %s: %s" % (language, models.Work.objects.annotate(num_editions=Count('editions')).filter(num_editions=1, language=language).count())
|
print "Number of singleton Works with language = %s: %s" % (language, models.Work.objects.annotate(num_editions=Count('editions')).filter(num_editions=1, language=language).count())
|
||||||
|
|
||||||
for work in models.Work.objects.annotate(num_editions=Count('editions')).filter(num_editions=1, language=language):
|
try:
|
||||||
|
max = int(max)
|
||||||
|
except:
|
||||||
|
max = None
|
||||||
|
|
||||||
|
for (i, work) in enumerate(islice(models.Work.objects.annotate(num_editions=Count('editions')).filter(num_editions=1, language=language),max)):
|
||||||
#check that there's still only one edition
|
#check that there's still only one edition
|
||||||
|
print "%d %s id:%s #editions:%d #isbn:%s -->" % (i, work, work.id, work.editions.count(), work.first_isbn_13()),
|
||||||
if work.editions.count() != 1:
|
if work.editions.count() != 1:
|
||||||
|
print
|
||||||
continue
|
continue
|
||||||
|
if work.first_isbn_13():
|
||||||
new_editions = bookloader.add_related( work.first_isbn_13() )
|
new_editions = bookloader.add_related( work.first_isbn_13() )
|
||||||
print "clustered %s editions for work %s" % (len(new_editions),work )
|
corresponding_works = set([ed.work for ed in new_editions])
|
||||||
|
print "clustered %s editions for work %s" % (len(new_editions),work ), \
|
||||||
|
"| Corresponding works : ", [(w.id, w.language, w.editions.count()) for w in corresponding_works], \
|
||||||
|
"#corresponding_works:%s" % (len(corresponding_works))
|
||||||
|
else:
|
||||||
|
print "no ISBN for this work and therefore no new editions"
|
||||||
print "Updated Number of singleton Works with language = %s: %s" % (language,models.Work.objects.annotate(num_editions=Count('editions')).filter(num_editions=1, language=language).count() )
|
print "Updated Number of singleton Works with language = %s: %s" % (language,models.Work.objects.annotate(num_editions=Count('editions')).filter(num_editions=1, language=language).count() )
|
||||||
|
|
|
@ -228,6 +228,9 @@ class Identifier(models.Model):
|
||||||
i.save()
|
i.save()
|
||||||
return i
|
return i
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return u'{0}:{1}'.format(self.type, self.value)
|
||||||
|
|
||||||
class Work(models.Model):
|
class Work(models.Model):
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
title = models.CharField(max_length=1000)
|
title = models.CharField(max_length=1000)
|
||||||
|
|
Loading…
Reference in New Issue