Coverage for jutil/management/commands/setpass.py: 0%

# Coverage for jutil/management/commands/setpass.py : 0%

## 19 statements 0 run 19 missing 0 excluded 0 partial

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 from django.contrib.auth.models import User

2 from django.core.management.base import BaseCommand, CommandParser

3 from django.db.models import Q

4

5

6 class Command(BaseCommand):

7 help = 'Non-interactive user password reset'

8

9 def add_arguments(self, parser: CommandParser):

10 parser.add_argument('name', type=str)

11 parser.add_argument('password', type=str)

12

13 def handle(self, *args, **options):

14 name = options['name']

15 passwd = options['password']

16 users = User.objects.filter(Q(username=name) | Q(email=name))

17 if not users:

18 print('User not found')

19 for user in users:

20 assert isinstance(user, User)

21 user.set_password(passwd)

22 user.save()

23 print("User {} password set to {}".format(name, passwd))