Пример #1
0
def orgs_add_project(request, org):
    form = AddProjectForm(org, request.couch_user, request.POST)
    if form.is_valid():
        domain_name = form.cleaned_data['domain_name']

        dom = Domain.get_by_name(domain_name)
        dom.organization = org
        dom.hr_name = form.cleaned_data['domain_hrname']
        dom.save()
        messages.success(request, "Project Added!")
    else:
        messages.error(request, "Unable to add project")
        return orgs_landing(request, org, add_form=form)
    return HttpResponseRedirect(reverse('orgs_landing', args=[org]))
Пример #2
0
def orgs_add_project(request, org):
    form = AddProjectForm(org, request.couch_user, request.POST)
    if form.is_valid():
        domain_name = form.cleaned_data['domain_name']

        dom = Domain.get_by_name(domain_name)
        dom.organization = org
        dom.hr_name = form.cleaned_data['domain_hrname']
        dom.save()
        messages.success(request, "Project Added!")
    else:
        messages.error(request, "Unable to add project")
        return orgs_landing(request, org, add_form=form)
    return HttpResponseRedirect(reverse('orgs_landing', args=[org]))
Пример #3
0
def orgs_add_project(request, org):
    form = AddProjectForm(org, request.POST)
    if form.is_valid():
        domain_name = form.cleaned_data["domain_name"]

        if not request.couch_user.is_domain_admin(domain_name):
            org_requests = filter(lambda r: r.domain == domain_name, OrgRequest.get_requests(org))
            if not org_requests:
                messages.error(request, "You must be an admin of this project in order to add it to your organization")
                return orgs_landing(request, org, add_form=form)

        dom = Domain.get_by_name(domain_name)
        dom.organization = org
        dom.hr_name = form.cleaned_data["domain_hrname"]
        dom.save()
        messages.success(request, "Project Added!")
    else:
        messages.error(request, "Unable to add project")
        return orgs_landing(request, org, add_form=form)
    return HttpResponseRedirect(reverse("orgs_landing", args=[org]))
Пример #4
0
def orgs_add_project(request, org):
    form = AddProjectForm(org, request.POST)
    if form.is_valid():
        domain_name = form.cleaned_data['domain_name']

        if not request.couch_user.is_domain_admin(domain_name):
            org_requests = filter(lambda r: r.domain == domain_name, OrgRequest.get_requests(org))
            if not org_requests:
                messages.error(request, 'You must be an admin of this project in order to add it to your organization')
                return orgs_landing(request, org, add_form=form)

        dom = Domain.get_by_name(domain_name)
        dom.organization = org
        dom.hr_name = form.cleaned_data['domain_hrname']
        dom.save()
        messages.success(request, "Project Added!")
    else:
        messages.error(request, "Unable to add project")
        return orgs_landing(request, org, add_form=form)
    return HttpResponseRedirect(reverse('orgs_landing', args=[org]))
Пример #5
0
def orgs_landing(request, org, template="orgs/orgs_landing.html", form=None, add_form=None, invite_member_form=None,
                 add_team_form=None, update_form=None, tab=None):
    organization = request.organization

    class LandingNotification(Notification):
        doc_type = 'OrgLandingNotification'

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

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

    reg_form_empty = not form
    add_form_empty = not add_form
    invite_member_form_empty = not invite_member_form
    add_team_form_empty = not add_team_form

    reg_form = form or DomainRegistrationForm(initial={'org': organization.name})
    add_form = add_form or AddProjectForm(org)
    invite_member_form = invite_member_form or InviteMemberForm(org)
    add_team_form = add_team_form or AddTeamForm(org)

    ctxt = base_context(request, organization, update_form=update_form)
    user_domains = []
    req_domains = []
    # display a notification for each org request that hasn't previously been seen
    if request.couch_user.is_org_admin(org):
        requests = OrgRequest.get_requests(org)
        for req in requests:
            if req.seen or req.domain in [d.name for d in ctxt["domains"]]:
                continue
            messages.info(request, render_to_string("orgs/partials/org_request_notification.html",
                {"requesting_user": WebUser.get(req.requested_by).username, "org_req": req, "org": organization}),
                extra_tags="html")

        def format_domains(dom_list, extra=None):
            extra = extra or []
            dom_list = list(set(filter(lambda d: d not in ctxt["domains"] + extra, dom_list)))
            return [Domain.get_by_name(d) for d in dom_list]

        # get the existing domains that an org admin would add to the organization
        user_domains = request.couch_user.domains or []
        req_domains = [req.domain for req in requests]
        user_domains = format_domains(user_domains)
        req_domains = format_domains(req_domains, [d.name for d in user_domains if d])

    ctxt.update(dict(reg_form=reg_form, add_form=add_form, reg_form_empty=reg_form_empty, add_form_empty=add_form_empty,
                invite_member_form=invite_member_form, invite_member_form_empty=invite_member_form_empty,
                add_team_form=add_team_form, add_team_form_empty=add_team_form_empty, tab="projects",
                user_domains=user_domains, req_domains=req_domains))
    return render(request, template, ctxt)