Add a tool to save/restore user passwords.

(imported from commit 59bea04308bc0c42aeef840aa923dbef1919d31d)
This commit is contained in:
Tim Abbott 2012-12-13 15:48:45 -05:00
parent 434765d810
commit ce40de14c9
1 changed files with 28 additions and 0 deletions

View File

@ -0,0 +1,28 @@
from optparse import make_option
from django.core.management.base import BaseCommand
from zephyr.models import User
import simplejson
def dump():
passwords = []
for u in User.objects.all():
passwords.append((u.email, u.password))
file("dumped-passwords", "w").write(simplejson.dumps(passwords) + "\n")
def restore(change):
for (email, password) in simplejson.loads(file("dumped-passwords").read()):
user = User.objects.get(email__iexact=email)
if change:
user.password = password
user.save()
class Command(BaseCommand):
option_list = BaseCommand.option_list + (
make_option('--restore', default=False, action='store_true'),
make_option('--dry-run', '-n', default=False, action='store_true'),)
def handle(self, *args, **options):
if options["restore"]:
restore(change=not options['dry_run'])
else:
dump()