Example #1
0
 def prepare_text(self, data):
     document = u' '.join([
         normalize(self.prepare_title(data)),
         normalize(data['description']),
         normalize(data['abstract'])
     ] + [a['acrelation__authority__name'] for a in data['acrelations']
          if a['acrelation__authority__name']])  # Exclude blank names.
     return document
Example #2
0
    def prepare_title_for_sort(self, data):
        """
        We want to ignore non-ASCII characters when sorting, and group reviews
        together with the works that they review.
        """
        if data['type_controlled'] != Citation.REVIEW:
            if not data['title']:
                return u""
            return normalize(data['title'])

        book = self._get_reviewed_book(data)
        if book is None:
            return u""
        return normalize(book)
def update_title_for_sort(apps, schema_editor):
    Citation = apps.get_model("isisdata", "Citation")
    CCRelation = apps.get_model("isisdata", "CCRelation")

    def get_title(obj):
        if obj.title:
            return obj.title
        else:
            title_parts = []
            for relation in get_related(obj):
                if relation.type_controlled =='RO' and relation.object and relation.object.title:
                    title_parts.append(relation.object.title)
                if relation.type_controlled == 'RB' and relation.subject and relation.subject.title:
                    title_parts.append(relation.subject.title)
            return u' '.join(title_parts)

    def get_related(obj):
        query = Q(subject_id=obj.id) | Q(object_id=obj.id) & (Q(type_controlled='RO') | Q(type_controlled='RB'))
        return CCRelation.objects.filter(query)

    # If we don't order by ID, the queryset will shift on every inner iteration.
    qs = Citation.objects.all().order_by('id')
    N = qs.count()
    CHUNK = 500
    print 'Migrating %i citations' % N
    for i in xrange(0, N + 1, CHUNK):
        print '\r', i,
        sys.stdout.flush()
        with transaction.atomic():
            # -vv- The database read is here. -vv-
            for citation in qs[i:i+CHUNK]:
                citation.title_for_sort = normalize(unidecode(get_title(citation)))
                citation.save()
def update_name_for_sort(apps, schema_editor):
    Authority = apps.get_model("isisdata", "Authority")

    # If we don't order by ID, the queryset will shift on every inner iteration.
    qs = Authority.objects.all().order_by('id')
    N = qs.count()
    CHUNK = 500
    print 'Migrating %i authority records' % N
    for i in xrange(0, N + 1, CHUNK):
        print '\r', i,
        sys.stdout.flush()
        with transaction.atomic():
            # -vv- The database read is here. -vv-
            for authority in qs[i:i+CHUNK]:
                authority.name_for_sort = normalize(unidecode(authority.name))
                authority.save()
Example #5
0
 def save(self, *args, **kwargs):
     self.name_for_sort = normalize(unidecode(self.name))
     super(DraftAuthority, self).save(*args, **kwargs)