本文整理汇总了Python中models.Token.send_token_email方法的典型用法代码示例。如果您正苦于以下问题:Python Token.send_token_email方法的具体用法?Python Token.send_token_email怎么用?Python Token.send_token_email使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Token
的用法示例。
在下文中一共展示了Token.send_token_email方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: forward_token
# 需要导入模块: from models import Token [as 别名]
# 或者: from models.Token import send_token_email [as 别名]
def forward_token(request, token_str=None, **kwargs):
kwargs['extra_context'] = {}
error = None
token = get_object_or_404(Token, token=token_str)
user_tokens = get_tokens_from_cookie(request)
if not token.can_forward:
error = _("Apologies! This token can not be forwarded.")
else:
if request.user.is_staff:
pass
elif not token.token in user_tokens:
error = _("Apologies! You are not allowed to forward this token.")
kwargs['extra_context']['token'] = token
kwargs['extra_context']['error'] = error
if not error:
if request.method == 'POST':
form = ForwardProtectedURLForm(token, request.POST)
if form.is_valid():
if token.forward_count:
token.forward_count = token.forward_count - len(form.cleaned_data['emails'])
token.save()
for email in form.cleaned_data['emails']:
forwarded_token = Token( url=token.url, valid_until=token.valid_until, forward_count=0, email=email )
forwarded_token.save()
forwarded_token.send_token_email()
return HttpResponseRedirect(reverse('token_list'))
else:
form = ForwardProtectedURLForm(token)
kwargs['extra_context']['form'] = form
return direct_to_template(request, template='token_auth/forward_token.html', **kwargs)