Exemplo n.º 1
0
def create_user():
    """
    Creates a user in the database
    """
    email = prompt("Please enter your email address ?", default='*****@*****.**')

    password_match = False
    while not password_match:
        password = prompt_pass("Please enter your password ?", default='password')
        confirm_password = prompt_pass("Please confirm your password ?", default='password')
        password_match = password == confirm_password

    role = prompt_choices("Please enter your role ?",
                          choices=[role.name for role in user_datastore.role_model.query],
                          resolve=str,
                          default='user')

    first_name = prompt("Please enter your first name ?", default="user")
    last_name = prompt("Please enter your first name ?", default="name")
    user_name = prompt("Please enter your first name ?", default="uname")

    user_datastore.create_user(email=email,
                               password=encrypt_password(password),
                               roles=[role],
                               first_name=first_name.capitalize(),
                               last_name=last_name.capitalize(),
                               user_name=user_name)
    user_datastore.commit()
Exemplo n.º 2
0
def createuser(email=None, password=None, role=None):
    """Create a user"""

    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 db.session.query(Role)]
        role_name = prompt_choices("Role", choices=roles,
                                   no_choice=('none', ''))
        if role_name:
            role = get_or_create(db.session, Role, name=role_name)
        else:
            role = None
    else:
        role = get_or_create(db.session, Role, name=role)

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

    print(user)
Exemplo n.º 3
0
    def run(self):
        choices = [
            (event.id, event.name)
            for event in Event.query.filter_by(active=True).order_by(Event.start_on.desc()).all()
        ]

        event_id = prompt_choices("Select your event", choices=choices, resolve=int, default=choices[-1][0])

        event = Event.query.get(event_id)
        if not event:
            print "There is no event, we stop the procedure"
            return

        users = set()
        for talk in event.validated_talks:

            users.add(talk.user)

        with mail.connect() as conn:
            for user in users:
                msg = mail_message(
                    _('Relevant Information'),
                    recipients=[user.email],
                    templates={'txt': 'emails/last_email_for_speaker.txt'},
                    values=dict(user=user)
                )
                conn.send(msg)
Exemplo n.º 4
0
    def run(self):
        choices = [
            (event.id, event.name)
            for event in Event.query.filter_by(active=True).order_by(Event.start_on.desc()).all()
        ]

        event_id = prompt_choices("Select your event",
                                  choices=choices,
                                  resolve=int,
                                  default=choices[-1][0])

        event = Event.query.get(event_id)
        if not event:
            print "There is no event, we stop the procedure"
            return

        for idx, talk in enumerate(event.validated_talks):
            lines = []
            if talk.user.twitter:
                lines.append(talk.user.twitter)

            lines.extend([
                'The talk "%s" has been accepted, by %s' % (talk.name, talk.user.name),
                external_url_for('general.talk_show', record_id=talk.id, slug=talk.slug),
            ])
            result = ' '.join(lines)
            print len(result), result
Exemplo n.º 5
0
    def run(self):
        choices = [
            (event.id, event.name)
            for event in Event.query.filter_by(active=True).order_by(Event.start_on.desc()).all()
        ]

        event_id = prompt_choices("Select your event", choices=choices, resolve=int, default=choices[-1][0])

        event = Event.query.get(event_id)
        if not event:
            print "There is no event, we stop the procedure"
            return

        import collections
        users = collections.defaultdict(list)
        for talk in event.validated_talks:
            users[talk.user].append(TalkPresenter(talk))

        with mail.connect() as conn:
            for user, talks in users.iteritems():
                print user.name, user.email
                msg = mail_message(
                    _('Update of the schedule'),
                    recipients=[user.email],
                    templates={'txt': 'emails/update_schedule.txt'},
                    values=dict(user=user, talks=talks)
                )
                conn.send(msg)
Exemplo n.º 6
0
def createuser(email=None, password=None, role=None):
    """Create a user"""

    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 db.session.query(Role)]
        role_name = prompt_choices("Role",
                                   choices=roles,
                                   no_choice=('none', ''))
        if role_name:
            role = get_or_create(db.session, Role, name=role_name)
        else:
            role = None
    else:
        role = get_or_create(db.session, Role, name=role)

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

    print(user)
Exemplo n.º 7
0
def getrole():

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

    role = prompt_choices("role", choices=choices, resolve=int, default=1)
    print "ROLE:", role
