mirror of
https://github.com/wassname/flask-security.git
synced 2026-09-09 11:22:35 +08:00
Update script.py for Python 2's print statement vs. Python 3's function.
This commit is contained in:
@@ -8,6 +8,8 @@
|
|||||||
:copyright: (c) 2012 by Matt Wright.
|
:copyright: (c) 2012 by Matt Wright.
|
||||||
:license: MIT, see LICENSE for more details.
|
:license: MIT, see LICENSE for more details.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@@ -26,7 +28,7 @@ _datastore = LocalProxy(lambda: current_app.extensions['security'].datastore)
|
|||||||
|
|
||||||
|
|
||||||
def pprint(obj):
|
def pprint(obj):
|
||||||
print json.dumps(obj, sort_keys=True, indent=4)
|
print(json.dumps(obj, sort_keys=True, indent=4))
|
||||||
|
|
||||||
|
|
||||||
def commit(fn):
|
def commit(fn):
|
||||||
@@ -59,11 +61,11 @@ class CreateUserCommand(Command):
|
|||||||
if form.validate():
|
if form.validate():
|
||||||
kwargs['password'] = encrypt_password(kwargs['password'])
|
kwargs['password'] = encrypt_password(kwargs['password'])
|
||||||
_datastore.create_user(**kwargs)
|
_datastore.create_user(**kwargs)
|
||||||
print 'User created successfully.'
|
print('User created successfully.')
|
||||||
kwargs['password'] = '****'
|
kwargs['password'] = '****'
|
||||||
pprint(kwargs)
|
pprint(kwargs)
|
||||||
else:
|
else:
|
||||||
print 'Error creating user'
|
print('Error creating user')
|
||||||
pprint(form.errors)
|
pprint(form.errors)
|
||||||
|
|
||||||
|
|
||||||
@@ -78,7 +80,7 @@ class CreateRoleCommand(Command):
|
|||||||
@commit
|
@commit
|
||||||
def run(self, **kwargs):
|
def run(self, **kwargs):
|
||||||
_datastore.create_role(**kwargs)
|
_datastore.create_role(**kwargs)
|
||||||
print 'Role "%(name)s" created successfully.' % kwargs
|
print('Role "%(name)s" created successfully.' % kwargs)
|
||||||
|
|
||||||
|
|
||||||
class _RoleCommand(Command):
|
class _RoleCommand(Command):
|
||||||
@@ -94,7 +96,7 @@ class AddRoleCommand(_RoleCommand):
|
|||||||
@commit
|
@commit
|
||||||
def run(self, user_identifier, role_name):
|
def run(self, user_identifier, role_name):
|
||||||
_datastore.add_role_to_user(user_identifier, role_name)
|
_datastore.add_role_to_user(user_identifier, role_name)
|
||||||
print "Role '%s' added to user '%s' successfully" % (role_name, user_identifier)
|
print("Role '%s' added to user '%s' successfully" % (role_name, user_identifier))
|
||||||
|
|
||||||
|
|
||||||
class RemoveRoleCommand(_RoleCommand):
|
class RemoveRoleCommand(_RoleCommand):
|
||||||
@@ -103,7 +105,7 @@ class RemoveRoleCommand(_RoleCommand):
|
|||||||
@commit
|
@commit
|
||||||
def run(self, user_identifier, role_name):
|
def run(self, user_identifier, role_name):
|
||||||
_datastore.remove_role_from_user(user_identifier, role_name)
|
_datastore.remove_role_from_user(user_identifier, role_name)
|
||||||
print "Role '%s' removed from user '%s' successfully" % (role_name, user_identifier)
|
print("Role '%s' removed from user '%s' successfully" % (role_name, user_identifier))
|
||||||
|
|
||||||
|
|
||||||
class _ToggleActiveCommand(Command):
|
class _ToggleActiveCommand(Command):
|
||||||
@@ -118,7 +120,7 @@ class DeactivateUserCommand(_ToggleActiveCommand):
|
|||||||
@commit
|
@commit
|
||||||
def run(self, user_identifier):
|
def run(self, user_identifier):
|
||||||
_datastore.deactivate_user(user_identifier)
|
_datastore.deactivate_user(user_identifier)
|
||||||
print "User '%s' has been deactivated" % user_identifier
|
print("User '%s' has been deactivated" % user_identifier)
|
||||||
|
|
||||||
|
|
||||||
class ActivateUserCommand(_ToggleActiveCommand):
|
class ActivateUserCommand(_ToggleActiveCommand):
|
||||||
@@ -127,4 +129,4 @@ class ActivateUserCommand(_ToggleActiveCommand):
|
|||||||
@commit
|
@commit
|
||||||
def run(self, user_identifier):
|
def run(self, user_identifier):
|
||||||
_datastore.activate_user(user_identifier)
|
_datastore.activate_user(user_identifier)
|
||||||
print "User '%s' has been activated" % user_identifier
|
print("User '%s' has been activated" % user_identifier)
|
||||||
|
|||||||
Reference in New Issue
Block a user