本文整理汇总了Python中pytas.http.TASClient.countries方法的典型用法代码示例。如果您正苦于以下问题:Python TASClient.countries方法的具体用法?Python TASClient.countries怎么用?Python TASClient.countries使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pytas.http.TASClient
的用法示例。
在下文中一共展示了TASClient.countries方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_country_choices
# 需要导入模块: from pytas.http import TASClient [as 别名]
# 或者: from pytas.http.TASClient import countries [as 别名]
def get_country_choices():
tas = TASClient()
countries_list = tas.countries()
return (('', 'Choose one'),) + tuple((c['id'], c['name']) for c in countries_list)
示例2: nees_migration
# 需要导入模块: from pytas.http import TASClient [as 别名]
# 或者: from pytas.http.TASClient import countries [as 别名]
def nees_migration(request, step=None):
if step == 0 or step is None:
return render(request, 'designsafe/apps/accounts/nees_migration.html',
{'form': forms.NEESAccountMigrationForm()})
elif step == '1':
if request.method == 'POST':
email_address = request.POST.get('email_address')
else:
email_address = request.GET.get('email_address')
if email_address:
nees_user_match = NEESUser.lookup_user(email_address)
if len(nees_user_match) == 0:
messages.error(request,
'We were unable to locate a NEEShub account for the email '
'address <b>%s</b>. Please confirm that you entered the '
'email address correctly and try again. If you feel this '
'is in error, please submit a support ticket.' %
email_address)
return HttpResponseRedirect(reverse('designsafe_accounts:nees_migration'))
else:
tas_by_username = None
tas_by_email = None
# check for existing TAS user
tas_api = TASClient()
try:
tas_by_username = tas_api.get_user(username=nees_user_match[0].username)
except:
logger.exception('Error checking for existing TAS users')
try:
tas_by_email = tas_api.get_user(email=nees_user_match[0].email)
except:
logger.exception('Error checking for existing TAS users')
context = {
'email_address': email_address,
'nees_user_match': nees_user_match,
'tas_by_username': tas_by_username,
'tas_by_email': tas_by_email,
}
return render(request,
'designsafe/apps/accounts/nees_migration_step_1.html',
context)
elif step == '2':
tas_api = TASClient()
if request.method == 'POST':
email_address = request.POST.get('email_address')
nees_user_match = NEESUser.lookup_user(email_address)
countries = tas_api.countries()
country_residence = next((c for c in countries if c['abbrev'] == nees_user_match[0].countryresident), {'id':None})
country_origin = next((c for c in countries if c['abbrev'] == nees_user_match[0].countryorigin), {'id':None})
initial_data = {
'firstName': nees_user_match[0].givenName,
'lastName': nees_user_match[0].surname,
'email': nees_user_match[0].email,
'phone': nees_user_match[0].phone,
'countryId': country_residence['id'],
'citizenshipId': country_origin['id'],
'username': nees_user_match[0].username,
}
if nees_user_match[0].organization is not None:
initial_data['institutionId'] = -1
initial_data['institution'] = nees_user_match[0].organization
form = forms.UserRegistrationForm(initial=initial_data)
return render(request,
'designsafe/apps/accounts/nees_migration_step_2.html',
{'form': form})
elif step == '3':
# final step!
tas_api = TASClient()
if request.method == 'POST':
form = forms.UserRegistrationForm(request.POST)
if form.is_valid():
# attempt TAS User creation
try:
form.save()
messages.success(
request,
'Congratulations! Your account migration was successful. You '
'still need you to activate your TACC account. You should an '
'activation code at the email address provided. Please follow '
'the instructions in the email to activate your account.'
)
return HttpResponseRedirect('/')
except Exception as e:
logger.exception('Error saving user!')
logger.info('error: {}'.format(e))
error_type = e.args[1] if len(e.args) > 1 else ''
if 'DuplicateLoginException' in error_type:
err_msg = (
'The username you chose has already been taken. Please '
'choose another. If you already have an account with TACC, '
'please log in using those credentials.')
form._errors.setdefault('username', [err_msg])
elif 'DuplicateEmailException' in error_type:
#.........这里部分代码省略.........