forked from ncss-2013/ForkingStories
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_story_tree.py
61 lines (51 loc) · 2 KB
/
handler_story_tree.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import template
from dbapi.story_tree import create_tree
from dbapi.story import Story
from dbapi.user import User
from dbapi.paragraph import Paragraph
from dbapi.rules import Rules
'''
def add_static_story():
barry = User.find('id', '0')[0]
story = Story.create(barry, 'ITS A STORY', 'No comment.')
story.save()
para = story.add_paragraph(barry, 'BLAH').save()
para2 = para.chain_paragraph(barry, 'IM A CHILD PARAGRAPH').save()
para3 = para.chain_paragraph(barry, 'ANOTHER CHILD PARA').save()
para4 = para3.chain_paragraph(barry, 'AWESOME').save()
para5 = para4.chain_paragraph(barry, 'TEH RECURSION').save()
para6 = para4.chain_paragraph(barry, 'IS SAH').save()
para7 = para4.chain_paragraph(barry, 'AWESUM').save()
'''
def display_story_tree(resp, story_id):
user = resp.get_secure_cookie('username')
story = Story.find('id', story_id)[0]
author = User.find('id', story.author_id)[0]
if user is not None:
user = User.find('username', str(user, 'utf-8'))[0]
else:
user = None
try:
resp.write(template.render_file('view_story_tree.html', {'node': create_tree(story), 'story': story, 'author': author, 'user': user}))
except Exception as e:
story.delete()
def add_to_story_tree(response, story_id):
try:
story_id = int(story_id)
username = response.get_secure_cookie('username')
user = User.find('username', str(username,'utf-8'))[0]
addition_to_story = response.get_argument('paragraph')
story = Story.find('id', story_id)[0]
if False:#not Rules.check(addition_to_story, story.id):
#return to story view without updating.... TODO: show error
response.write('DR')
response.redirect('/view_story/{}'.format(story_id))
return
response.write('aoeuhotnaeuhaoe ')
parent = Paragraph.find('id',int(response.get_argument('parentId')))[0]
if parent:
parent.chain_paragraph(user, addition_to_story).save()
response.redirect('/view_story/{}'.format(story_id))
except Exception as e:
response.write(str(e))
raise e