Adding a bit more info to recluster_singletons but now requires a max parameter
Also adding __unicode__ method to Identifierpull/1/head
parent
4a7f82d513
commit
3a2cece7dd
|
@ -7,18 +7,31 @@ This script goes through all singleton works and attempts to add_related. 'xx' w
|
|||
from django.core.management.base import BaseCommand
|
||||
from django.db.models import Count
|
||||
from regluit.core import models, bookloader
|
||||
from itertools import islice
|
||||
|
||||
class Command(BaseCommand):
|
||||
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())
|
||||
|
||||
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
|
||||
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:
|
||||
print
|
||||
continue
|
||||
new_editions = bookloader.add_related( work.first_isbn_13() )
|
||||
print "clustered %s editions for work %s" % (len(new_editions),work )
|
||||
if 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 : ", [(w.id, w.language, w.editions.count()) for w in set([ed.work for ed in new_editions])]
|
||||
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() )
|
||||
|
|
|
@ -227,6 +227,9 @@ class Identifier(models.Model):
|
|||
i=Identifier(type=type, value=value, edition=edition, work=work)
|
||||
i.save()
|
||||
return i
|
||||
|
||||
def __unicode__(self):
|
||||
return u'{0}:{1}'.format(self.type, self.value)
|
||||
|
||||
class Work(models.Model):
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
|
|
Loading…
Reference in New Issue