Example #1
0
def show_character(character_id):
	
	character = db.nodes.indexes.get('characters')['id'][character_id].pop()
	
	current_question = character.relationships.outgoing(['Current'])

	if len(current_question) == 0:
		attributes = character.relationships.outgoing(['Attribute'])
		return template('character', character = character.properties, attributes = [attribute.end.properties for attribute in attributes])
	
	current_question = finders.current_question(character)
	answers = current_question.relationships.outgoing(['Answer'])
	return template('character_question.tpl', character = character.properties, current_question = current_question.properties, answers = [answer.end.properties for answer in answers])
Example #2
0
def record_answer(character_id):
	given_answer = request.params['answer']
	character = finders.find_character(character_id)
	current_question = finders.current_question(character)
	answers = [answer.end for answer in current_question.relationships.outgoing(['Answer'])]
	for answer in answers:
		if answer.properties['id'] == given_answer:
			for reward_rel in answer.relationships.outgoing(['Reward']):
				reward = reward_rel.end
				character.relationships.create("Attribute", reward)

			character.relationships.outgoing(['Current']).pop().delete()
			for next_question_rel in answer.relationships.outgoing(['Next']):
				next_question = next_question_rel.end
				character.relationships	.create('Current', next_question)
				print "Next", next_question
	redirect('/character/%s' % character_id)
Example #3
0
def show_character(character_id):

    character = db.nodes.indexes.get('characters')['id'][character_id].pop()

    current_question = character.relationships.outgoing(['Current'])

    if len(current_question) == 0:
        attributes = character.relationships.outgoing(['Attribute'])
        return template(
            'character',
            character=character.properties,
            attributes=[attribute.end.properties for attribute in attributes])

    current_question = finders.current_question(character)
    answers = current_question.relationships.outgoing(['Answer'])
    return template('character_question.tpl',
                    character=character.properties,
                    current_question=current_question.properties,
                    answers=[answer.end.properties for answer in answers])
Example #4
0
def record_answer(character_id):
    given_answer = request.params['answer']
    character = finders.find_character(character_id)
    current_question = finders.current_question(character)
    answers = [
        answer.end
        for answer in current_question.relationships.outgoing(['Answer'])
    ]
    for answer in answers:
        if answer.properties['id'] == given_answer:
            for reward_rel in answer.relationships.outgoing(['Reward']):
                reward = reward_rel.end
                character.relationships.create("Attribute", reward)

            character.relationships.outgoing(['Current']).pop().delete()
            for next_question_rel in answer.relationships.outgoing(['Next']):
                next_question = next_question_rel.end
                character.relationships.create('Current', next_question)
                print "Next", next_question
    redirect('/character/%s' % character_id)