summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-09-12 15:44:56 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-09-12 15:44:56 +0200
commit548d6f5cdf01ac205db4bb96148bde1832b4f75f (patch)
tree5b31facf87206255bdaf7cedf1078c523388068c
parentbf0f3075a1771a70fd270ad3df622167171dc103 (diff)
downloadIshtar-548d6f5cdf01ac205db4bb96148bde1832b4f75f.tar.bz2
Ishtar-548d6f5cdf01ac205db4bb96148bde1832b4f75f.zip
Migrate to UUID: warehoue, containers, person, organization
-rw-r--r--archaeological_warehouse/migrations/0041_auto_20190912_1518.py43
-rw-r--r--archaeological_warehouse/models.py25
-rw-r--r--ishtar_common/migrations/0110_auto_20190912_1517.py65
-rw-r--r--ishtar_common/models.py50
4 files changed, 131 insertions, 52 deletions
diff --git a/archaeological_warehouse/migrations/0041_auto_20190912_1518.py b/archaeological_warehouse/migrations/0041_auto_20190912_1518.py
new file mode 100644
index 000000000..f1158d9b1
--- /dev/null
+++ b/archaeological_warehouse/migrations/0041_auto_20190912_1518.py
@@ -0,0 +1,43 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.18 on 2019-09-12 15:18
+from __future__ import unicode_literals
+
+import uuid
+
+from django.db import migrations, models
+
+from ishtar_common.utils_migrations import set_uuid_helper
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('archaeological_warehouse', '0040_auto_20190910_1324'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='container',
+ name='uuid',
+ field=models.UUIDField(blank=True, null=True),
+ ),
+ migrations.AddField(
+ model_name='warehouse',
+ name='uuid',
+ field=models.UUIDField(blank=True, null=True),
+ ),
+ migrations.RunPython(set_uuid_helper('archaeological_warehouse',
+ 'Container')),
+ migrations.RunPython(set_uuid_helper('archaeological_warehouse',
+ 'Warehouse')),
+ migrations.AlterField(
+ model_name='container',
+ name='uuid',
+ field=models.UUIDField(default=uuid.uuid4),
+ ),
+ migrations.AlterField(
+ model_name='warehouse',
+ name='uuid',
+ field=models.UUIDField(default=uuid.uuid4),
+ ),
+ ]
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py
index 96257da3c..f3fd5c3aa 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -18,6 +18,7 @@
# See the file COPYING for details.
import datetime
+import uuid
from django.conf import settings
from django.contrib.gis.db import models
@@ -28,7 +29,7 @@ from django.template.defaultfilters import slugify
from django.utils.translation import ugettext_lazy as _, pgettext_lazy
from ishtar_common.data_importer import post_importer_action
-from ishtar_common.model_managers import ExternalIdManager
+from ishtar_common.model_managers import ExternalIdManager, UUIDModelManager
from ishtar_common.models import Document, GeneralType, get_external_id, \
LightHistorizedItem, OwnPerms, Address, Person, post_save_cache, \
DashboardFormItem, ShortMenuItem, Organization, OrganizationType, \
@@ -93,8 +94,9 @@ class Warehouse(Address, DocumentItem, GeoItem, QRCodeItem, DashboardFormItem,
)
QUICK_ACTIONS = [QA_LOCK]
- objects = ExternalIdManager()
+ objects = UUIDModelManager()
+ uuid = models.UUIDField(default=uuid.uuid4)
name = models.CharField(_(u"Name"), max_length=200)
warehouse_type = models.ForeignKey(WarehouseType,
verbose_name=_(u"Warehouse type"))
@@ -136,7 +138,7 @@ class Warehouse(Address, DocumentItem, GeoItem, QRCodeItem, DashboardFormItem,
return self.name
def natural_key(self):
- return (self.external_id, )
+ return (self.uuid, )
def _get_base_image_path(self):
return u"{}/{}".format(self.SLUG, self.external_id)
@@ -375,7 +377,7 @@ post_delete.connect(post_save_cache, sender=WarehouseDivision)
class WarehouseDivisionLinkManager(models.Manager):
def get_by_natural_key(self, warehouse, division):
- return self.get(warehouse__external_id=warehouse,
+ return self.get(warehouse__uuid=warehouse,
division__txt_idx=division)
@@ -396,7 +398,7 @@ class WarehouseDivisionLink(models.Model):
return u"{} - {}".format(self.warehouse, self.division)
def natural_key(self):
- return self.warehouse.external_id, self.division.txt_idx
+ return self.warehouse.uuid, self.division.txt_idx
class ContainerType(GeneralType):
@@ -592,9 +594,10 @@ class Container(DocumentItem, LightHistorizedItem, QRCodeItem, GeoItem,
)
QUICK_ACTIONS = [QA_LOCK]
- objects = ExternalIdManager()
+ objects = UUIDModelManager()
# fields
+ uuid = models.UUIDField(default=uuid.uuid4)
location = models.ForeignKey(
Warehouse, verbose_name=_(u"Location (warehouse)"),
related_name='containers')
@@ -641,7 +644,7 @@ class Container(DocumentItem, LightHistorizedItem, QRCodeItem, GeoItem,
return self.cached_label or ""
def natural_key(self):
- return (self.external_id, )
+ return (self.uuid, )
def _generate_cached_label(self):
items = [self.reference, self.precise_location]
@@ -894,9 +897,9 @@ m2m_changed.connect(document_attached_changed,
class ContainerLocalisationManager(models.Manager):
def get_by_natural_key(self, container, warehouse, division):
- return self.get(container__external_id=container,
- division__warehouse__external_id=warehouse,
- division__division__txt_idx = division)
+ return self.get(container__uuid=container,
+ division__warehouse__uuid=warehouse,
+ division__division__txt_idx=division)
class ContainerLocalisation(models.Model):
@@ -919,7 +922,7 @@ class ContainerLocalisation(models.Model):
return lbl
def natural_key(self):
- return self.container.external_id, self.division.warehouse.external_id,\
+ return self.container.uuid, self.division.warehouse.uuid,\
self.division.division.txt_idx
def save(self, *args, **kwargs):
diff --git a/ishtar_common/migrations/0110_auto_20190912_1517.py b/ishtar_common/migrations/0110_auto_20190912_1517.py
new file mode 100644
index 000000000..f842643e7
--- /dev/null
+++ b/ishtar_common/migrations/0110_auto_20190912_1517.py
@@ -0,0 +1,65 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.18 on 2019-09-12 15:17
+from __future__ import unicode_literals
+
+import uuid
+
+from django.db import migrations, models
+
+from ishtar_common.utils_migrations import set_uuid_helper
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('ishtar_common', '0109_auto_20190911_1256'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='historicalorganization',
+ name='uuid',
+ field=models.UUIDField(default=uuid.uuid4),
+ ),
+ migrations.AddField(
+ model_name='historicalperson',
+ name='uuid',
+ field=models.UUIDField(default=uuid.uuid4),
+ ),
+ migrations.AddField(
+ model_name='organization',
+ name='uuid',
+ field=models.UUIDField(blank=True, null=True),
+ ),
+ migrations.AddField(
+ model_name='person',
+ name='uuid',
+ field=models.UUIDField(blank=True, null=True),
+ ),
+ migrations.AddField(
+ model_name='author',
+ name='uuid',
+ field=models.UUIDField(blank=True, null=True),
+ ),
+ migrations.RunPython(set_uuid_helper('ishtar_common',
+ 'Person')),
+ migrations.RunPython(set_uuid_helper('ishtar_common',
+ 'Organization')),
+ migrations.RunPython(set_uuid_helper('ishtar_common',
+ 'Author')),
+ migrations.AlterField(
+ model_name='organization',
+ name='uuid',
+ field=models.UUIDField(default=uuid.uuid4),
+ ),
+ migrations.AlterField(
+ model_name='person',
+ name='uuid',
+ field=models.UUIDField(default=uuid.uuid4),
+ ),
+ migrations.AlterField(
+ model_name='author',
+ name='uuid',
+ field=models.UUIDField(default=uuid.uuid4),
+ ),
+ ]
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index ef9a59937..b750ee613 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -4012,11 +4012,6 @@ organization_type_pk_lazy = lazy(OrganizationType.get_or_create_pk, str)
organization_type_pks_lazy = lazy(OrganizationType.get_or_create_pks, str)
-class OrganizationManager(models.Manager):
- def get_by_natural_key(self, name, organization_type):
- return self.get(name=name, organization_type__txt_idx=organization_type)
-
-
class Organization(Address, Merge, OwnPerms, ValueGetter):
TABLE_COLS = ('name', 'organization_type', 'town')
SLUG = "organization"
@@ -4039,9 +4034,10 @@ class Organization(Address, Merge, OwnPerms, ValueGetter):
),
}
- objects = OrganizationManager()
+ objects = UUIDModelManager()
# fields
+ uuid = models.UUIDField(default=uuid.uuid4)
name = models.CharField(_("Name"), max_length=500)
organization_type = models.ForeignKey(OrganizationType,
verbose_name=_("Type"))
@@ -4067,7 +4063,7 @@ class Organization(Address, Merge, OwnPerms, ValueGetter):
self.town or "")
def natural_key(self):
- return (self.name, self.organization_type.txt_idx)
+ return (self.uuid,)
def __str__(self):
return self.cached_label or ""
@@ -4127,19 +4123,6 @@ post_save.connect(post_save_cache, sender=TitleType)
post_delete.connect(post_save_cache, sender=TitleType)
-class PersonManager(models.Manager):
- def get_by_natural_key(
- self, name, surname, attached_to_name,
- attached_to_organization_type):
- q = {"name": name, "surname": surname}
- if attached_to_name:
- q['attached_to__name'] = attached_to_name
- if attached_to_organization_type:
- q['attached_to__organization_type__txt_idx'] = \
- attached_to_organization_type
- return self.get(**q)
-
-
class Person(Address, Merge, OwnPerms, ValueGetter, MainItem):
SLUG = "person"
_prefix = 'person_'
@@ -4209,9 +4192,10 @@ class Person(Address, Merge, OwnPerms, ValueGetter, MainItem):
QA_EDIT
]
- objects = PersonManager()
+ objects = UUIDModelManager()
# fields
+ uuid = models.UUIDField(default=uuid.uuid4)
old_title = models.CharField(_("Title"), max_length=100, choices=TYPE,
blank=True, null=True)
title = models.ForeignKey(TitleType, verbose_name=_("Title"),
@@ -4248,10 +4232,7 @@ class Person(Address, Merge, OwnPerms, ValueGetter, MainItem):
)
def natural_key(self):
- if not self.attached_to:
- return (self.name, self.surname, '', '')
- return (self.name, self.surname, self.attached_to.name,
- self.attached_to.organization_type.txt_idx)
+ return (self.uuid,)
@property
def full_title(self):
@@ -4822,30 +4803,17 @@ post_save.connect(post_save_cache, sender=AuthorType)
post_delete.connect(post_save_cache, sender=AuthorType)
-class AuthorManager(models.Manager):
- def get_by_natural_key(
- self, name, surname, attached_to_name,
- attached_to_organization_type, author_type):
- q = {"person__name": name, "person__surname": surname,
- "author_type__txt_idx": author_type}
- if attached_to_name:
- q['person__attached_to__name'] = attached_to_name
- if attached_to_organization_type:
- q['person__attached_to__organization_type__txt_idx'] = \
- attached_to_organization_type
- return self.get(**q)
-
-
class Author(FullSearch):
PARENT_SEARCH_VECTORS = ['person']
SLUG = "author"
+ uuid = models.UUIDField(default=uuid.uuid4)
person = models.ForeignKey(Person, verbose_name=_("Person"),
related_name='author')
author_type = models.ForeignKey(AuthorType, verbose_name=_("Author type"))
cached_label = models.TextField(_("Cached name"), null=True, blank=True,
db_index=True)
- objects = AuthorManager()
+ objects = UUIDModelManager()
class Meta:
verbose_name = _("Author")
@@ -4863,7 +4831,7 @@ class Author(FullSearch):
return self.cached_label or ""
def natural_key(self):
- return self.person.natural_key() + (self.author_type.txt_idx,)
+ return self.uuid,
def _generate_cached_label(self):
return str(self.person) + settings.JOINT + \