コード例 #1
0
ファイル: permissions.py プロジェクト: dodumosu/apollo
    def run(self):
        deployments = models.Deployment.objects.all()
        option = prompt_choices('Deployment',
                                [(str(i), v)
                                 for i, v in enumerate(deployments, 1)])
        g.deployment = deployments[int(option) - 1]

        roles = models.Role.objects.all()
        option = prompt_choices('Role',
                                [(str(i), v) for i, v in enumerate(roles, 1)])
        role = roles[int(option) - 1]
        all_permissions = filter(
            lambda key: isinstance(getattr(permissions, key), Permission),
            sorted(permissions.__dict__.keys()))

        all_needs = set()
        for perm in all_permissions:
            all_needs.update(getattr(permissions, perm).needs)

        presentable_needs = sorted(
            map(lambda need: need.value,
                filter(lambda need: need.method == 'action', all_needs)))

        option = prompt_choices('Permission',
                                [(str(i), v)
                                 for i, v in enumerate(presentable_needs, 1)])
        need = presentable_needs[int(option) - 1]

        services.perms.remove_action_need_from_entity(role, need)
コード例 #2
0
ファイル: permissions.py プロジェクト: nditech/elections
    def run(self):
        deployments = models.Deployment.objects.all()
        option = prompt_choices('Deployment', [
            (str(i), v) for i, v in enumerate(deployments, 1)])
        g.deployment = deployments[int(option) - 1]

        roles = models.Role.objects.all()
        option = prompt_choices('Role', [
            (str(i), v) for i, v in enumerate(roles, 1)])
        role = roles[int(option) - 1]
        all_permissions = filter(
            lambda key: isinstance(getattr(permissions, key), Permission),
            sorted(permissions.__dict__.keys()))

        all_needs = set()
        for perm in all_permissions:
            all_needs.update(getattr(permissions, perm).needs)

        presentable_needs = sorted(map(lambda need: need.value, filter(
            lambda need: need.method == 'action', all_needs)))

        option = prompt_choices('Permission', [
            (str(i), v) for i, v in enumerate(presentable_needs, 1)])
        need = presentable_needs[int(option) - 1]

        services.perms.remove_action_need_from_entity(role, need)
コード例 #3
0
    def run(self):
        deployments = models.Deployment.objects()
        option = prompt_choices('Deployment',
                                [(str(i), v)
                                 for i, v in enumerate(deployments, 1)])
        deployment = deployments[int(option) - 1]
        events = services.events.find(deployment=deployment)
        option = prompt_choices('Event',
                                [(str(i), v) for i, v in enumerate(events, 1)])
        event = events[int(option) - 1]
        roles = services.participant_roles.find(deployment=deployment)
        option = prompt_choices('Role',
                                [(str(i), v) for i, v in enumerate(roles, 1)])
        role = roles[int(option) - 1]
        forms = services.forms.find(deployment=deployment,
                                    events=event,
                                    form_type='CHECKLIST')
        option = prompt_choices('Role',
                                [(str(i), v) for i, v in enumerate(forms, 1)])
        form = forms[int(option) - 1]

        for o in services.participants.find(role=role,
                                            deployment=deployment,
                                            event=event):
            submission, _ = models.Submission.objects.get_or_create(
                form=form,
                contributor=o,
                location=o.location,
                created=event.start_date,
                deployment=event.deployment,
                event=event,
                submission_type='O')
            # hack to force creation of a master submission
            submission.master
コード例 #4
0
ファイル: submissions.py プロジェクト: JamesMura/elections
    def run(self):
        deployments = models.Deployment.objects()
        option = prompt_choices('Deployment', [
            (str(i), v) for i, v in enumerate(deployments, 1)])
        deployment = deployments[int(option) - 1]
        events = services.events.find(deployment=deployment)
        option = prompt_choices('Event', [
            (str(i), v) for i, v in enumerate(events, 1)])
        event = events[int(option) - 1]
        roles = services.participant_roles.find(deployment=deployment)
        option = prompt_choices('Role', [
            (str(i), v) for i, v in enumerate(roles, 1)])
        role = roles[int(option) - 1]
        forms = services.forms.find(
            deployment=deployment, events=event, form_type='CHECKLIST')
        option = prompt_choices('Role', [
            (str(i), v) for i, v in enumerate(forms, 1)])
        form = forms[int(option) - 1]

        for o in services.participants.find(
            role=role, deployment=deployment, event=event
        ):
            submission, _ = models.Submission.objects.get_or_create(
                form=form, contributor=o, location=o.location,
                created=event.start_date, deployment=event.deployment,
                event=event, submission_type='O')
            # hack to force creation of a master submission
            submission.master
