Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions src/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2915,26 +2915,28 @@ def get_or_create_without_ror(
# Or maybe a primary affiliation has already been
# entered without a ROR for this
# account / frozen author / preprint author?
# If there is no `institution`, this method is being used to update
# the department or country in isolation, so we want the primary
# affiliation's org regardless of what its custom label is.
query = models.Q(
controlledaffiliation__is_primary=True,
controlledaffiliation__account=account,
controlledaffiliation__frozen_author=frozen_author,
controlledaffiliation__preprint_author=preprint_author,
ror_id__exact="",
)
try:
# If there is no `institution`, this method is being used to update
# the department or country in isolation, so we want the primary
# affiliation's org regardless of what its custom label is.
query = models.Q(
controlledaffiliation__is_primary=True,
controlledaffiliation__account=account,
controlledaffiliation__frozen_author=frozen_author,
controlledaffiliation__preprint_author=preprint_author,
ror_id__exact="",
)
# If there is an institution name, we should only match organizations
# with that as a custom label.
if institution and institution != " ":
query &= models.Q(custom_label__value=institution)
organization = cls.objects.get(query)
except (cls.DoesNotExist, cls.MultipleObjectsReturned):
except cls.DoesNotExist:
# Otherwise, create a new, disconnected record.
organization = cls.objects.create()
created = True
except cls.MultipleObjectsReturned:
organization = cls.objects.filter(query).first()

# Set custom label if organization is not controlled by ROR
if institution and institution != " " and not organization.ror_id:
Expand Down
Loading