From 29415b4ad6a6cce10c79bebf3d2c4c7d0370ee97 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Fri, 4 Mar 2016 16:18:26 +0000 Subject: [PATCH] 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. --- .../entity/migrations/0002_auto_20160304_1641.py | 21 +++++++++++++++++++++ pandora/entity/models.py | 4 ++-- pandora/event/migrations/0003_auto_20160304_1644.py | 21 +++++++++++++++++++++ pandora/event/models.py | 8 ++++---- pandora/place/migrations/0002_auto_20160304_1644.py | 21 +++++++++++++++++++++ pandora/place/models.py | 2 +- 6 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 pandora/entity/migrations/0002_auto_20160304_1641.py create mode 100644 pandora/event/migrations/0003_auto_20160304_1644.py create mode 100644 pandora/place/migrations/0002_auto_20160304_1644.py diff --git a/pandora/entity/migrations/0002_auto_20160304_1641.py b/pandora/entity/migrations/0002_auto_20160304_1641.py new file mode 100644 index 0000000..b2556b1 --- /dev/null +++ b/pandora/entity/migrations/0002_auto_20160304_1641.py @@ -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=()), + ), + ] diff --git a/pandora/entity/models.py b/pandora/entity/models.py index 0b91261..aa1c86f 100644 --- a/pandora/entity/models.py +++ b/pandora/entity/models.py @@ -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) @@ -206,7 +206,7 @@ class Entity(models.Model): ids.append(key['id']) save('name', u'\n'.join([self.name] + list(self.alternativeNames))) self.find.exclude(key__in=ids).delete() - + def update_matches(self): import annotation.models import item.models diff --git a/pandora/event/migrations/0003_auto_20160304_1644.py b/pandora/event/migrations/0003_auto_20160304_1644.py new file mode 100644 index 0000000..ecf5c2d --- /dev/null +++ b/pandora/event/migrations/0003_auto_20160304_1644.py @@ -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=()), + ), + ] diff --git a/pandora/event/models.py b/pandora/event/models.py index 81a528e..f490279 100644 --- a/pandora/event/models.py +++ b/pandora/event/models.py @@ -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: diff --git a/pandora/place/migrations/0002_auto_20160304_1644.py b/pandora/place/migrations/0002_auto_20160304_1644.py new file mode 100644 index 0000000..d3c4cf4 --- /dev/null +++ b/pandora/place/migrations/0002_auto_20160304_1644.py @@ -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=()), + ), + ] diff --git a/pandora/place/models.py b/pandora/place/models.py index 981442e..9e0024e 100644 --- a/pandora/place/models.py +++ b/pandora/place/models.py @@ -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) -- 2.5.0