コード例 #5
0
ファイル: submissions.py プロジェクト: nditech/elections
    def run(self):
        deployments = models.Deployment.objects()
        option = prompt_choices('Deployment', [
            (str(i), v) for i, v in enumerate(deployments, 1)])
        deployment = deployments[int(option) - 1]
        events = services.events.find(deployment=deployment)
        option = prompt_choices('Event', [
            (str(i), v) for i, v in enumerate(events, 1)])
        event = events[int(option) - 1]
        roles = services.participant_roles.find(deployment=deployment)
        option = prompt_choices('Role', [
            (str(i), v) for i, v in enumerate(roles, 1)])
        role = roles[int(option) - 1]
        forms = services.forms.find(
            deployment=deployment, events=event, form_type='CHECKLIST')
        option = prompt_choices('Form', [
            (str(i), v) for i, v in enumerate(forms, 1)])
        form = forms[int(option) - 1]
        location_types = services.location_types.find(deployment=deployment)
        option = prompt_choices('Location level', [
            (str(i), v) for i, v in enumerate(location_types, 1)])
        location_type = location_types[int(option) - 1]

        models.Submission.init_submissions(
            deployment, event, form, role, location_type)
コード例 #6
0
ファイル: permissions.py プロジェクト: nditech/elections
    def run(self):
        deployments = models.Deployment.objects.all()
        option = prompt_choices('Deployment', [
            (str(i), v) for i, v in enumerate(deployments, 1)])
        g.deployment = deployments[int(option) - 1]

        roles = models.Role.objects.all()
        option = prompt_choices('Role', [
            (str(i), v) for i, v in enumerate(roles, 1)])
        role = roles[int(option) - 1]

        for need in models.Need.objects.filter(
            entities=role, deployment=g.deployment
        ):
            print need.action
コード例 #7
0
ファイル: permissions.py プロジェクト: dodumosu/apollo
    def run(self):
        deployments = models.Deployment.objects.all()
        option = prompt_choices('Deployment',
                                [(str(i), v)
                                 for i, v in enumerate(deployments, 1)])
        g.deployment = deployments[int(option) - 1]

        roles = models.Role.objects.all()
        option = prompt_choices('Role',
                                [(str(i), v) for i, v in enumerate(roles, 1)])
        role = roles[int(option) - 1]

        for need in models.Need.objects.filter(entities=role,
                                               deployment=g.deployment):
            print need.action
コード例 #8
0
    def run(self):
        deployments = models.Deployment.objects.all()
        option = prompt_choices('Deployment',
                                [(str(i), v)
                                 for i, v in enumerate(deployments, 1)])
        deployment = deployments[int(option) - 1]
        name = prompt('Event name')
        start = end = None
        while True:
            try:
                start = datetime.strptime(prompt('Start date (YYYY-MM-DD)'),
                                          '%Y-%m-%d')
            except ValueError:
                pass
            if start:
                break
        while True:
            try:
                end = datetime.strptime(prompt('End date (YYYY-MM-DD)'),
                                        '%Y-%m-%d')
            except ValueError:
                pass
            if end:
                break

        event, _ = models.Event.objects.get_or_create(name=name,
                                                      deployment=deployment)
        event.start_date = datetime.combine(start, datetime.min.time())
        event.end_date = datetime.combine(end, datetime.max.time())
        event.save()
