Skip to content

Commit

Permalink
Duplicate finder finds dupes by title and container now
Browse files Browse the repository at this point in the history
  • Loading branch information
cpritcha committed Oct 11, 2019
1 parent 9cc92b7 commit b7db563
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion citation/bibtex/entry/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def process(entry: Dict, creator: User, duplicate_pk=None):
detached_authors, unassigned_emails = create_detached_authors(entry)
detached_raw = create_detached_raw(entry)

duplicate_publications = detached_publication.duplicates()
duplicate_publications = detached_publication.duplicates(container=detached_container)
publication_already_in_db = len(duplicate_publications) > 0

audit_command = models.AuditCommand(creator=creator, action=models.AuditCommand.Action.MERGE)
Expand Down
22 changes: 15 additions & 7 deletions citation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,15 +829,23 @@ class Publication(AbstractLogModel):
objects = LogManager.from_queryset(LogQuerySet)()
api = PublicationQuerySet.as_manager()

def duplicates(self, query=None, **kwargs):
def duplicates(self, query=None, container=None, **kwargs):
criteria = (Q(isi=self.isi) & Q(isi__isnull=False)) | \
(Q(doi=self.doi) & Q(doi__isnull=False))
container = getattr(self, 'container', container)
if container is not None:
if container.id is not None:
criteria |= (Q(container_id=container.id) &
Q(title__iexact=self.title) &
~Q(title=''))
elif container.issn:
criteria |= (Q(container__issn=container.issn) &
Q(title__iexact=self.title) &
~Q(title=''))

if query is None:
query = Publication.objects \
.filter((Q(isi=self.isi) & Q(isi__isnull=False)) |
(Q(doi=self.doi) & Q(doi__isnull=False)) |
(Q(date_published_text__iexact=self.date_published_text) &
~Q(date_published_text='') &
Q(title__iexact=self.title) &
~Q(title=''))) \
.filter(criteria) \
.exclude(id=self.id)

return query.filter(**kwargs)
Expand Down

0 comments on commit b7db563

Please sign in to comment.