本文整理汇总了Python中corehq.apps.orgs.models.Organization类的典型用法代码示例。如果您正苦于以下问题:Python Organization类的具体用法?Python Organization怎么用?Python Organization使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Organization类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clean_org_name
def clean_org_name(self):
data = self.cleaned_data['org_name'].strip().lower()
if not re.match("^%s$" % new_org_re, data):
raise forms.ValidationError('Only lowercase letters and numbers allowed. Single hyphens may be used to separate words.')
if Organization.get_by_name(data) or Organization.get_by_name(data.replace('-', '.')):
raise forms.ValidationError('Organization name already taken---please try another')
return data
示例2: register_org
def register_org(request, template="registration/org_request.html"):
referer_url = request.GET.get('referer', '')
if request.method == "POST":
form = OrganizationRegistrationForm(request.POST, request.FILES)
if form.is_valid():
name = form.cleaned_data["org_name"]
title = form.cleaned_data["org_title"]
email = form.cleaned_data["email"]
url = form.cleaned_data["url"]
location = form.cleaned_data["location"]
org = Organization(name=name, title=title, location=location, email=email, url=url)
org.save()
request.couch_user.add_org_membership(org.name, is_admin=True)
request.couch_user.save()
send_new_request_update_email(request.couch_user, get_ip(request), org.name, entity_type="org")
if referer_url:
return redirect(referer_url)
messages.info(request, render_to_string('orgs/partials/landing_notification.html',
{"org": org, "user": request.couch_user}), extra_tags="html")
return HttpResponseRedirect(reverse("orgs_landing", args=[name]))
else:
form = OrganizationRegistrationForm()
return render(request, template, {
'form': form,
})
示例3: register_org
def register_org(request, template="registration/org_request.html"):
referer_url = request.GET.get('referer', '')
if request.method == "POST":
form = OrganizationRegistrationForm(request.POST, request.FILES)
if form.is_valid():
name = form.cleaned_data["org_name"]
title = form.cleaned_data["org_title"]
email = form.cleaned_data["email"]
url = form.cleaned_data["url"]
location = form.cleaned_data["location"]
logo = form.cleaned_data["logo"]
if logo:
logo_filename = logo.name
else:
logo_filename = ''
org = Organization(name=name, title=title, location=location, email=email, url=url, logo_filename=logo_filename)
org.save()
if logo:
org.put_attachment(content=logo.read(), name=logo.name)
if referer_url:
return redirect(referer_url)
return HttpResponseRedirect(reverse("orgs_landing", args=[name]))
else:
form = OrganizationRegistrationForm() # An unbound form
vals = dict(form=form)
return render_to_response(request, template, vals)
示例4: orgs_update_info
def orgs_update_info(request, org):
organization = Organization.get_by_name(org)
if request.method == "POST":
form = UpdateOrgInfo(request.POST, request.FILES)
if form.is_valid():
logo = None
if form.cleaned_data['org_title'] or organization.title:
organization.title = form.cleaned_data['org_title']
if form.cleaned_data['email'] or organization.email:
organization.email = form.cleaned_data['email']
if form.cleaned_data['url'] or organization.url:
organization.url = form.cleaned_data['url']
if form.cleaned_data['location'] or organization.location:
organization.location = form.cleaned_data['location']
#logo not working, need to look into this
if form.cleaned_data['logo']:
logo = form.cleaned_data['logo']
if organization.logo_filename:
organization.delete_attachment(organization.logo_filename)
organization.logo_filename = logo.name
organization.save()
if logo:
organization.put_attachment(content=logo.read(), name=logo.name)
else:
return orgs_landing(request, org, update_form=form)
return HttpResponseRedirect(reverse('orgs_landing', args=[org]))
示例5: 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)
示例6: orgs_logo
def orgs_logo(request, org, template="orgs/orgs_logo.html"):
organization = Organization.get_by_name(org)
if organization.logo_filename:
image = organization.get_logo()
else:
image = None
return HttpResponse(image, content_type='image/gif')
示例7: public
def public(request, org, template='orgs/public.html'):
organization = Organization.get_by_name(org, strict=True)
ctxt = base_context(request, organization)
ctxt["snapshots"] = []
for dom in ctxt["domains"]:
if dom.published_snapshot() and dom.published_snapshot().is_approved:
ctxt["snapshots"].append(dom.published_snapshot())
return render(request, template, ctxt)
示例8: verify_org
def verify_org(request, org):
organization = Organization.get_by_name(org)
if request.POST.get('verify') == 'true':
organization.verified = True
organization.save()
elif request.POST.get('verify') == 'false':
organization.verified = False
organization.save()
return HttpResponseRedirect(request.META.get('HTTP_REFERER') or reverse('orgs_base'))
示例9: get_domains
def get_domains(self):
from corehq.apps.orgs.models import Organization
from corehq.apps.domain.models import Domain
org = self.request.GET.get('org', None)
organization = Organization.get_by_name(org, strict=True)
if organization and \
(self.request.couch_user.is_superuser or self.request.couch_user.is_member_of_org(org)):
return [d for d in Domain.get_by_organization(organization.name).all()]
return []
示例10: 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)))
示例11: response_cross_project_reports
def response_cross_project_reports(self):
"""
Organization menu and corresponding reports are hidden on downgrade.
"""
if self.domain.organization:
org = Organization.get_by_name(self.domain.organization)
return self._fmt_alert(
_("You will lose access to cross-project reports for the organization '%(org_name)s'.") % {
'org_name': org.title,
})
示例12: clean_email
def clean_email(self):
data = self.cleaned_data["email"].strip().lower()
validate_email(data)
existing_member = CouchUser.get_by_username(data)
if existing_member:
org = Organization.get_by_name(self.org_name)
for member in org.get_members():
if member.get_id == existing_member.get_id:
raise forms.ValidationError("User is already part of this organization!")
return data
示例13: orgs_add_member
def orgs_add_member(request, org):
if request.method == "POST":
form = AddMemberForm(org, request.POST)
if form.is_valid():
username = form.cleaned_data['member_email']
user_id = CouchUser.get_by_username(username).userID
organization = Organization.get_by_name(org)
organization.add_member(user_id)
messages.success(request, "Member Added!")
else:
messages.error(request, "Unable to add member")
return orgs_landing(request, org, add_member_form=form)
return HttpResponseRedirect(reverse('orgs_landing', args=[org]))
示例14: page_context
def page_context(self):
domain = self.domain_object
org_users = []
teams = Team.get_by_domain(domain.name)
for team in teams:
for user in team.get_members():
user.team_id = team.get_id
user.team = team.name
org_users.append(user)
for user in org_users:
user.current_domain = domain.name
all_orgs = Organization.get_all()
return {
"project": domain,
'domain': domain.name,
"organization": Organization.get_by_name(getattr(domain, "organization", None)),
"org_users": org_users,
"all_orgs": all_orgs,
}
示例15: org_settings
def org_settings(request, domain):
domain = Domain.get_by_name(domain)
org_users = []
teams = Team.get_by_domain(domain.name)
for team in teams:
for user in team.get_members():
user.team_id = team.get_id
user.team = team.name
org_users.append(user)
for user in org_users:
user.current_domain = domain.name
all_orgs = Organization.get_all()
return render(request, 'domain/orgs_settings.html', {
"project": domain, 'domain': domain.name,
"organization": Organization.get_by_name(getattr(domain, "organization", None)),
"org_users": org_users,
"all_orgs": all_orgs,
})