Ejemplo n.º 1
0
def next():

    # Redirects to another template view
    experiment = app.get_next(session)
    if experiment is not None:
        app.logger.info('Next experiment is %s' % experiment)
    return perform_checks('/experiments/%s' % experiment, do_redirect=True)
Ejemplo n.º 2
0
def next():

    # Headless mode requires logged in user with token
    if app.headless and "token" not in session:
        return headless_denied()

    # To generate redirect to experiment
    experiment = app.get_next(session)

    if experiment is not None:
        app.logger.debug('Next experiment is %s' % experiment)
        template = '/experiments/%s' % experiment

        # Do we have runtime variables?
        token = session.get('token')
        if app.vars is not None:
            variables = get_runtime_vars(token=token,
                                         varset=app.vars,
                                         experiment=experiment)
            template = "%s?%s" % (template, variables)

        return perform_checks(template=template,
                              do_redirect=True,
                              next=experiment)

    return redirect('/finish')
Ejemplo n.º 3
0
def next():

    # Headless mode requires logged in user with token
    if app.headless and "token" not in session:
        return headless_denied()

    # To generate redirect to experiment
    experiment = app.get_next(session)
 
    if experiment is not None:
        app.logger.debug('Next experiment is %s' % experiment)
        template = '/experiments/%s' % experiment

        # Do we have runtime variables?
        token = session.get('token')
        if app.vars is not None:
            variables = get_runtime_vars(token=token,
                                         varset=app.vars,
                                         experiment=experiment)
            template = "%s?%s" %(template, variables)

        return perform_checks(template=template,
                              do_redirect=True,
                              next=experiment)

    return redirect('/finish')
Ejemplo n.º 4
0
def perform_checks(template,
                   do_redirect=False,
                   context=None,
                   next=None,
                   quiet=False):
    """return all checks for required variables before returning to 
       desired view

       Parameters
       ==========
       template: the html template to render
       do_redirect: if True, perform a redirect and not render
       context: dictionary of context variables to pass to render_template
       next: a pre-defined next experiment, will calculate if None
       quiet: decrease verbosity

    """
    from expfactory.server import app

    username = session.get("username")
    subid = session.get("subid")

    # If redirect, "last" is currently active (about to start)
    # If render, "last" is last completed / active experiment (just finished)
    last = session.get("exp_id")
    if next is None:
        next = app.get_next(session)
    session["exp_id"] = next

    # Headless mode requires token
    if "token" not in session and app.headless is True:
        flash("A token is required for these experiments.")
        return redirect("/")

    # Update the user / log
    if quiet is False:
        app.logger.info("[router] %s --> %s [subid] %s [user] %s" %
                        (last, next, subid, username))

    if username is None and app.headless is False:
        flash("You must start a session before doing experiments.")
        return redirect("/")

    if subid is None:
        flash(
            "You must have a participant identifier before doing experiments")
        return redirect("/")

    if next is None:
        flash("Congratulations, you have finished the battery!")
        return redirect("/finish")

    if do_redirect is True:
        app.logger.debug("Redirecting to %s" % template)
        return redirect(template)

    if context is not None and isinstance(context, dict):
        app.logger.debug("Rendering %s" % template)
        return render_template(template, **context)
    return render_template(template)
Ejemplo n.º 5
0
def perform_checks(template,
                   do_redirect=False,
                   context=None,
                   next=None,
                   quiet=False):
    '''return all checks for required variables before returning to 
       desired view
    '''
    from expfactory.server import app
    username = session.get('username')
    subid = session.get('subid')

    # If redirect, "last" is currently active (about to start)
    # If render, "last" is last completed / active experiment (just finished)
    last = session.get('exp_id')
    if next is None:
        next = app.get_next(session)
    session['exp_id'] = next

    # Headless mode requires token
    if "token" not in session and app.headless is True:
        flash('A token is required for these experiments.')
        return redirect('/')

    # Update the user / log
    if quiet is False:
        app.logger.info("[router] %s --> %s for [subid] %s [username] %s" %
                        (last, next, subid, username))

    if username is None and app.headless is False:
        flash('You must start a session before doing experiments.')
        return redirect('/')

    if subid is None:
        flash(
            'You must have a participant identifier before doing experiments')
        return redirect('/')

    if next is None:
        flash('Congratulations, you have finished the battery!')
        return redirect('/finish')

    if do_redirect is True:
        app.logger.debug('Redirecting to %s' % template)
        return redirect(template)

    if context is not None and isinstance(context, dict):
        app.logger.debug('Rendering %s' % template)
        return render_template(template, **context)
    return render_template(template)
Ejemplo n.º 6
0
def next():

    # Headless mode requires logged in user with token
    if app.headless and "token" not in session:
        return headless_denied()

    # To generate redirect to experiment
    experiment = app.get_next(session)

    if experiment is not None:
        app.logger.debug('Next experiment is %s' % experiment)
        return perform_checks('/experiments/%s' % experiment,
                              do_redirect=True,
                              next=experiment)

    return redirect('/finish')
Ejemplo n.º 7
0
def perform_checks(template, do_redirect=False, context=None):
    '''return all checks for required variables before returning to 
       desired view
    '''
    from expfactory.server import app

    bot.debug('Performing checks...')
    username = session.get('username')
    subid = session.get('subid')
    last = session.get('exp_id')
    next = app.get_next(session)
    session['exp_id'] = next

    # Update the user / log
    app.logger.info("<current:%s><next:%s> for <%s, %s>" %
                    (last, next, subid, username))

    if username is None:
        flash('You must start a session before doing experiments.')
        return redirect('/')

    if subid is None:
        flash(
            'You must have a participant identifier before doing experiments')
        return redirect('/')

    if next is None:
        flash('Congratulations, you have finished the battery!')
        return redirect('/finish')

    if do_redirect is True:
        return redirect(template)

    if context is not None and isinstance(context, dict):
        return render_template(template, **context)
    return render_template(template)
Ejemplo n.º 8
0
def perform_checks(template,
                   do_redirect=False,
                   context=None,
                   next=None,
                   quiet=False):

    '''return all checks for required variables before returning to 
       desired view

       Parameters
       ==========
       template: the html template to render
       do_redirect: if True, perform a redirect and not render
       context: dictionary of context variables to pass to render_template
       next: a pre-defined next experiment, will calculate if None
       quiet: decrease verbosity

    '''
    from expfactory.server import app
    username = session.get('username')
    subid = session.get('subid')

    # If redirect, "last" is currently active (about to start)
    # If render, "last" is last completed / active experiment (just finished)
    last = session.get('exp_id')
    if next is None:
        next = app.get_next(session)
    session['exp_id'] = next

    # Headless mode requires token
    if "token" not in session and app.headless is True:
        flash('A token is required for these experiments.')
        return redirect('/')

    # Update the user / log
    if quiet is False:
        app.logger.info("[router] %s --> %s [subid] %s [user] %s" %(last,
                                                                    next, 
                                                                    subid,
                                                                    username))

    if username is None and app.headless is False:
        flash('You must start a session before doing experiments.')
        return redirect('/')

    if subid is None:
        flash('You must have a participant identifier before doing experiments')
        return redirect('/')

    if next is None:
        flash('Congratulations, you have finished the battery!')
        return redirect('/finish')

    if do_redirect is True:
        app.logger.debug('Redirecting to %s' %template)
        return redirect(template)

    if context is not None and isinstance(context, dict):
        app.logger.debug('Rendering %s' %template)
        return render_template(template, **context)
    return render_template(template)