def main():
	global name
    	if request.method == 'GET':
		if name == "":
			titles = database.getStories()
			return render_template('Storynator.html', selected = False, titles = titles)
		else:
			title = database.getTitle(name)
      			lines = database.getLines(name)
      			titles = database.getStories()
      			return render_template('Storynator.html', selected = True, title = title, titles = titles, lines = lines)
	else:	
		button = request.form['button']
		
		if button == 'go':
			name = request.form['story']
			return redirect('/')
		elif button == 'create':
			title = request.form['title']
        		if title:
        			database.newStory(title)
	        		return redirect('/')
	        	else: 	return redirect('/')
		elif button == 'addline':
			title = database.getTitle(name)
			line = request.form['line']
         		assert line != ""
         	        database.newLine(title,line)
         	        return redirect('/')
		elif button == 'main':
			name = ""
			return redirect('/')
def home():
    #stories=['fun', 'story', 'god']
    stories = database.getStories()
    if request.method == 'GET':
        return render_template('home.html', story = stories)
    else:
        story = request.form['story']
        button = request.form['button']
        if button == 'Go':
            #storey = 'Odessy'#request.form['storey']
            url=urllib2.quote('/story/%s'%(story))
            return redirect(url)
        elif button == 'Delete':
            #storey = request.form['story']
            database.deleteStory(story)
            return redirect(url_for('home'))
        elif button == 'New':
            return redirect(url_for('newStory'))
        return redirect(url_for('home'))


    #stories = database.getStories()
    return render_template('home', story = stories)
import database
import unittest

print database.getStories()
print database.getStory('Odessy')
print database.getLastLine('Odessy')