Entity.alternativeNames: default to () not [] (fixes #2896)

Otherwise this:

    self.name_find = '||' + '||'.join((self.name,) + self.alternativeNames) + '||'
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

fails because () + [] is an error. I guess this must have been
introduced by the DictField/TupleField rewrite.

Without this fix, it is impossible to create a new entity.

Basically the same logic is used for Event and Place too so I've made
the same change to those, and, in passing, fix another copy of the bug
fixed for Entity.name_find in fe7f961.
This commit is contained in:
Will Thompson 2016-03-04 16:18:26 +00:00
parent 9a4c24cdb4
commit 0c98cd080e
6 changed files with 69 additions and 6 deletions

View file

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.2 on 2016-03-04 16:41
from __future__ import unicode_literals
from django.db import migrations
import oxdjango.fields
class Migration(migrations.Migration):
dependencies = [
('entity', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='entity',
name='alternativeNames',
field=oxdjango.fields.TupleField(default=()),
),
]

View file

@ -35,7 +35,7 @@ class Entity(models.Model):
type = models.CharField(max_length=255)
name = models.CharField(max_length=255)
alternativeNames = fields.TupleField(default=[])
alternativeNames = fields.TupleField(default=())
data = fields.DictField(default={}, editable=False)
matches = models.IntegerField(default=0)

View file

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.2 on 2016-03-04 16:44
from __future__ import unicode_literals
from django.db import migrations
import oxdjango.fields
class Migration(migrations.Migration):
dependencies = [
('event', '0002_auto_20160219_1537'),
]
operations = [
migrations.AlterField(
model_name='event',
name='alternativeNames',
field=oxdjango.fields.TupleField(default=()),
),
]

View file

@ -36,14 +36,14 @@ class Event(models.Model):
name_find = models.TextField(default='', editable=True)
wikipediaId = models.CharField(max_length=1000, blank=True)
alternativeNames = fields.TupleField(default=[])
alternativeNames = fields.TupleField(default=())
objects = managers.EventManager()
#start yyyy-mm-dd|mm-dd|dow 00:00|00:00
start = models.CharField(default='', max_length=255)
startTime = models.BigIntegerField(default=None, null=True)
#end yyyy-mm-dd|mm-dd|dow 00:00|00:01
end = models.CharField(default='', max_length=255)
endTime = models.BigIntegerField(default=None, null=True)
@ -77,7 +77,7 @@ class Event(models.Model):
user.profile.capability('canEditEvents')):
return True
return False
def get_matches(self, qs=None):
return get_matches(self, Event, 'event', qs)
@ -130,7 +130,7 @@ class Event(models.Model):
def save(self, *args, **kwargs):
if not self.name_sort:
self.set_name_sort()
self.name_find = '||' + self.name + '||'.join(self.alternativeNames) + '||'
self.name_find = '||' + '||'.join((self.name,) + self.alternativeNames) + '||'
self.defined = len(filter(None, [getattr(self, key)
for key in ('start', 'end')])) > 0
if self.endTime and self.startTime:

View file

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.2 on 2016-03-04 16:44
from __future__ import unicode_literals
from django.db import migrations
import oxdjango.fields
class Migration(migrations.Migration):
dependencies = [
('place', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='place',
name='alternativeNames',
field=oxdjango.fields.TupleField(default=()),
),
]

View file

@ -23,7 +23,7 @@ class Place(models.Model):
user = models.ForeignKey(User, null=True, related_name='places')
name = models.CharField(max_length=1024)
alternativeNames = fields.TupleField(default=[])
alternativeNames = fields.TupleField(default=())
name_sort = models.CharField(max_length=200, db_index=True)
name_find = models.TextField(default='', editable=False)