コード例 #9
0
    def run(self):
        email = prompt('email of user to grant visa to')
        visa_choices=[(1, 'Tier 1 (Entrepreneur) visa'),
                        (2, 'Tier 2 (General) visa'),
                            (3, 'Tier 5 (Temporary Worker)')]

        choice = prompt_choices(name='Visa type', resolve=int, choices=visa_choices)

        visa_type = visa_choices[choice-1][1]
        print("You have chosen:", visa_type)

        person = auth.AuthUser.objects(email=email).first()

        if not person:
            print('No user found for email', email)
            return

        from datetime import datetime, timedelta

        visa = registers.Visa()
        visa.issued_at = datetime.now()
        visa.expires_at = visa.issued_at + timedelta(weeks=52)
        visa.person_uri = person.person_uri
        visa.visa_type = visa_type
        visa.passport_number = self._fake_passport_number()
        visa.save()
コード例 #10
0
def createuser(nickname=None, email=None, role=None, invite=None):
	if nickname is None:
		while True:
			nickname = prompt('nickname')
			user = User.query.filter(User.nickname==nickname).first()
			if user is not None:
				if user.status == User.S_NORMAL:
					print 'nickname %s is already taken' % nickname
				else:
					active_user(user)
					return
			else:
				break

	roles = (
		(User.R_ADMIN, 'admin'),
		(User.R_MEMBER, 'member'),
		(User.R_GUEST, 'guest'),
	)

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

	user = User(nickname=unicode(nickname),
				urlname='%s_url' % nickname,
				anonyname='%s_anony' % nickname,
				email=email,
				role=role)
	user.gen_anonyname()

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

	print 'Usre created with ID', user.id
	active_user(user)
コード例 #11
0
    def run(self, name=None, email=None, password=None, role=None):
        if not name:
            name = prompt("Full Name")

        if not email:
            email = prompt("A valid email address")

        if not password:
            password = prompt_pass("Password")

        if not role:
            roles = [r.name for r in Role.objects]
            role_name = prompt_choices("Role",
                                       choices=roles,
                                       no_choice=('none', ''))
            if role_name:
                role, created = Role.objects.get_or_create(name=role_name)
            else:
                role = None
        else:
            role, created = Role.objects.get_or_create(name=role)

        if all([name, email, password]):
            user = User.createuser(name, email, password, roles=[role])
        else:
            user = "******"

        print(user)
コード例 #12
0
ファイル: users.py プロジェクト: peterayeniofficial/elections
 def run(self):
     deployments = Deployment.objects
     option = prompt_choices('Deployment', [
         (str(i), v) for i, v in enumerate(deployments, 1)])
     deployment = deployments[int(option) - 1]
     for u in users.find(deployment=deployment):
         print 'User(id=%s email=%s)' % (u.id, u.email)
コード例 #13
0
ファイル: commands.py プロジェクト: adityaU/quokka
    def run(self, name=None, email=None, password=None, role=None):
        if not name:
            name = prompt("Full Name")

        if not email:
            email = prompt("A valid email address")

        if not password:
            password = prompt_pass("Password")

        if not role:
            roles = [r.name for r in Role.objects]
            role_name = prompt_choices("Role", choices=roles,
                                       no_choice=('none', ''))
            if role_name:
                role, created = Role.objects.get_or_create(name=role_name)
            else:
                role = None
        else:
            role, created = Role.objects.get_or_create(name=role)

        if all([name, email, password]):
            user = User.objects.create(
                name=name,
                email=email,
                password=encrypt_password(password),
                active=True,
                roles=[role]
            )
        else:
            user = u"Cant create the supersuser"

        print user
コード例 #14
0
ファイル: deployments.py プロジェクト: JamesMura/elections
    def run(self):
        deployments = models.Deployment.objects.all()
        option = prompt_choices('Deployment', [
            (str(i), v) for i, v in enumerate(deployments, 1)])
        deployment = deployments[int(option) - 1]
        name = prompt('Event name')
        start = end = None
        while True:
            try:
                start = datetime.strptime(
                    prompt('Start date (YYYY-MM-DD)'), '%Y-%m-%d')
            except ValueError:
                pass
            if start:
                break
        while True:
            try:
                end = datetime.strptime(
                    prompt('End date (YYYY-MM-DD)'), '%Y-%m-%d')
            except ValueError:
                pass
            if end:
                break

        event, _ = models.Event.objects.get_or_create(
            name=name,
            deployment=deployment)
        event.start_date = datetime.combine(start, datetime.min.time())
        event.end_date = datetime.combine(end, datetime.max.time())
        event.save()
