当前位置: 首页>>代码示例>>Python>>正文


Python models.Team类代码示例

本文整理汇总了Python中corehq.apps.orgs.models.Team的典型用法代码示例。如果您正苦于以下问题:Python Team类的具体用法?Python Team怎么用?Python Team使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Team类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: orgs_team_members

def orgs_team_members(request, org, team_id, template="orgs/orgs_team_members.html"):
    #organization and teams
    organization = Organization.get_by_name(org)
    teams = Team.get_by_org(org)
    current_domains = Domain.get_by_organization(org)

    #check that the team exists
    team = Team.get(team_id)
    if team is None:
        raise Http404("Group %s does not exist" % team_id)

    #inspect the members of the team
    member_ids = team.get_member_ids()
    members = WebUser.view("_all_docs", keys=member_ids, include_docs=True).all()
    members.sort(key=lambda user: user.username)

    #inspect the domains of the team
    domain_names = team.get_domains()
    domains = list()
    for name in domain_names:
        domains.append([Domain.get_by_name(name), team.role_label(domain=name)])

    all_org_domains = Domain.get_by_organization(org)
    non_domains = [domain for domain in all_org_domains if domain.name not in domain_names]

    all_org_member_ids = organization.members
    all_org_members = WebUser.view("_all_docs", keys=all_org_member_ids, include_docs=True).all()
    non_members = [member for member in all_org_members if member.user_id not in member_ids]

    vals = dict(org=organization, team=team, teams=teams, members=members, nonmembers=non_members, domains=current_domains, team_domains=domains, team_nondomains=non_domains)
    return render_to_response(request, template, vals)
开发者ID:mchampanis,项目名称:core-hq,代码行数:31,代码来源:views.py

示例2: orgs_add_team

def orgs_add_team(request, org):
    if request.method == "POST":
        form = AddTeamForm(org, request.POST)
        if form.is_valid():
            team_name = form.cleaned_data['team']
            team = Team(name=team_name, organization=org)
            team.save()
            messages.success(request, "Team Added!")
        else:
            messages.error(request, "Unable to add team")
            return orgs_landing(request, org, add_team_form=form)
    return HttpResponseRedirect(reverse('orgs_landing', args=[org]))
开发者ID:mchampanis,项目名称:core-hq,代码行数:12,代码来源:views.py

示例3: has_permission

    def has_permission(self, domain, permission, data=None):
        # is_admin is the same as having all the permissions set
        from corehq.apps.orgs.models import Team
        if self.is_global_admin():
            return True
        elif self.is_domain_admin(domain):
            return True

        dm_list = list()

        dm = self.get_domain_membership(domain)
        if dm:
            dm_list.append([dm, ''])

        for team_name, team_id in self.teams:
            team = Team.get(team_id)
            if team.get_domain_membership(domain) and team.get_domain_membership(domain).role:
                dm_list.append([team.get_domain_membership(domain), '(' + team_name + ')'])

        #now find out which dm has the highest permissions
        if dm_list:
            role = self.total_domain_membership(dm_list, domain)
            dm = CustomDomainMembership(domain=domain, custom_role=role)
            return dm.has_permission(permission, data)
        else:
            return False
开发者ID:mchampanis,项目名称:core-hq,代码行数:26,代码来源:models.py

示例4: orgs_add_team

def orgs_add_team(request, org):
    team_name = request.POST.get("team", None)
    if not team_name:
        messages.error(request, 'You must specify a team name')
        return HttpResponseRedirect(reverse('orgs_teams', args=[org]))

    org_teams = Team.get_by_org(org)
    for t in org_teams:
        if t.name == team_name:
            messages.error(request, 'A team with that name already exists.')
            return HttpResponseRedirect(reverse('orgs_teams', args=[org]))

    team = Team(name=team_name, organization=org)
    team.save()
    messages.success(request, "Team Added!")
    return HttpResponseRedirect(reverse('orgs_teams', args=[org]))
开发者ID:dszafranek,项目名称:commcare-hq,代码行数:16,代码来源:views.py

示例5: remove_domain_from_team

def remove_domain_from_team(request, org, team_id, domain):
    team = Team.get(team_id)
    if team:
        team.delete_domain_membership(domain)
        team.save()
    if 'redirect_url' in request.POST:
        return HttpResponseRedirect(reverse(request.POST['redirect_url'], args=(org, team_id)))
开发者ID:mchampanis,项目名称:core-hq,代码行数:7,代码来源:views.py

示例6: orgs_team_members

def orgs_team_members(request, org, team_id, template="orgs/orgs_team_members.html"):
    class TeamMembersNotification(Notification):
        doc_type = 'OrgTeamMembersNotification'

        def template(self):
            return 'orgs/partials/team_members_notification.html'

    MainNotification.display_if_needed(messages, request, ctxt={"org": request.organization})
    TeamMembersNotification.display_if_needed(messages, request)

    ctxt = base_context(request, request.organization)
    ctxt["tab"] = "teams"

    try:
        team = Team.get(team_id)
    except ResourceNotFound:
        raise Http404("Team %s does not exist" % team_id)

    team_members = team.get_members()
    team_members.sort(key=lambda user: user.username)

    #inspect the domains of the team
    domain_names = team.get_domains()
    team_domains = list()
    for name in domain_names:
        team_domains.append([Domain.get_by_name(name), team.role_label(domain=name), UserRole.by_domain(name)])

    nonmembers = filter(lambda m: m.username not in [tm.username for tm in team_members], ctxt["members"])
    nondomains = filter(lambda d: d.name not in [td[0].name for td in team_domains], ctxt["domains"])

    ctxt.update(dict(team=team, team_members=team_members, nonmembers=nonmembers,
                     team_domains=team_domains, nondomains=nondomains))
    return render(request, template, ctxt)
