From 0c98cd080e280899d44d42b7ab5c6c86f188622b 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. --- .../migrations/0002_auto_20160304_1641.py | 21 +++++++++++++++++++ pandora/entity/models.py | 2 +- .../migrations/0003_auto_20160304_1644.py | 21 +++++++++++++++++++ pandora/event/models.py | 8 +++---- .../migrations/0002_auto_20160304_1644.py | 21 +++++++++++++++++++ pandora/place/models.py | 2 +- 6 files changed, 69 insertions(+), 6 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 00000000..b2556b18 --- /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 9b5eb20f..ff197835 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) 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 00000000..ecf5c2d4 --- /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 81a528e6..f4902794 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 00000000..d3c4cf4d --- /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 981442ee..9e0024e7 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)