コード例 #15
0
ファイル: manager.py プロジェクト: giocalitri/adslabs
def useradd(email=None, level=None):
    """add an api user"""

    import api_user
    from adsabs.modules.user import AdsUser
    
    if not email:
        email = prompt("Enter e-mail address of Classic ADS account", "")
        if not len(email):
            sys.exit(1)
    if not level:
        level = prompt_choices("Enter developer permission level", sorted(api_user.PERMISSION_LEVELS.keys()), "basic")
        if level not in api_user.PERMISSION_LEVELS:
            sys.exit(1)
            
    user = AdsUser.from_email(email)
    if not user:
        app.logger.info("user not found")
        sys.exit(1)
        
    # first check if the user is already a dev
    user = api_user.AdsApiUser(user.user_rec)
    if user.is_developer():
        app.logger.info("User already has api access. Developer key: %s" % user.get_dev_key())
        if prompt_bool("Would you like to reset the user's permissions", False):
            user.set_perms(level)
            app.logger.info("API User permissions updated")
        return
            
    user = api_user.create_api_user(user, level)
    dev_key = user.get_dev_key()
    app.logger.info("API User created with %s permissions. Developer key: %s" % (level, dev_key))
    
    if prompt_bool("Send welcome message", True):
        sendwelcome(dev_key=dev_key, no_prompt=True)
コード例 #16
0
ファイル: users.py プロジェクト: peterayeniofficial/elections
    def run(self):
        deployments = Deployment.objects
        option = prompt_choices('Deployment', [
            (str(i), v) for i, v in enumerate(deployments, 1)])
        deployment = deployments[int(option) - 1]
        email = prompt('Email')
        password = prompt_pass('Password')
        password_confirm = prompt_pass('Confirm Password')

        can_create, form_errors = can_create_user(email, password,
                                                  password_confirm, deployment)

        if can_create:
            try:
                user = register_user(email=email, password=password)
            except socket.error as e:
                # if there's an error sending the notification email,
                # recover
                print 'Error sending confirmation email: {}'.format(e)
                user = users.get(email=email, deployment=None)
            user.update(set__deployment=deployment)
            print '\nUser created successfully'
            print 'User(id=%s email=%s)' % (user.id, user.email)
            return
        print '\nError creating user:'******'\n'.join(errors)
コード例 #17
0
    def run(self):
        deployments = models.Deployment.objects.all()
        option = prompt_choices('Deployment',
                                [(str(i), v)
                                 for i, v in enumerate(deployments, 1)])
        deployment = deployments[int(option) - 1]

        self._create_event(deployment)
コード例 #18
0
ファイル: deployments.py プロジェクト: JamesMura/elections
 def run(self):
     deployments = models.Deployment.objects.all()
     option = prompt_choices('Deployment', [
         (str(i), v) for i, v in enumerate(deployments, 1)])
     deployment = deployments[int(option) - 1]
     events = models.Event.objects(deployment=deployment)
     for event in events:
         print event.name
コード例 #19
0
 def run(self):
     deployments = models.Deployment.objects.all()
     option = prompt_choices('Deployment',
                             [(str(i), v)
                              for i, v in enumerate(deployments, 1)])
     deployment = deployments[int(option) - 1]
     events = models.Event.objects(deployment=deployment)
     for event in events:
         print event.name
コード例 #20
0
def getrole():

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

    role = prompt_choices("role", choices=choices, resolve=int, default=1)
    print "ROLE:", role
コード例 #21
0
ファイル: manage.py プロジェクト: jirikuncar/flask-script
def getrole():

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

    role = prompt_choices("role", choices=choices, resolve=int, default=1)
    print "ROLE:", role
