Commit 108cf5c2 authored by Philipp Sebastian Sommer's avatar Philipp Sebastian Sommer
Browse files

add --names option to makedummyusers

parent 7dea2806
Pipeline #101397 failed with stage
in 45 seconds
......@@ -45,7 +45,9 @@ Quick start for development
8. Populate the database with dummy users (note that this is for development
purposes only!)::
python manage.py makedummyusers
python manage.py makedummyusers -n "Beate Geyer" "Burkhardt Rockel"
The password for these user accounts will be ``admin``.
9. Run the local development server via::
......
import operator
from functools import reduce
from django.core.management.base import BaseCommand, CommandError
import datetime as dt
......@@ -39,15 +42,34 @@ class Command(BaseCommand):
def add_arguments(self, parser):
"""Add connection arguments to the parser."""
pass
parser.add_argument(
"-n",
"--names",
help=(
"User name to create (must match one person in the database, "
"e.g. `Beate Geyer`."
),
nargs="+",
metavar="FIRSTNAME LASTNAME",
)
def handle(self, *args, **options):
"""Migrate the database."""
from django.db.models import Q
from clm_members.models import CommunityMember
from django.contrib.auth.models import User
for member in log_progress(CommunityMember.objects.all()):
if options.get("names"):
names = map(lambda s: s.split(maxsplit=1), options["names"])
query = reduce(
operator.or_,
(Q(first_name=fn, last_name=ln) for fn, ln in names))
members = CommunityMember.objects.filter(query)
else:
members = CommunityMember.objects.all()
for member in log_progress(members):
first = member.first_name
last = member.last_name
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment