Exemplo n.º 1
0
def update_authorized_domains(corp_profile, domain_names):
    """
    Update the authorized domains for this corporate membership.
    """
    from urllib.parse import urlparse
    from tendenci.apps.corporate_memberships.models import CorpMembershipAuthDomain
    if domain_names.strip():
        dname_list = []
        for name in domain_names.split(','):
            name = name.strip().strip('/')
            if name.startswith('http://') or name.startswith('https://'):
                name = urlparse(name).netloc
            if name.startswith('www.'):
                name = name[4:]
            dname_list.append(name)

        # if domain is not in the list domain_names, delete it from db
        # otherwise, remove it from list
        if corp_profile.authorized_domains:
            for auth_domain in list(corp_profile.authorized_domains.all()):
                if auth_domain.name in dname_list:
                    dname_list.remove(auth_domain.name)
                else:
                    auth_domain.delete()

        # add the rest of the domain
        for name in dname_list:
            auth_domain = CorpMembershipAuthDomain(corp_profile=corp_profile,
                                                   name=name)
            auth_domain.save()
Exemplo n.º 2
0
def update_authorized_domains(corp_profile, domain_names):
    """
    Update the authorized domains for this corporate membership.
    """
    from tendenci.apps.corporate_memberships.models import CorpMembershipAuthDomain
    if domain_names.strip():
        dname_list = domain_names.split(',')
        dname_list = [name.strip() for name in dname_list]

        # if domain is not in the list domain_names, delete it from db
        # otherwise, remove it from list
        if corp_profile.authorized_domains:
            for auth_domain in list(corp_profile.authorized_domains.all()):
                if auth_domain.name in dname_list:
                    dname_list.remove(auth_domain.name)
                else:
                    auth_domain.delete()

        # add the rest of the domain
        for name in dname_list:
            auth_domain = CorpMembershipAuthDomain(corp_profile=corp_profile,
                                                   name=name)
            auth_domain.save()
Exemplo n.º 3
0
def update_authorized_domains(corp_profile, domain_names):
    """
    Update the authorized domains for this corporate membership.
    """
    from tendenci.apps.corporate_memberships.models import CorpMembershipAuthDomain
    if domain_names.strip():
        dname_list = domain_names.split(',')
        dname_list = [name.strip() for name in dname_list]

        # if domain is not in the list domain_names, delete it from db
        # otherwise, remove it from list
        if corp_profile.authorized_domains:
            for auth_domain in list(corp_profile.authorized_domains.all()):
                if auth_domain.name in dname_list:
                    dname_list.remove(auth_domain.name)
                else:
                    auth_domain.delete()

        # add the rest of the domain
        for name in dname_list:
            auth_domain = CorpMembershipAuthDomain(corp_profile=corp_profile,
                                                   name=name)
            auth_domain.save()