本文整理汇总了Python中corehq.apps.users.models.Invitation.by_email方法的典型用法代码示例。如果您正苦于以下问题:Python Invitation.by_email方法的具体用法?Python Invitation.by_email怎么用?Python Invitation.by_email使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.users.models.Invitation
的用法示例。
在下文中一共展示了Invitation.by_email方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: select
# 需要导入模块: from corehq.apps.users.models import Invitation [as 别名]
# 或者: from corehq.apps.users.models.Invitation import by_email [as 别名]
def select(request, domain_select_template='domain/select.html', do_not_redirect=False):
domains_for_user = Domain.active_for_user(request.user)
if not domains_for_user:
from corehq.apps.registration.views import track_domainless_new_user
track_domainless_new_user(request)
return redirect('registration_domain')
email = request.couch_user.get_email()
open_invitations = [e for e in Invitation.by_email(email) if not e.is_expired]
additional_context = {
'domains_for_user': domains_for_user,
'open_invitations': open_invitations,
'current_page': {'page_name': _('Select A Project')},
}
last_visited_domain = request.session.get('last_visited_domain')
if open_invitations \
or do_not_redirect \
or not last_visited_domain:
return render(request, domain_select_template, additional_context)
else:
domain_obj = Domain.get_by_name(last_visited_domain)
if domain_obj and domain_obj.is_active:
# mirrors logic in login_and_domain_required
if (
request.couch_user.is_member_of(domain_obj)
or (request.user.is_superuser and not domain_obj.restrict_superusers)
or domain_obj.is_snapshot
):
try:
from corehq.apps.dashboard.views import dashboard_default
return dashboard_default(request, last_visited_domain)
except Http404:
pass
del request.session['last_visited_domain']
return render(request, domain_select_template, additional_context)
示例2: test_by_email
# 需要导入模块: from corehq.apps.users.models import Invitation [as 别名]
# 或者: from corehq.apps.users.models.Invitation import by_email [as 别名]
def test_by_email(self):
self.assertEqual(len(Invitation.by_email('[email protected]')), 1)
self.assertEqual(len(Invitation.by_email('[email protected]')), 1)
self.assertEqual(len(Invitation.by_email('[email protected]')), 0)