Skip to content
Draft
Show file tree
Hide file tree
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
12 changes: 5 additions & 7 deletions ojs/importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from django.utils.html import strip_tags
from django.utils.safestring import mark_safe
from django.template.defaultfilters import linebreaksbr
from django_countries import countries

from core import models as core_models, files as core_files
from copyediting import models as copyediting_models
Expand Down Expand Up @@ -1128,15 +1129,12 @@ def get_or_create_account(data, update=False):
account.biography = data.get('bio')
account.orcid = extract_orcid(data.get("orcid"))


# Assign a country if the code is recognised in ISO-3166-1
if data.get('country'):
try:
country = core_models.Country.objects.get(
code=data.get('country'))
account.country = country
valid_alpha2 = countries.alpha2(data.get('country'))
if valid_alpha2:
account.country = valid_alpha2
account.save()
except core_models.Country.DoesNotExist:
pass

account.save()
return account, created
Expand Down
7 changes: 4 additions & 3 deletions ojs/ojs3_importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.template.defaultfilters import linebreaksbr
from django.utils import timezone
from django.utils.html import strip_tags
from django_countries import countries

from cms import models as cms_models
from copyediting import models as copyediting_models
Expand Down Expand Up @@ -653,10 +654,10 @@ def import_user(user_dict, journal):
account.orcid = orcid
if user_dict["disabled"] is True:
account.active = False
# Assign a country if the code is recognised in ISO-3166-1
if user_dict["country"]:
account.country = core_models.Country.objects.filter(
name=user_dict["country"]
).first()
valid_alpha2 = countries.alpha2(user_dict['country'])
account.country = valid_alpha2

import_user_roles(user_dict, account, journal)
for interest in user_dict["interests"]:
Expand Down
10 changes: 5 additions & 5 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from django.template.defaultfilters import linebreaksbr
from django.utils.dateparse import parse_datetime, parse_date
from django.utils.timezone import is_aware, make_aware, now
from django_countries import countries

from core import models as core_models, files, logic as core_logic, workflow, plugin_loader
from identifiers import models as id_models
Expand Down Expand Up @@ -162,11 +163,10 @@ def import_editors(request, reader):
if not user.is_editor(request):
user.add_account_role('editor', request.journal)


def import_user(request, row, reset_pwd=False):
try:
country = core_models.Country.objects.get(code=row[7])
except core_models.Country.DoesNotExist:
country = None
# Validate country code against ISO-3166-1
valid_country_code = countries.alpha2(row[7])
user, created = core_models.Account.objects.update_or_create(
email=row[4],
defaults={
Expand All @@ -176,7 +176,7 @@ def import_user(request, row, reset_pwd=False):
'last_name': row[3],
'department': row[5],
'institution': row[6],
'country': country,
'country': valid_country_code,
}
)
if created and reset_pwd:
Expand Down