sort events
This commit is contained in:
parent
654a967311
commit
ea518c13a6
2 changed files with 17 additions and 7 deletions
|
@ -10,7 +10,9 @@ import ox
|
||||||
from ox.django import fields
|
from ox.django import fields
|
||||||
|
|
||||||
from annotation.models import Annotation
|
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
|
import managers
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,9 +84,18 @@ class Event(models.Model):
|
||||||
self.items.add(i)
|
self.items.add(i)
|
||||||
self.save()
|
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):
|
def save(self, *args, **kwargs):
|
||||||
if not self.name_sort:
|
if not self.name_sort:
|
||||||
self.name_sort = self.name
|
self.set_name_sort()
|
||||||
self.name_find = '||' + self.name + '||'.join(self.alternativeNames) + '||'
|
self.name_find = '||' + self.name + '||'.join(self.alternativeNames) + '||'
|
||||||
self.durationTime = self.endTime - self.startTime
|
self.durationTime = self.endTime - self.startTime
|
||||||
super(Event, self).save(*args, **kwargs)
|
super(Event, self).save(*args, **kwargs)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
from __future__ import division
|
from __future__ import division
|
||||||
import unicodedata
|
|
||||||
|
|
||||||
import ox
|
import ox
|
||||||
from ox.utils import json
|
from ox.utils import json
|
||||||
|
@ -42,7 +41,7 @@ def addEvent(request):
|
||||||
value = tuple(value)
|
value = tuple(value)
|
||||||
setattr(event, key, value)
|
setattr(event, key, value)
|
||||||
if 'nameSort' in data:
|
if 'nameSort' in data:
|
||||||
event.name_sort = unicodedata.normalize('NFKD', data['nameSort'])
|
event.set_name_sort(data['nameSort'])
|
||||||
event.save()
|
event.save()
|
||||||
tasks.update_matches.delay(event.id)
|
tasks.update_matches.delay(event.id)
|
||||||
response = json_response(status=200, text='created')
|
response = json_response(status=200, text='created')
|
||||||
|
@ -76,8 +75,8 @@ def editEvent(request):
|
||||||
conflict = True
|
conflict = True
|
||||||
conflict_names.append(name)
|
conflict_names.append(name)
|
||||||
if not conflict:
|
if not conflict:
|
||||||
if 'name' in data and event.name_sort == unicodedata.normalize('NFKD', event.name):
|
if 'name' in data:
|
||||||
event.name_sort = unicodedata.normalize('NFKD', data['name'])
|
event.set_name_sort(data['name'])
|
||||||
for key in ('name', 'start', 'startTime', 'end', 'endTime', 'duration', 'durationTime',
|
for key in ('name', 'start', 'startTime', 'end', 'endTime', 'duration', 'durationTime',
|
||||||
'type', 'alternativeNames'):
|
'type', 'alternativeNames'):
|
||||||
if key in data:
|
if key in data:
|
||||||
|
@ -86,7 +85,7 @@ def editEvent(request):
|
||||||
value = tuple(value)
|
value = tuple(value)
|
||||||
setattr(event, key, value)
|
setattr(event, key, value)
|
||||||
if 'nameSort' in data:
|
if 'nameSort' in data:
|
||||||
event.name_sort = unicodedata.normalize('NFKD', data['nameSort'])
|
event.set_name_sort(data['nameSort'])
|
||||||
event.save()
|
event.save()
|
||||||
tasks.update_matches.delay(event.id)
|
tasks.update_matches.delay(event.id)
|
||||||
response = json_response(status=200, text='updated')
|
response = json_response(status=200, text='updated')
|
||||||
|
|
Loading…
Reference in a new issue