From ea518c13a6294aaaa22d29404d0a01e4b436dcfe Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 11 Oct 2011 10:41:08 +0000 Subject: [PATCH] sort events --- pandora/event/models.py | 15 +++++++++++++-- pandora/event/views.py | 9 ++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/pandora/event/models.py b/pandora/event/models.py index 29b58ea5..75a33a68 100644 --- a/pandora/event/models.py +++ b/pandora/event/models.py @@ -10,7 +10,9 @@ import ox from ox.django import fields from annotation.models import Annotation -from item.models import Item +from item.models import Item, canonicalTitle +from item import utils +from person.models import get_name_sort import managers @@ -82,9 +84,18 @@ class Event(models.Model): self.items.add(i) self.save() + def set_name_sort(self, value=None): + if not value: + value = self.name + if self.type == 'person': + value = get_name_sort(value) + else: + value = utils.sort_title(canonicalTitle(value)) + self.name_sort = utils.sort_string(value) + def save(self, *args, **kwargs): if not self.name_sort: - self.name_sort = self.name + self.set_name_sort() self.name_find = '||' + self.name + '||'.join(self.alternativeNames) + '||' self.durationTime = self.endTime - self.startTime super(Event, self).save(*args, **kwargs) diff --git a/pandora/event/views.py b/pandora/event/views.py index e0f28b8d..d7fbd489 100644 --- a/pandora/event/views.py +++ b/pandora/event/views.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 from __future__ import division -import unicodedata import ox from ox.utils import json @@ -42,7 +41,7 @@ def addEvent(request): value = tuple(value) setattr(event, key, value) if 'nameSort' in data: - event.name_sort = unicodedata.normalize('NFKD', data['nameSort']) + event.set_name_sort(data['nameSort']) event.save() tasks.update_matches.delay(event.id) response = json_response(status=200, text='created') @@ -76,8 +75,8 @@ def editEvent(request): conflict = True conflict_names.append(name) if not conflict: - if 'name' in data and event.name_sort == unicodedata.normalize('NFKD', event.name): - event.name_sort = unicodedata.normalize('NFKD', data['name']) + if 'name' in data: + event.set_name_sort(data['name']) for key in ('name', 'start', 'startTime', 'end', 'endTime', 'duration', 'durationTime', 'type', 'alternativeNames'): if key in data: @@ -86,7 +85,7 @@ def editEvent(request): value = tuple(value) setattr(event, key, value) if 'nameSort' in data: - event.name_sort = unicodedata.normalize('NFKD', data['nameSort']) + event.set_name_sort(data['nameSort']) event.save() tasks.update_matches.delay(event.id) response = json_response(status=200, text='updated')