當前位置: 首頁>>代碼示例>>Python>>正文


Python models.Invitation類代碼示例

本文整理匯總了Python中corehq.apps.users.models.Invitation的典型用法代碼示例。如果您正苦於以下問題:Python Invitation類的具體用法?Python Invitation怎麽用?Python Invitation使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Invitation類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: invite_web_user

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)
開發者ID:mchampanis,項目名稱:core-hq,代碼行數:25,代碼來源:views.py

示例2: setUpClass

 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)
開發者ID:ansarbek,項目名稱:commcare-hq,代碼行數:10,代碼來源:test_models.py

示例3: reinvite_web_user

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"})
開發者ID:philipkaare,項目名稱:commcare-hq,代碼行數:10,代碼來源:__init__.py

示例4: resend_pending_invitations

def resend_pending_invitations():
    from corehq.apps.users.models import Invitation
    days_to_resend = (15, 29)
    days_to_expire = 30
    domains = Domain.get_all()
    for domain in domains:
        invitations = Invitation.by_domain(domain.name)
        for invitation in invitations:
            days = (datetime.utcnow() - invitation.invited_on).days
            if days in days_to_resend:
                invitation.send_activation_email(days_to_expire - days)
開發者ID:bazuzi,項目名稱:commcare-hq,代碼行數:11,代碼來源:tasks.py

示例5: accept_invitation

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})
開發者ID:mchampanis,項目名稱:core-hq,代碼行數:48,代碼來源:views.py

示例6: invite_web_user_form

    def invite_web_user_form(self):
        role_choices = UserRole.role_choices(self.domain)
        loc = None
        domain_request = DomainRequest.objects.get(id=self.request_id) if self.request_id else None
        initial = {"email": domain_request.email if domain_request else None}
        if "location_id" in self.request.GET:
            from corehq.apps.locations.models import SQLLocation

            loc = SQLLocation.objects.get(location_id=self.request.GET.get("location_id"))
        if self.request.method == "POST":
            current_users = [user.username for user in WebUser.by_domain(self.domain)]
            pending_invites = [di.email for di in Invitation.by_domain(self.domain)]
            return AdminInvitesUserForm(
                self.request.POST,
                excluded_emails=current_users + pending_invites,
                role_choices=role_choices,
                domain=self.domain,
            )
        return AdminInvitesUserForm(initial=initial, role_choices=role_choices, domain=self.domain, location=loc)
開發者ID:philipkaare,項目名稱:commcare-hq,代碼行數:19,代碼來源:__init__.py

示例7: invite_web_user_form

 def invite_web_user_form(self):
     role_choices = _get_editable_role_choices(self.domain, self.request.couch_user, allow_admin_role=True)
     loc = None
     domain_request = DomainRequest.objects.get(id=self.request_id) if self.request_id else None
     initial = {
         'email': domain_request.email if domain_request else None,
     }
     if 'location_id' in self.request.GET:
         from corehq.apps.locations.models import SQLLocation
         loc = SQLLocation.objects.get(location_id=self.request.GET.get('location_id'))
     if self.request.method == 'POST':
         current_users = [user.username for user in WebUser.by_domain(self.domain)]
         pending_invites = [di.email for di in Invitation.by_domain(self.domain)]
         return AdminInvitesUserForm(
             self.request.POST,
             excluded_emails=current_users + pending_invites,
             role_choices=role_choices,
             domain=self.domain
         )
     return AdminInvitesUserForm(initial=initial, role_choices=role_choices, domain=self.domain, location=loc)
開發者ID:kkrampa,項目名稱:commcare-hq,代碼行數:20,代碼來源:__init__.py

示例8: select

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)
開發者ID:dimagi,項目名稱:commcare-hq,代碼行數:38,代碼來源:base.py

示例9: __call__

    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():
#.........這裏部分代碼省略.........
開發者ID:philipkaare,項目名稱:commcare-hq,代碼行數:101,代碼來源:__init__.py

示例10: delete_invitation

def delete_invitation(request, domain):
    invitation_id = request.POST["id"]
    invitation = Invitation.get(invitation_id)
    invitation.delete()
    return json_response({"status": "ok"})
開發者ID:philipkaare,項目名稱:commcare-hq,代碼行數:5,代碼來源:__init__.py

示例11: test_by_domain

 def test_by_domain(self):
     self.assertEqual(len(Invitation.by_domain('domain_1')), 1)
     self.assertEqual(len(Invitation.by_domain('domain_2')), 1)
     self.assertEqual(len(Invitation.by_domain('domain_3')), 0)
開發者ID:ansarbek,項目名稱:commcare-hq,代碼行數:4,代碼來源:test_models.py

示例12: test_by_email

 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)
開發者ID:ansarbek,項目名稱:commcare-hq,代碼行數:4,代碼來源:test_models.py


注:本文中的corehq.apps.users.models.Invitation類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。