コード例 #1
0
def create_organization_object(org_name, creator, attrs={}):
    '''Creates an OrganizationProfile object without saving to the database'''
    name = attrs.get('name', org_name)
    first_name, last_name = _get_first_last_names(name)
    email = attrs.get('email', u'')
    new_user = User(username=org_name,
                    first_name=first_name,
                    last_name=last_name,
                    email=email,
                    is_active=True)
    new_user.save()
    registration_profile = RegistrationProfile.objects.create_profile(new_user)
    if email:
        site = Site.objects.get(pk=settings.SITE_ID)
        registration_profile.send_activation_email(site)
    profile = OrganizationProfile(user=new_user,
                                  name=name,
                                  creator=creator,
                                  created_by=creator,
                                  city=attrs.get('city', u''),
                                  country=attrs.get('country', u''),
                                  organization=attrs.get('organization', u''),
                                  home_page=attrs.get('home_page', u''),
                                  twitter=attrs.get('twitter', u''))
    return profile
コード例 #2
0
ファイル: tools.py プロジェクト: kenhorn/onadata
def create_organization_object(org_name, creator, attrs=None):
    '''Creates an OrganizationProfile object without saving to the database'''
    attrs = attrs if attrs else {}
    name = attrs.get('name', org_name) if attrs else org_name
    first_name, last_name = _get_first_last_names(name)
    email = attrs.get('email', u'') if attrs else u''
    new_user = User(username=org_name,
                    first_name=first_name,
                    last_name=last_name,
                    email=email,
                    is_active=getattr(settings, 'ORG_ON_CREATE_IS_ACTIVE',
                                      True))
    new_user.save()
    try:
        registration_profile = RegistrationProfile.objects.create_profile(
            new_user)
    except IntegrityError:
        raise ValidationError(_(u"%s already exists" % org_name))
    if email:
        site = Site.objects.get(pk=settings.SITE_ID)
        registration_profile.send_activation_email(site)
    profile = OrganizationProfile(user=new_user,
                                  name=name,
                                  creator=creator,
                                  created_by=creator,
                                  city=attrs.get('city', u''),
                                  country=attrs.get('country', u''),
                                  organization=attrs.get('organization', u''),
                                  home_page=attrs.get('home_page', u''),
                                  twitter=attrs.get('twitter', u''))
    return profile
コード例 #3
0
ファイル: tools.py プロジェクト: okal/onadata
def create_organization_object(org_name, creator, attrs={}):
    '''Creates an OrganizationProfile object without saving to the database'''
    name = attrs.get('name', org_name)
    first_name, last_name = _get_first_last_names(name)
    new_user = User(username=org_name,
                    first_name=first_name,
                    last_name=last_name,
                    email=attrs.get('email', u''))
    new_user.save()
    profile = OrganizationProfile(user=new_user,
                                  name=name,
                                  creator=creator,
                                  created_by=creator,
                                  city=attrs.get('city', u''),
                                  country=attrs.get('country', u''),
                                  organization=attrs.get('organization', u''),
                                  home_page=attrs.get('home_page', u''),
                                  twitter=attrs.get('twitter', u''))
    return profile