示例#1
0
文件: sites.py 项目: aspc/piccolo
def adduser(args):
    logger.debug("add user " + args.username + " to " + args.shortname + " from console")
    thesite = Site.get(args.shortname)
    theuser = User.get(args.username)
    if not thesite:
        logger.error("No site named {0} exists".format(args.shortname))
    if not theuser:
        logger.error("No user named {0} exists".format(args.username))
    if thesite and theuser:
        try:
            thesite.addUser(theuser, suppress_welcome=args.no_email)
        except Site.AlreadyHasUser:
            logger.info("{0} is already an administrator of {1}".format(args.username, args.shortname))
        except ShellActionFailed:
            logger.exception("Could not create {0} because shell actions failed. See log for details.".format(args.username))
示例#2
0
文件: sites.py 项目: aspc/piccolo
def removeuser(args):
    logger.debug("remove user" + args.username + " from " + args.shortname + " from console")
    thesite = Site.get(args.shortname)
    theuser = User.get(args.username)
    if not thesite:
        logger.error("No site named {0} exists".format(args.shortname))
    if not theuser:
        logger.error("No user named {0} exists".format(args.username))
    if thesite and theuser:
        try:
            thesite.removeUser(theuser)
        except Site.NoSuchUser:
            logger.info("User {0} is not an administrator of {1}".format(
                theuser.username,
                thesite.shortname
            ))
        except ShellActionFailed as e:
            logger.exception("Could not remove {0} from {1} because shell actions failed. User remains in Site in DB.".format(
                theuser.username,
                thesite.shortname,
            ))