diff options
Diffstat (limited to 'ishtar_common/models.py')
| -rw-r--r-- | ishtar_common/models.py | 50 | 
1 files changed, 9 insertions, 41 deletions
| 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 + \ | 