Exemplo n.º 8
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
Exemplo n.º 9
0
def invalidate_cache(cache_name):
    """Invalidate cache of certain type e.g. brief, citation etc."""
    possible_caches = cfg['CACHED_VIEWS'].keys() + ['all']
    how_many_invalidated = 0

    if cache_name not in possible_caches:
        cache_name = prompt_choices(name="Choose cache view you want to invalidate: ", choices=possible_caches)
    if cache_name == 'all':
        click.echo('Removing all cached views...')
        how_many_invalidated = cache_manager.invalidate_all_cached_views()
        click.echo('Invalidated {count} cached views.'.format(count=how_many_invalidated))
    elif cache_name in possible_caches:
        click.echo('Removing {cache_type} view...'.format(cache_type=cache_name))
        how_many_invalidated = cache_manager.invalidate_all_certain_views(cache_name)
        click.echo('Invalidated {count} cached views.'.format(count=how_many_invalidated))
    else:
        click.echo('Chosen cached view does not exist.')
Exemplo n.º 10
0
    def run(self, validated=False, declined=False, backup=False):
        choices = [
            (event.id, event.name)
            for event in Event.query.filter_by(active=True).order_by(Event.start_on.desc()).all()
        ]

        event_id = prompt_choices("Select your event", choices=choices, resolve=int, default=choices[-1][0])

        event = Event.query.get(event_id)
        if not event:
            print "There is no event, we stop the procedure"
            return

        with mail.connect() as conn:
            for idx, talk in enumerate(event.talks):
                values = dict(talk=TalkPresenter(talk))

                msg = None
                if declined and talk.state == 'declined':
                    msg = mail_message(
                        _('Your talk has been declined!'),
                        recipients=[talk.user.email],
                        templates={'txt': 'emails/talk_declined.txt'},
                        values=values
                    )

                if validated and talk.state == 'validated' and not talk.is_backup:
                    msg = mail_message(
                        _('Congratulations, your talk has been accepted!'),
                        recipients=[talk.user.email],
                        templates={'txt': 'emails/talk_accepted.txt'},
                        values=values
                    )

                if backup and talk.state == 'validated' and talk.is_backup:
                    msg = mail_message(
                        _('Your talk has been accepted for a Backup!'),
                        recipients=[talk.user.email],
                        templates={'txt': 'emails/talk_accepted_backup.txt'},
                        values=values
                    )

                if msg:
                    print msg
                    conn.send(msg)
Exemplo n.º 11
0
def babel():
    """ to setup a new language translation.
        `pybabel init -i ./babel/messages.pot -d hospitalSystem/translations -l zh`
    """
    choices = (("update", "extract text"), ("compile",
                                            "compile the translations"))

    op = prompt_choices("operation",
                        choices=choices,
                        resolve=str,
                        default="update")
    if op == 'update':
        os.system('pybabel extract -F ./babel/babel.cfg -k lazy_gettext '
                  '-o ./babel/messages.pot hospitalSystem')
        os.system(
            'pybabel update -i ./babel/messages.pot -d hospitalSystem/translations'
        )
    elif op == 'compile':
        os.system('pybabel compile -d hospitalSystem/translations')
Exemplo n.º 12
0
    def run(self):
        choices = [
            (event.id, event.name)
            for event in Event.query.filter_by(active=True).order_by(Event.start_on.desc()).all()
        ]

        event_id = prompt_choices("Select your event", choices=choices, resolve=int, default=choices[-1][0])

        event = Event.query.get(event_id)
        if not event:
            print "There is no event, we stop the procedure"
            return

        talk = event.validated_talks[0]
        values = dict(talk=TalkPresenter(talk))
        msg = mail_message(
            _('Congratulations, your talk has been accepted!'),
            recipients=[talk.user.email],
            templates={'txt': 'emails/talk_accepted.txt'},
            values=values
        )
        print msg
Exemplo n.º 13
0
 def hello():
     print(prompt_choices(name='hello', choices=['peter', 'charlie', 'sam'], default="john"))
Exemplo n.º 14
0
 def hello():
     print(prompt_choices(name='hello', choices=['peter', 'john', 'sam']))
Exemplo n.º 15
0
def getrolesimple():

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

    role = prompt_choices("role", choices=choices, default="member")
    print "ROLE:", role