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
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)
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)
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)