コード例 #22
0
ファイル: manager.py プロジェクト: Movile/hecuba
    def run(self):
        """
        Prompts the user to Changes a cluster password
        """
        clusters = []
        for c in models.Cluster.query.all():
          clusters.append(c.name)

        try:
            cluster = prompt_choices("Which cluster?", clusters, resolve=str)
            password_old = prompt_pass("Enter the current cluster password", "None")

            c = models.Cluster.query.get(cluster)

            # no password provided
            if (password_old == "None"):
                # if cluster has a password, obviously deny the request
                if (c.secret is not None):
                    print "Cluster password is wrong."
                    sys.exit(1)

            if (auth.verify_password(cluster, password_old)):
                password_one = prompt_pass("Enter the new password", "None")
                password_two = prompt_pass("Confirm the new password", "None")

                if password_one == password_two:
                    # if password is None, we will remove the password, not change it
                    if (password_one == "None" and password_two == "None"):
                        if (prompt_bool("Do you want to remove the password?", True)):
                            c.secret = None
                            action = "removed"
                        else:
                            print "Password change cancelled."
                            sys.exit(1)
                    else:
                        c.secret = auth.generate_password(password_one)
                        action = "changed"

                    try:
                      db.session.commit()
                      log.info("Password for cluster %s was %s." % (cluster, action))
                    except Exception as ex:
                      log.debug(ex)
                      print "Error while changing the cluster password."
                      sys.exit(1)
                else:
                    print "Passwords don't match."
                    sys.exit(1)
            else:
                print "Cluster password is wrong."
                sys.exit(1)

        except KeyboardInterrupt:
            print "Password change cancelled."
            sys.exit(1)
コード例 #23
0
ファイル: users.py プロジェクト: peterayeniofficial/elections
 def run(self):
     deployments = Deployment.objects
     option = prompt_choices('Deployment', [
         (str(i), v) for i, v in enumerate(deployments, 1)])
     deployment = deployments[int(option) - 1]
     email = prompt('Email')
     user = users.first(email=email, deployment=deployment)
     if not user:
         print 'Invalid user'
         return
     for role in user.roles:
         print 'Role(name=%s)' % (role.name)
コード例 #24
0
ファイル: users.py プロジェクト: peterayeniofficial/elections
 def run(self):
     deployments = Deployment.objects
     option = prompt_choices('Deployment', [
         (str(i), v) for i, v in enumerate(deployments, 1)])
     deployment = deployments[int(option) - 1]
     email = prompt('Email')
     user = users.first(deployment=deployment, email=email)
     if not user:
         print 'Invalid user'
         return
     users.delete(user)
     print 'User deleted successfully'
コード例 #25
0
ファイル: manage.py プロジェクト: 04052038/newsmeme
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
コード例 #26
0
ファイル: manage.py プロジェクト: fossix/fossix_site
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
コード例 #27
0
def command_test_default(host, port):  # 有参数名称 有默认值
    msg = "host:{}\tport:{}".format(host, port)
    if prompt_bool(msg):  # 用户交互
        print "You input {}".format(msg)
        info = prompt("you name")
        print "info:{}".format(info)
        password = prompt_pass("password")
        print "password:{}".format(password)
        # China [1], USA [2])  选择 1,2
        #(key, value)
        choice = prompt_choices(u"homeland", (("1", "China"), ("2", "USA")))
        print "choice:{}".format(choice)
    else:
        print "out"
コード例 #28
0
    def run(self):
        scopes = []
        service_name = prompt('Service name')
        service_description = prompt('Description')
        organisation_type = prompt_choices(name='Organisation type', resolve=resolve_choice, choices=['central government', 'local government', 'devolved government', 'non-profit', 'commercial'])
        redirect_uri = prompt('OAuth redirect URI')
        for scope in registers.avaliable_scopes:
            if prompt_bool("Register for %s (%s)?" % (scope, registers.avaliable_scopes[scope].lower())):
                scopes.append(scope)

        client = auth.AuthClient.register_service(service_name, service_description, scopes, redirect_uri, organisation_type)

        print("You client ID is: %s" % client.client_id)
        print("You client secret is: %s" % client.client_secret)
コード例 #29
0
ファイル: users.py プロジェクト: peterayeniofficial/elections
 def run(self):
     deployments = Deployment.objects
     option = prompt_choices('Deployment', [
         (str(i), v) for i, v in enumerate(deployments, 1)])
     deployment = deployments[int(option) - 1]
     email = prompt('Email')
     user = users.first(email=email, deployment=deployment)
     role_name = prompt('Role')
     role = Role.objects(name=role_name).first()
     if not user:
         print 'Invalid user'
         return
     if not role:
         print 'Invalid role'
         return
     user.update(add_to_set__roles=role)
     print 'Role added to User successfully'
