diff options
Diffstat (limited to 'ishtar_common')
| -rw-r--r-- | ishtar_common/forms_common.py | 9 | ||||
| -rw-r--r-- | ishtar_common/models.py | 19 | 
2 files changed, 27 insertions, 1 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index dd55f95b4..486d25fcf 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -1425,6 +1425,15 @@ class AuthorForm(ManageOldType, NewItemForm):              initial=self.init_data.get('author_type'))          self.limit_fields() +    def clean(self): +        person_id = self.cleaned_data.get("person", None) +        author_type_id = self.cleaned_data.get("author_type", None) +        if not person_id or not author_type_id: +            return self.cleaned_data +        if models.Author.objects.filter(author_type_id=author_type_id, +                                        person_id=person_id).count(): +            raise forms.ValidationError(_("This author already exist.")) +      def save(self, user):          dct = self.cleaned_data          dct['author_type'] = models.AuthorType.objects.get( diff --git a/ishtar_common/models.py b/ishtar_common/models.py index b750ee613..b3956e2f1 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -4853,8 +4853,25 @@ class Author(FullSearch):              "person": str(self.person)          } +    def merge(self, item, keep_old=False): +        merge_model_objects(self, item, keep_old=keep_old) + + +def author_post_save(sender, **kwargs): +    if not kwargs.get('instance'): +        return +    cached_label_changed(sender, **kwargs) +    instance = kwargs.get('instance') +    q = Author.objects.filter(person=instance.person, +                              author_type=instance.author_type) +    if q.count() <= 1: +        return +    authors = list(q.all()) +    for author in authors[1:]: +        authors[0].merge(author) + -post_save.connect(cached_label_changed, sender=Author) +post_save.connect(author_post_save, sender=Author)  class SourceType(HierarchicalType):  | 
