Пример #1
0
def create_user(data, field=None):
    """Create users setting the password."""

    if field:
        return write_models(User, data, field=field)

    data = guess_types(data)
    for hash_ in data:
        is_superuser = hash_.pop('is_superuser', False)
        is_staff = None
        if is_superuser:
            if 'email' not in hash_:
                hash_['email'] = '*****@*****.**'
            if 'password' not in hash_:
                hash_['password'] = '******'
            if 'is_staff' in hash_:
                del hash_['is_staff']

            user = User.objects.create_superuser(**hash_)
        else:
            is_staff = hash_.pop('is_staff', None)
            if 'username' not in hash_:
                hash_['username'] = \
                    hashlib.md5(hash_['email']).hexdigest()[:30]
            if 'email' not in hash_:
                hash_['email'] = '*****@*****.**' % (hash_['username'])
            user = User.objects.create_user(**hash_)

        if is_staff is not None:
            user.is_staff = is_staff
        user.save()

    reset_sequence(User)
Пример #2
0
def write_pandas(data, field):
    # It is not necessary to call hashes_data/guess_types, but it might be
    # present in old code using the library. Test that it is a no-op
    # in that case.
    data = guess_types(data)

    for hash_ in data:
        if 'name' in hash_:
            hash_['name'] += ' Panda'

    return write_models(Panda, data, field)
Пример #3
0
def write_with_rego(data, field=None):
    for hash_ in data:
        hash_['rego'] = hash_['make'][:3].upper() + "001"

    write_models(Harvester, data, field=field)