本文整理汇总了Python中corehq.apps.users.models.Invitation.get方法的典型用法代码示例。如果您正苦于以下问题:Python Invitation.get方法的具体用法?Python Invitation.get怎么用?Python Invitation.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.users.models.Invitation
的用法示例。
在下文中一共展示了Invitation.get方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reinvite_web_user
# 需要导入模块: from corehq.apps.users.models import Invitation [as 别名]
# 或者: from corehq.apps.users.models.Invitation import get [as 别名]
def reinvite_web_user(request, domain):
invitation_id = request.POST["invite"]
try:
invitation = Invitation.get(invitation_id)
invitation.invited_on = datetime.utcnow()
invitation.save()
invitation.send_activation_email()
return json_response({"response": _("Invitation resent"), "status": "ok"})
except ResourceNotFound:
return json_response({"response": _("Error while attempting resend"), "status": "error"})
示例2: accept_invitation
# 需要导入模块: from corehq.apps.users.models import Invitation [as 别名]
# 或者: from corehq.apps.users.models.Invitation import get [as 别名]
def accept_invitation(request, domain, invitation_id):
if request.GET.get('switch') == 'true':
logout(request)
return redirect_to_login(request.path)
if request.GET.get('create') == 'true':
logout(request)
return HttpResponseRedirect(request.path)
invitation = Invitation.get(invitation_id)
assert(invitation.domain == domain)
if invitation.is_accepted:
messages.error(request, "Sorry that invitation has already been used up. "
"If you feel this is a mistake please ask the inviter for "
"another invitation.")
return HttpResponseRedirect(reverse("login"))
if request.user.is_authenticated():
# if you are already authenticated, just add the domain to your
# list of domains
if request.couch_user.username != invitation.email:
messages.error(request, "The invited user %s and your user %s do not match!" % (invitation.email, request.couch_user.username))
if request.method == "POST":
couch_user = CouchUser.from_django_user(request.user)
couch_user.add_domain_membership(domain=domain)
couch_user.set_role(domain, invitation.role)
couch_user.save()
invitation.is_accepted = True
invitation.save()
messages.success(request, "You have been added to the %s domain" % domain)
return HttpResponseRedirect(reverse("domain_homepage", args=[domain,]))
else:
return render_to_response(request, 'users/accept_invite.html', {'domain': domain,
"invited_user": invitation.email if request.couch_user.username != invitation.email else ""})
else:
# if you're not authenticated we need you to fill out your information
if request.method == "POST":
form = NewWebUserRegistrationForm(request.POST)
if form.is_valid():
user = activate_new_user(form, is_domain_admin=False, domain=invitation.domain)
user.set_role(domain, invitation.role)
user.save()
invitation.is_accepted = True
invitation.save()
messages.success(request, "User account for %s created! You may now login." % form.cleaned_data["email"])
return HttpResponseRedirect(reverse("login"))
else:
form = NewWebUserRegistrationForm(initial={'email': invitation.email})
return render_to_response(request, "users/accept_invite.html", {"form": form})
示例3: delete_invitation
# 需要导入模块: from corehq.apps.users.models import Invitation [as 别名]
# 或者: from corehq.apps.users.models.Invitation import get [as 别名]
def delete_invitation(request, domain):
invitation_id = request.POST["id"]
invitation = Invitation.get(invitation_id)
invitation.delete()
return json_response({"status": "ok"})
示例4: __call__
# 需要导入模块: from corehq.apps.users.models import Invitation [as 别名]
# 或者: from corehq.apps.users.models.Invitation import get [as 别名]
def __call__(self, request, invitation_id, **kwargs):
logging.warning("Don't use this view in more apps until it gets cleaned up.")
# add the correct parameters to this instance
self.request = request
self.inv_id = invitation_id
if "domain" in kwargs:
self.domain = kwargs["domain"]
if request.GET.get("switch") == "true":
logout(request)
return redirect_to_login(request.path)
if request.GET.get("create") == "true":
logout(request)
return HttpResponseRedirect(request.path)
try:
invitation = Invitation.get(invitation_id)
except ResourceNotFound:
messages.error(
request,
_(
"Sorry, it looks like your invitation has expired. "
"Please check the invitation link you received and try again, or request a "
"project administrator to send you the invitation again."
),
)
return HttpResponseRedirect(reverse("login"))
if invitation.is_accepted:
messages.error(
request,
_(
"Sorry, that invitation has already been used up. "
"If you feel this is a mistake please ask the inviter for "
"another invitation."
),
)
return HttpResponseRedirect(reverse("login"))
self.validate_invitation(invitation)
if invitation.is_expired:
return HttpResponseRedirect(reverse("no_permissions"))
context = self.added_context()
if request.user.is_authenticated():
is_invited_user = request.couch_user.username.lower() == invitation.email.lower()
if self.is_invited(invitation, request.couch_user) and not request.couch_user.is_superuser:
if is_invited_user:
# if this invite was actually for this user, just mark it accepted
messages.info(
request, _("You are already a member of {entity}.").format(entity=self.inviting_entity)
)
invitation.is_accepted = True
invitation.save()
else:
messages.error(
request,
_(
"It looks like you are trying to accept an invitation for "
"{invited} but you are already a member of {entity} with the "
"account {current}. Please sign out to accept this invitation "
"as another user."
).format(
entity=self.inviting_entity, invited=invitation.email, current=request.couch_user.username
),
)
return HttpResponseRedirect(self.redirect_to_on_success)
if not is_invited_user:
messages.error(
request,
_("The invited user {invited} and your user {current} do not match!").format(
invited=invitation.email, current=request.couch_user.username
),
)
if request.method == "POST":
couch_user = CouchUser.from_django_user(request.user)
self._invite(invitation, couch_user)
track_workflow(
request.couch_user.get_email(),
"Current user accepted a project invitation",
{"Current user accepted a project invitation": "yes"},
)
meta = get_meta(request)
track_existing_user_accepted_invite_on_hubspot.delay(request.couch_user, request.COOKIES, meta)
return HttpResponseRedirect(self.redirect_to_on_success)
else:
mobile_user = CouchUser.from_django_user(request.user).is_commcare_user()
context.update(
{
"mobile_user": mobile_user,
"invited_user": invitation.email if request.couch_user.username != invitation.email else "",
}
)
return render(request, self.template, context)
else:
if request.method == "POST":
form = NewWebUserRegistrationForm(request.POST)
if form.is_valid():
#.........这里部分代码省略.........