sort events

This commit is contained in:
j 2011-10-11 10:41:08 +00:00
parent 654a967311
commit ea518c13a6
2 changed files with 17 additions and 7 deletions

View file

@ -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)

View file

@ -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')