Example #1
0
def load_member(cli, size, fake, root, *_):
    """
    Load members
    """
    nb_users = size * 10
    cli.stdout.write("Nombres de membres à créer : {}".format(nb_users))
    tps1 = time.time()
    cpt = 1
    # member in settings
    users_set = [
        "admin",
        settings.ZDS_APP["member"]["external_account"],
        settings.ZDS_APP["member"]["anonymous_account"],
    ]
    for default_user in users_set:
        current_user = Profile.objects.filter(
            user__username=default_user).first()
        if current_user is None:
            profile = ProfileFactory(user__username=default_user)
            profile.user.set_password(default_user)
            profile.user.first_name = default_user
            profile.user.email = fake.free_email()
            if default_user == "admin":
                profile.user.is_superuser = True
                profile.user.is_staff = True
            with contextlib.suppress(IntegrityError):
                profile.user.save()
                profile.site = fake.url()
                profile.biography = fake.text(max_nb_chars=200)
                profile.last_ip_address = fake.ipv4()
                profile.save()

    for i in range(0, nb_users):
        while Profile.objects.filter(
                user__username="******".format(root, cpt)).count() > 0:
            cpt += 1
        profile = ProfileFactory(user__username="******".format(root, cpt))
        profile.user.set_password(profile.user.username)
        profile.user.first_name = fake.first_name()
        profile.user.last_name = fake.last_name()
        profile.user.email = fake.free_email()
        profile.user.save()
        profile.site = fake.url()
        profile.biography = fake.text(max_nb_chars=200)
        profile.last_ip_address = fake.ipv4()
        profile.save()
        cpt += 1
        sys.stdout.write(" User {}/{}  \r".format(i + 1, nb_users))
        sys.stdout.flush()
    tps2 = time.time()
    cli.stdout.write("\nFait en {} sec".format(tps2 - tps1))
Example #2
0
def load_member(cli, size, fake, root):
    """
    Load members
    """
    nb_users = size * 10
    cli.stdout.write(u'Nombres de membres à créer : {}'.format(nb_users))
    tps1 = time.time()
    cpt = 1
    # member in settings
    users_set = [
        'admin', settings.ZDS_APP['member']['external_account'],
        settings.ZDS_APP['member']['anonymous_account']
    ]
    for default_user in users_set:
        current_user = Profile.objects.filter(
            user__username=default_user).first()
        if current_user is None:
            profile = ProfileFactory(user__username=default_user)
            profile.user.set_password(default_user)
            profile.user.first_name = default_user
            profile.user.email = fake.free_email()
            if default_user == 'admin':
                profile.user.is_superuser = True
                profile.user.is_staff = True
            profile.user.save()
            profile.site = fake.url()
            profile.biography = fake.text(max_nb_chars=200)
            profile.last_ip_address = fake.ipv4()
            profile.save()

    for i in range(0, nb_users):
        while Profile.objects.filter(
                user__username='******'.format(root, cpt)).count() > 0:
            cpt += 1
        profile = ProfileFactory(user__username='******'.format(root, cpt))
        profile.user.set_password(profile.user.username)
        profile.user.first_name = fake.first_name()
        profile.user.last_name = fake.last_name()
        profile.user.email = fake.free_email()
        profile.user.save()
        profile.site = fake.url()
        profile.biography = fake.text(max_nb_chars=200)
        profile.last_ip_address = fake.ipv4()
        profile.save()
        cpt += 1
        sys.stdout.write(' User {}/{}  \r'.format(i + 1, nb_users))
        sys.stdout.flush()
    tps2 = time.time()
    cli.stdout.write(u'\nFait en {} sec'.format(tps2 - tps1))