本文整理匯總了Python中corehq.apps.users.models.Invitation.save方法的典型用法代碼示例。如果您正苦於以下問題:Python Invitation.save方法的具體用法?Python Invitation.save怎麽用?Python Invitation.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類corehq.apps.users.models.Invitation
的用法示例。
在下文中一共展示了Invitation.save方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: invite_web_user
# 需要導入模塊: from corehq.apps.users.models import Invitation [as 別名]
# 或者: from corehq.apps.users.models.Invitation import save [as 別名]
def invite_web_user(request, domain, template="users/invite_web_user.html"):
role_choices = UserRole.role_choices(domain)
if request.method == "POST":
form = AdminInvitesUserForm(request.POST,
excluded_emails=[user.username for user in WebUser.by_domain(domain)],
role_choices=role_choices
)
if form.is_valid():
data = form.cleaned_data
# create invitation record
data["invited_by"] = request.couch_user.user_id
data["invited_on"] = datetime.utcnow()
data["domain"] = domain
invite = Invitation(**data)
invite.save()
invite.send_activation_email()
messages.success(request, "Invitation sent to %s" % invite.email)
return HttpResponseRedirect(reverse("web_users", args=[domain]))
else:
form = AdminInvitesUserForm(role_choices=role_choices)
context = _users_context(request, domain)
context.update(
registration_form=form
)
return render_to_response(request, template, context)
示例2: setUpClass
# 需要導入模塊: from corehq.apps.users.models import Invitation [as 別名]
# 或者: from corehq.apps.users.models.Invitation import save [as 別名]
def setUpClass(cls):
cls.invitations = []
for kwargs in [
{'domain': 'domain_1', 'email': '[email protected]'},
{'domain': 'domain_1', 'email': '[email protected]', 'is_accepted': True},
{'domain': 'domain_2', 'email': '[email protected]'},
]:
inv = Invitation(**kwargs)
inv.save()
cls.invitations.append(inv)