Exemplo n.º 1
0
def answer(flow_id, question_id, answer_id):

    flow_start = finders.find_flow(flow_id)

    if flow_start == None:
        abort(404, 'That flow is unrecognised')

    question = finders.find_question(flow_id, question_id)

    if question == None:
        abort(404, 'That question is unrecognised')

    answers = [
        answer.end for answer in question.relationships.outgoing(['Answer'])
        if answer.end.properties['id'] == answer_id
    ]

    if not len(answers) == 1:
        abort(404, 'Answer not found')

    answer = answers[0]

    next_questions = answer.relationships.outgoing(['Next'])

    if not next_questions:
        return template('conclusion')

    next_question_id = next_questions[0].end['id']

    return redirect('/flow/%s/question/%s' % (flow_id, next_question_id))
Exemplo n.º 2
0
def start(flow_id):
	from uuid import uuid4
	flow_start = find_flow(flow_id)
	
	if flow_start == None:
		abort(404, 'That flow is unrecognised')
		
	first_question = [rel.end for rel in flow_start.relationships.outgoing(['First'])]
	
	if len(first_question) == 0:
		abort(404, 'The flow has no first question identified')
		
	first_question = first_question[0]
	
	character_id = uuid4().hex
	new_character = db.nodes.create(id = character_id)
	
	flow_start.relationships.create("Character", new_character)
	
	new_character.relationships.create("Current", first_question)
	
	if not 'characters' in db.nodes.indexes:
		db.nodes.indexes.create('characters')
		
	db.nodes.indexes.get('characters').add('id', character_id, new_character)
	
	redirect('/character/%s' % character_id)
Exemplo n.º 3
0
def question(flow_id, question_id):
    def next_question(answer):
        decorated_answer = answer.properties
        decorated_answer['next'] = answer.relationships.outgoing(
            ['Next'])[0].end.properties
        return decorated_answer

    flow_start = finders.find_flow(flow_id)

    if flow_start == None:
        abort(404, 'That flow is unrecognised')

    question = finders.find_question(flow_id, question_id)

    if question == None:
        abort(404, 'That question is unrecognised')

    answers = [
        answer.end for answer in question.relationships.outgoing(['Answer'])
    ]

    answers = [
        answer.properties if not answer.relationships.outgoing(['Next']) else
        next_question(answer) for answer in answers
    ]

    return template('question',
                    flow=flow_start,
                    question=question,
                    answers=answers)
Exemplo n.º 4
0
def start(flow_id):
    from uuid import uuid4
    flow_start = finders.find_flow(flow_id)

    if flow_start == None:
        abort(404, 'That flow is unrecognised')

    first_question = [
        rel.end for rel in flow_start.relationships.outgoing(['First'])
    ]

    if len(first_question) == 0:
        abort(404, 'The flow has no first question identified')

    first_question = first_question[0]

    character_id = uuid4().hex
    new_character = db.nodes.create(id=character_id)

    flow_start.relationships.create("Character", new_character)

    new_character.relationships.create("Current", first_question)

    if not 'characters' in db.nodes.indexes:
        db.nodes.indexes.create('characters')

    db.nodes.indexes.get('characters').add('id', character_id, new_character)

    redirect('/character/%s' % character_id)
Exemplo n.º 5
0
def answer(flow_id, question_id, answer_id):

	flow_start = finders.find_flow(flow_id)

	if flow_start == None:
		abort(404, 'That flow is unrecognised')

	question = finders.find_question(flow_id, question_id)

	if question == None:
		abort(404, 'That question is unrecognised')

	answers = [answer.end for answer in question.relationships.outgoing(['Answer']) if answer.end.properties['id'] == answer_id]
	
	if not len(answers) == 1:
		abort(404, 'Answer not found')

	answer = answers[0]
	
	next_questions = answer.relationships.outgoing(['Next'])
	
	if not next_questions:
		return template('conclusion')
	
	next_question_id = next_questions[0].end['id']
	
	return redirect('/flow/%s/question/%s' % (flow_id, next_question_id))
Exemplo n.º 6
0
def flows(id):
	flow_start = find_flow(id)
	
	if flow_start == None:
		abort(404, 'That flow is unrecognised')

	questions = [rel.end.properties for rel in flow_start.relationships.outgoing(['Question'])]
		
	return template('questionnaire', questionnaire = flow_start, questions = questions)
Exemplo n.º 7
0
def flows(id):
    flow_start = finders.find_flow(id)

    if flow_start == None:
        abort(404, 'That flow is unrecognised')

    questions = [
        rel.end.properties
        for rel in flow_start.relationships.outgoing(['Question'])
    ]

    return template('questionnaire',
                    questionnaire=flow_start,
                    questions=questions)
Exemplo n.º 8
0
def question(flow_id, question_id):
	
	flow_start = find_flow(flow_id)
	
	if flow_start == None:
		abort(404, 'That flow is unrecognised')
	
	question = find_question(flow_id, question_id)
		
	if question == None:
		abort(404, 'That question is unrecognised')

	answers = [answer.end.properties for answer in question.relationships.outgoing(['Answer'])]
	
	return template('question', flow = flow_start, question = question, answers = answers)
Exemplo n.º 9
0
def question(flow_id, question_id):
	def next_question(answer):
		decorated_answer = answer.properties
		decorated_answer['next'] = answer.relationships.outgoing(['Next'])[0].end.properties
		return decorated_answer
	
	flow_start = finders.find_flow(flow_id)
	
	if flow_start == None:
		abort(404, 'That flow is unrecognised')
	
	question = finders.find_question(flow_id, question_id)
		
	if question == None:
		abort(404, 'That question is unrecognised')

	answers = [answer.end for answer in question.relationships.outgoing(['Answer'])]
	
	answers = [answer.properties if not answer.relationships.outgoing(['Next']) else next_question(answer) for answer in answers]
	
	return template('question', flow = flow_start, question = question, answers = answers)