本文整理汇总了Python中accounts.models.User.import_user方法的典型用法代码示例。如果您正苦于以下问题:Python User.import_user方法的具体用法?Python User.import_user怎么用?Python User.import_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类accounts.models.User
的用法示例。
在下文中一共展示了User.import_user方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_user
# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import import_user [as 别名]
def import_user(request):
""" View in the admin """
if request.method == 'POST':
form = ImportForm(request.POST, request.FILES)
if form.is_valid():
try:
imported_user = User.import_user(form.files['file'])
request.user.message_set.create(message="The import was successfull. %i users imported." % imported_user.count())
if form.cleaned_data['require_reactivation']:
for user in [user for user in imported_user if user.is_active]:
user.is_active = False
user.set_new_activation_key()
user.save()
if form.cleaned_data['send_reactivation_email']:
# Send activation email
t = Template(form.cleaned_data['meassagetext'])
c = {
'email': user.email,
'domain': RequestSite(request).domain,
'site_name': settings.SITE_NAME,
'uid': int_to_base36(user.id),
'user': user,
'protocol': request.is_secure() and 'https' or 'http',
'activation_key': user.activation_key,
'expiration_days': get_settings().acount_activation_days,
}
send_mail(_("Account activation on %s") % settings.SITE_NAME, t.render(Context(c)), None, [user.email])
return HttpResponseRedirect(urlresolvers.reverse('admin:accounts_user_changelist'))
except:
raise
from django.forms.util import ErrorList
msg = "An Error occured. The import file was propably malformed."
form._errors["file"] = ErrorList([msg])
else:
form = ImportForm()
return render_to_response('admin/accounts/user/import.html', {'form': form, 'title':"Import User" }, RequestContext(request))