예제 #1
0
파일: views.py 프로젝트: imankulov/trytry
def get_task(request, flow_name):
    flow = _get_flow(request, flow_name)
    if flow is None:
        flow = create_flow('trytry.{0}.steps'.format(flow_name))
        flow.setup_flow()
        request.session['{0}_flow_id'.format(flow_name)] = flow.id
    command_result = {}
    if request.method == 'POST':
        data = request.POST.copy()
        # navigate through steps
        if data.get('navigate'):
            if data['navigate'] == 'prev':
                flow.current_step = flow.get_prev_step_name()
                flow.state = 'active'
            elif data['navigate'] == 'next':
                current_step = flow.get_next_step_name()
                if current_step is None:
                    flow.state = 'complete'
                else:
                    flow.current_step = current_step
                    flow.state = 'active'
            flow.save()
        if data.get('command'):
            command_result = flow.apply(data.get('command'))
            if flow.state == 'complete':
                flow.teardown_flow()
    result = {
        'task': flow.get_task(),
        'id': flow.id,
        'progress': get_progress(flow),
        'flow_name': str(flow),
        'step_prompt': flow.get_prompt()
    }
    result.update(command_result)
    return wrap_json(result)
예제 #2
0
파일: views.py 프로젝트: imankulov/trytry
def get_status(request, flow_id):
    flow = _get_flow(request, None, id=flow_id)
    if flow is None:
        return redirect('/')
    session_key = '{0}_flow_id'.format(flow.get_flow_settings().url)
    session_value = request.session.get(session_key)
    if flow.state in ('destroyed', 'complete') and session_value == flow.id:
        del request.session[session_key]

    log_list = flow.log_set.all().order_by('timestamp')
    template = 'core/status.html'
    return render(request, template, {'log_list': log_list, 'progress': get_progress(flow)})