コード例 #30
0
ファイル: manager.py プロジェクト: yunlzheng/dashbord
def createuser(email=None, password=None, nickname=None, role=None):
    if email is None:
        while True:
            email = prompt("Email address")
            user = User.query.filter_by(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

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

    roles = (
        (0, "member"),
        (1, "admin")
    )

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

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

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

    print "User created with ID", user.id
コード例 #31
0
 def hello():
     print(
         prompt_choices(name='hello', choices=['peter', 'john', 'sam']))
コード例 #32
0
ファイル: console.py プロジェクト: johnvey/flask-tool
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 "###################"
コード例 #33
0
def getrolesimple():

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

    role = prompt_choices("role", choices=choices, default="member")
    print "ROLE:", role
コード例 #34
0
ファイル: manage.py プロジェクト: jirikuncar/flask-script
def getrolesimple():

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

    role = prompt_choices("role", choices=choices, default="member")
    print "ROLE:", role
コード例 #35
0
ファイル: tests.py プロジェクト: raizyr/flask-script
 def hello():
     print(prompt_choices(name='hello', choices=['peter', 'john', 'sam']))
コード例 #36
0
    def run(self):
        deployments = models.Deployment.objects.all()
        option = prompt_choices('Deployment',
                                [(str(i), v)
                                 for i, v in enumerate(deployments, 1)])
        deployment = deployments[int(option) - 1]

        events = models.Event.objects(deployment=deployment)
        option = prompt_choices('Source event',
                                [(str(i), v) for i, v in enumerate(events, 1)])
        source_event = events[int(option) - 1]

        reduced_events = events(pk__ne=source_event.pk)
        option = prompt_choices('Destination event',
                                [(str(i), v)
                                 for i, v in enumerate(reduced_events, 1)])
        dest_event = reduced_events[int(option) - 1]

        print '--- AVAILABLE FORMS ---'
        forms = models.Form.objects(deployment=deployment)
        for i, f in enumerate(forms, 1):
            print '{} [{}]'.format(f.name, i)

        form_indexes = raw_input('Enter forms to copy, separated by commas: ')
        indexes = [
            int(i.strip()) for i in form_indexes.split(',')
            if i.strip().isdigit()
        ]

        copy_participants = False
        while True:
            response = raw_input(
                'Copy participants from source to destination (yes/no)? ')
            response = response.lower()
            if response[0] == 'y':
                copy_participants = True
                break
            elif response[0] == 'n':
                break

        for index in indexes:
            form = forms[index - 1]
            data = loads(form.to_json())
            data.pop('_id')
            new_form = models.Form.from_json(dumps(data))
            new_form.events = [dest_event]
            new_form.save()
            form.update(pull__events=dest_event)

        # copy participant data
        if copy_participants:
            participants = models.Participant.objects(deployment=deployment,
                                                      event=source_event)
            supervisor_map = {
                p.participant_id: p.supervisor.participant_id
                for p in participants if p.supervisor
            }
            for participant in participants:
                data = loads(participant.to_json())
                data.pop('_id')
                data.pop('supervisor', None)
                new_participant = models.Participant.from_json(dumps(data))
                new_participant.accurate_message_count = 0
                new_participant.message_count = 0
                new_participant.event = dest_event
                new_participant.save()

            for p_id, sup_id in supervisor_map.iteritems():
                participant = models.Participant.objects.get(
                    deployment=deployment,
                    event=dest_event,
                    participant_id=p_id)
                supervisor = models.Participant.objects.get(
                    deployment=deployment,
                    event=dest_event,
                    participant_id=sup_id)
                participant.update(set__supervisor=supervisor)
コード例 #37
0
ファイル: tests.py プロジェクト: raizyr/flask-script
 def hello():
     print(prompt_choices(name='hello', choices=['peter', 'charlie', 'sam'], default="john"))
コード例 #38
0
 def hello():
     print(
         prompt_choices(name='hello',
                        choices=['peter', 'charlie', 'sam'],
                        default="john"))