开发者ID:dszafranek,项目名称:commcare-hq,代码行数:33,代码来源:views.py

示例7: clean_team

 def clean_team(self):
     data = self.cleaned_data["team"].strip()
     org_teams = Team.get_by_org(self.org_name)
     for t in org_teams:
         if t.name == data:
             raise forms.ValidationError("A team with that name already exists.")
     return data
开发者ID:nikhilvarma22,项目名称:commcare-hq,代码行数:7,代码来源:forms.py

示例8: get_role

    def get_role(self, domain=None):
        """
        Get the role object for this user

        """
        from corehq.apps.orgs.models import Team
        if domain is None:
            # default to current_domain for django templates
            domain = self.current_domain

        if self.is_global_admin():
            return AdminUserRole(domain=domain)

        dm_list = list()

        dm = self.get_domain_membership(domain)
        if dm:
            dm_list.append([dm, ''])

        for team_name, team_id in self.teams:
            team = Team.get(team_id)
            if team.get_domain_membership(domain) and team.get_domain_membership(domain).role:
                dm_list.append([team.get_domain_membership(domain), ' (' + team_name + ')'])

        #now find out which dm has the highest permissions
        if dm_list:
            return self.total_domain_membership(dm_list, domain)
        else:
            raise DomainMembershipError()
开发者ID:mchampanis,项目名称:core-hq,代码行数:29,代码来源:models.py

示例9: remove_all_from_team

def remove_all_from_team(request, org, team_id):
    team = Team.get(team_id)
    members = team.get_members()
    for member in members:
        member.remove_from_team(org, team_id)
        member.save()
    return HttpResponseRedirect(reverse(request.POST.get('redirect_url', 'orgs_team_members'), args=(org, team_id)))
开发者ID:dszafranek,项目名称:commcare-hq,代码行数:7,代码来源:views.py

示例10: remove_all_from_team

def remove_all_from_team(request, org, team_id):
    team = Team.get(team_id)
    if team:
        member_ids = team.member_ids
        for member in member_ids:
            team.remove_member(member)
    if 'redirect_url' in request.POST:
        return HttpResponseRedirect(reverse(request.POST['redirect_url'], args=(org, team_id)))
开发者ID:mchampanis,项目名称:core-hq,代码行数:8,代码来源:views.py

示例11: apply_teams_to_users

 def apply_teams_to_users(self, web_users):
     teams = Team.get_by_domain(self.domain)
     for team in teams:
         for user in team.get_members():
             if user.get_id not in [web_user.get_id for web_user in web_users]:
                 user.from_team = True
                 web_users.append(user)
     for user in web_users:
         user.current_domain = self.domain
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:9,代码来源:__init__.py

示例12: add_all_to_team

def add_all_to_team(request, org, team_id):
    team = Team.get(team_id)
    if team:
        organization = Organization.get_by_name(org)
        members = organization.members
        for member in members:
            team.add_member(member)
    if 'redirect_url' in request.POST:
        return HttpResponseRedirect(reverse(request.POST['redirect_url'], args=(org, team_id)))
开发者ID:mchampanis,项目名称:core-hq,代码行数:9,代码来源:views.py

示例13: delete_team

def delete_team(request, org, team_id):
    team = Team.get(team_id)
    if team.organization == org:
        record = team.soft_delete()
        messages.success(request, 'You have deleted a team. <a href="{url}" class="post-link">Undo</a>'.format(
            url=reverse('undo_delete_team', args=[org, record.get_id])
        ), extra_tags="html")
        return HttpResponseRedirect(reverse("orgs_teams", args=(org, )))
    else:
        return HttpResponseForbidden()
开发者ID:mchampanis,项目名称:core-hq,代码行数:10,代码来源:views.py

示例14: web_users

 def web_users(self):
     web_users = WebUser.by_domain(self.domain)
     teams = Team.get_by_domain(self.domain)
     for team in teams:
         for user in team.get_members():
             if user.get_id not in [web_user.get_id for web_user in web_users]:
                 user.from_team = True
                 web_users.append(user)
     for user in web_users:
         user.current_domain = self.domain
     return web_users
开发者ID:pawelreise,项目名称:commcare-hq,代码行数:11,代码来源:__init__.py

示例15: get_domains

 def get_domains(self):
     from corehq.apps.orgs.models import Team
     domains = [dm.domain for dm in self.domain_memberships]
     if self.teams:
         for team_name, team_id in self.teams:
             team = Team.get(team_id)
             team_domains = [dm.domain for dm in team.domain_memberships]
             for domain in team_domains:
                 if domain not in domains:
                     domains.append(domain)
     return domains
开发者ID:mchampanis,项目名称:core-hq,代码行数:11,代码来源:models.py


注:本文中的corehq.apps.orgs.models.Team类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。