[minor] add system manager in wnf

This commit is contained in:
Anand Doshi 2013-10-07 19:24:17 +05:30
parent 08bb06fab5
commit 7e4232e738
3 changed files with 28 additions and 5 deletions

View file

@ -274,8 +274,7 @@ Thank you,<br>
email = email.strip()
if not validate_email_add(email):
webnotes.msgprint("%s is not a valid email id" % email)
raise Exception
webnotes.throw("%s is not a valid email id" % email)
def add_roles(self, *roles):
for role in roles:

View file

@ -5,7 +5,6 @@
from __future__ import unicode_literals
import webnotes
import webnotes.widgets.reportview
import webnotes.widgets.query_builder
from webnotes.utils import cstr
try:

29
wnf.py
View file

@ -89,6 +89,8 @@ def setup_install(parser):
help="Install demo in demo_db_name specified in conf.py")
parser.add_argument("--make_demo_fresh", default=False, action="store_true",
help="(Re)Install demo in demo_db_name specified in conf.py")
parser.add_argument("--add_system_manager", nargs="+",
metavar=("EMAIL", "[FIRST-NAME] [LAST-NAME]"), help="Add a user with all roles")
def setup_utilities(parser):
# update
@ -214,6 +216,28 @@ def install_fixtures(site=None):
from webnotes.install_lib.install import install_fixtures
install_fixtures()
@cmd
def add_system_manager(email, first_name=None, last_name=None, site=None):
webnotes.connect(site=site)
# add profile
profile = webnotes.new_bean("Profile")
profile.doc.fields.update({
"name": email,
"email": email,
"enabled": 1,
"first_name": first_name or email,
"last_name": last_name
})
profile.insert()
# add roles
roles = webnotes.conn.sql_list("""select name from `tabRole`
where name not in ("Administrator", "Guest", "All")""")
profile.make_controller().add_roles(*roles)
webnotes.conn.commit()
@cmd
def make_demo(site=None):
import utilities.demo.make_demo
@ -294,11 +318,12 @@ def watch():
webnotes.build.watch(True)
@cmd
def backup(site=None, with_files=False):
def backup(site=None, with_files=False, verbose=True):
from webnotes.utils.backups import scheduled_backup
webnotes.connect(site=site)
odb = scheduled_backup(ignore_files=not with_files)
if __name__ == "__main__":
if verbose:
from webnotes.utils import now
print "backup taken -", odb.backup_path_db, "- on", now()
return odb