Beispiel #1
0
def getrole():

    choices = (
        (1, "member"),
        (2, "moderator"),
        (3, "admin"),
    )

    role = prompt_choices("role", choices=choices, resolve=int, default=1)
    print "ROLE:", role
Beispiel #2
0
def createuser(username=None, password=None, email=None, role=None):
    """
    Create a new user
    """

    if username is None:
        while True:
            username = prompt("Username")
            user = User.query.filter(User.username==username).first()
            if user is not None:
                print "Username %s is already taken" % username
            else:
                break

    if email is None:
        while True:
            email = prompt("Email address")
            user = User.query.filter(User.email==email).first()
            if user is not None:
                print "Email %s is already taken" % email
            else:
                break

    if password is None:
        password = prompt_pass("Password")

        while True:
            password_again = prompt_pass("Password again")
            if password != password_again:
                print "Passwords do not match"
            else:
                break

    roles = (
        (User.MEMBER, "member"),
        (User.MODERATOR, "moderator"),
        (User.ADMIN, "admin"),
    )

    if role is None:
        role = prompt_choices("Role", roles, resolve=int, default=User.MEMBER)

    user = User(username=username,
                email=email,
                password=password,
                role=role)

    db.session.add(user)
    db.session.commit()

    print "User created with ID", user.id
Beispiel #3
0
def createuser(username=None, password=None, email=None, role=None):
    """
    Create a new user
    """
    
    if username is None:
        while True:
            username = prompt("Username")
            user = User.query.filter(User.username==username).first()
            if user is not None:
                print "Username %s is already taken" % username
            else:
                break

    if email is None:
        while True:
            email = prompt("Email address")
            user = User.query.filter(User.email==email).first()
            if user is not None:
                print "Email %s is already taken" % email
            else:
                break

    if password is None:
        password = prompt_pass("Password")

        while True:
            password_again = prompt_pass("Password again")
            if password != password_again:
                print "Passwords do not match"
            else:
                break
    
    roles = (
        (User.MEMBER, "member"),
        (User.MODERATOR, "moderator"),
        (User.ADMIN, "admin"),
    )

    if role is None:
        role = prompt_choices("Role", roles, resolve=int, default=User.MEMBER)

    user = User(username=username,
                email=email,
                password=password,
                role=role)

    db.session.add(user)
    db.session.commit()

    print "User created with ID", user.id
Beispiel #4
0
def add_address(**values):
    domain = prompt_choices("Domain (%s@DOMAIN)" % values['username'], (d.name for d in Domain.query.order_by('-name')))
    passwd = prompt_pass("Password")
Beispiel #5
0
def create(what="app", name="MyAwesomeApp", layout="factory"):
    """(ext|app) <name>"""
    """
    flasktool create ext 'Flask-MongoEngine'

    flasktool create app MyAwesomeApp
    flasktool create app MyAwesomeApp --layout=factory
        - Create new folder.
        - Make app.yaml and  add to new folder.
        - Look at layout for template to use.
        - cd to new app directory
        - Create tasks, settings, etc.

    flasktool create view account
    flasktool create view api.account
        - Check we're in an app and load app yaml.
        - Default view imports in app.yaml
        - Create tests.views.test_account.py

    flasktool create view api.account
        - Check we're in an app and load app yaml.

    flasktool create model Account
        - Check we're in an app and load app yaml.
        - Create models.account.py.
        - Create tests.models.account.py
    """
    what = what[0]
    name = name[0]
    if what == "app":
        _app = FlaskApplication(name, layout=layout)
        _app.bootstrap()

        print "###################"
        print "Your new Flask app is ready!"
        print "###################"
        print "What to do now:"
        print "- cd %s" % name
        print "- Run ./manage.py runserver"
        print "- Write your app and tests"
        print "- Check in your code"
        print "- setup an EC2 instance"
        print "- Add credentials and hosts to fabfile.py"
        print "- Run fab deploy"
        print "- ???????"
        print "- Profit!"

    elif what == "ext":
        if not url:
            url = prompt("URL")

        if not author_name:
            author_name = prompt("Author Name")

        if not author_email:
            author_email = prompt("Author Email")

        license = prompt_choices("License", ("BSD", "MIT", "WTFPL"), default="BSD", resolve=string.upper)

        if not short_description:
            short_description = prompt("Short Description")

        if not requires:
            requires = prompt("Dependencies (comma separated, exclude Flask)")

        extension = FlaskExtension(name, url, author_name, author_email, short_description, requires, license)

        print "###################"
        print "Makin' the donuts..."
        print "###################"
        extension.boostrap()
        print "###################"
        print "Flask-%s created in %s" % (extension.name, extension.dir)
        print "###################"
Beispiel #6
0
def getrolesimple():

    choices = ("member", "moderator", "admin")

    role = prompt_choices("role", choices=choices, default="member")
    print "ROLE:", role
Beispiel #7
0
def create(what='app', name='MyAwesomeApp', layout='factory'):
    """(ext|app) <name>  # create an app or extension"""
    """
    flasktool create ext 'Flask-MongoEngine'

    flasktool create app MyAwesomeApp
    flasktool create app MyAwesomeApp --layout=factory
        - Create new folder.
        - Make app.yaml and  add to new folder.
        - Look at layout for template to use.
        - cd to new app directory
        - Create tasks, settings, etc.

    flasktool create view account
    flasktool create view api.account
        - Check we're in an app and load app yaml.
        - Default view imports in app.yaml
        - Create tests.views.test_account.py

    flasktool create view api.account
        - Check we're in an app and load app yaml.

    flasktool create model Account
        - Check we're in an app and load app yaml.
        - Create models.account.py.
        - Create tests.models.account.py
    """
    what = what[0]
    name = name[0]
    if what == 'app':
        _app = FlaskApplication(name, layout=layout)
        _app.bootstrap()

        print whatnext % {'name':name}
    
    elif what == 'ext':
        if not url:
            url = prompt('URL')
        
        if not author_name:
            author_name = prompt('Author Name')
        
        if not author_email:
            author_email = prompt('Author Email')
        
        license = prompt_choices('License', ('BSD','MIT','WTFPL'), 
            default='BSD', resolve=string.upper)
            
        if not short_description:
            short_description = prompt('Short Description')
        
        if not requires:
            requires = prompt('Dependencies (comma separated, exclude Flask)')
            
        extension = FlaskExtension(name, url, author_name, author_email, 
            short_description, requires, license)

        print "###################"
        print "Makin' the donuts..."
        print "###################"
        extension.boostrap()
        print "###################"
        print "Flask-%s created in %s" % (extension.name, extension.dir)
        print "###################"