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
Esempio n. 2
0
 def get_number_of_paragraphs(self):
     cur = conn.cursor()
     cur.execute("SELECT id" "FROM paragraphs" "WHERE author_id = ?", (self.id,))
     rows = cur.fetchall()
     results = []
     for row in rows:
         results += Paragraph.find("id", *row)
     return len(results)
Esempio n. 3
0
    def add_paragraph(self, userObj:object, content:str, parent_id=None):
        '''This method should be used to create the first paragraph in a
story. After that, use the Paragraph.chain_paragraph() method.'''
        # --- Alex Mueller wrote this ---
        paragraph = Paragraph.create(content, None, 1, userObj.id, True,
                                     self.id)
        #paragraphs = Paragraph.find('story_id', self.id)
        #parent_ids = [p.parent_id for p in paragraphs if p.approved]
        paragraph.parent_id = parent_id if parent_id else -1
        return paragraph
Esempio n. 4
0
 def get_number_of_paragraphs_approved(self):
     cur = conn.cursor()
     cur.execute(
         """SELECT id
         FROM paragraphs
         WHERE author_id = ? AND approved = 1""",
         (self.id,),
     )
     rows = cur.fetchall()
     results = []
     for row in rows:
         results += Paragraph.find("id", *row)
     return len(results)
Esempio n. 5
0
def create_tree(story=None,story_id=None):
	if story_id is None:
		story_id = story.id
	from dbapi.paragraph import Paragraph
	paragraphs = Paragraph.get_approved_paragraphs(story_id)
	tree = dict((p.id, ParagraphNode(p)) for p in paragraphs)
		
	# Fill out the node data
	root = None
	for p in paragraphs:
		if p.parent_id != -1:
			tree[p.id].parent = tree[p.parent_id]
			tree[p.parent_id].children.append(tree[p.id])
		else:
			root = tree[p.id]
	
	# Return the root node
	return root
Esempio n. 6
0
 def get_approved_paragraphs(self):
     return Paragraph.get_approved_paragraphs(self.id)
Esempio n. 7
0
        return stories
                    
    @classmethod
    def create(cls, author_obj:object, title:str, author_init_comment:str=''):
        author_id = author_obj.id
        return Story(None, author_id, title, None, author_init_comment, 0)

if __name__ == "__main__":
    user=User.find('username','barry_1233')
    story = Story.create(user[0],'hello')
    story.save()
    p = story.add_paragraph(user[0], 'Hey! Where\'s my hobbit?')
    assert p.content == 'Hey! Where\'s my hobbit?'
    p.save()
    story.get_approved_paragraphs()
    assert Paragraph.find('id', p.id)[0].content == 'Hey! Where\'s my hobbit?', \
        'Failed to read content back from databse when testing Story.create()'
    p.delete()
    stories = Story.find('author',user[0])
    author = story.get_author()
    assert len(stories) > 0, 'stories should have at least 1 story'
    count = len(stories)
    stories[0].get_approved_paragraphs()
    comment=story.add_comment(user[0],'That was a cool read!')
    comment.save()
    story.get_comments()
    comment.delete()
    story.set_rule('banned_words','cat')
    assert False == story.check_rules('the cat sat on the mat')
    story.delete()
    story.find('author_id',12)