Example #1
0
    def get_approved_paragraphs(clf, story_id):
        '''Takes a story id and returns a list of all the aprroved content
in order for that story.'''
        cur = conn.cursor()
        cur.execute('''SELECT * FROM paragraphs WHERE
story_id = ''' + str(story_id) + ''' AND approved = 1
ORDER BY created;''')
        rows = cur.fetchall()
        return [Paragraph(p[0], p[1], p[2], p[3], p[4], p[5], p[6],
                         dbtime.get_time_from_str(p[7])) for p in rows]
Example #2
0
 def find(clf, field_name, query, order_by=None):
     cur = conn.cursor()
     if not order_by:
         order_by = field_name
         
     # TODO: This is a bug, maybe escape field_name later
     rows = cur.execute('SELECT * FROM paragraphs WHERE ' + field_name +
                        ' = ? ORDER BY ?',
                     (query, order_by)).fetchall()     
     return [Paragraph(p[0], p[1], p[2], p[3], p[4], p[5], p[6],
                      dbtime.get_time_from_str(p[7])) for p in rows]
Example #3
0
 def save(self):
     cur = conn.cursor()
     if self.id is None:
         time = dbtime.make_time_str()
         self.created_time = dbtime.get_time_from_str(time)
         cur.execute("INSERT INTO stories VALUES (NULL, ?, ?, ?, ?, ?);",
                     (self.author_id,self.title,time,self.author_init_comment, self.votes))
         self.id = cur.lastrowid
     else:
         cur.execute('''UPDATE stories SET
                     author_id=?,
                     title=?,
                     WHERE id=?'''(self.author_id,self.title,self.id))
     conn.commit()
     return self
Example #4
0
 def save(self):
     cur = conn.cursor()
     if self.id == None:
         time = dbtime.make_time_str()
         self.created_time = dbtime.get_time_from_str(time)
         cur.execute("INSERT INTO comments VALUES (NULL, ?, ?, ?, ?);",
                     (self.author_id,self.story_id,self.content,self.created_time))
         self.id = cur.lastrowid
     else:
         cur.execute('''UPDATE comments SET
                 author_id=?,
                 story_id=?,
                 content=?,
                 WHERE id=?'''(self.author_id,self.story_id,self.content,self.id))
     conn.commit()
Example #5
0
 def find(cls, field_name, field_value):
     if field_name == 'author':
         field_name = 'author_id'
         field_value = field_value.id
     cur = conn.cursor()
     if field_name == 'all':
         cur.execute("SELECT * FROM stories")
     else:
         cur.execute("SELECT * FROM stories WHERE " + field_name + "= ?",(field_value,))
     records = cur.fetchall()
     stories = []
     for record in records:
         story = Story(*record)
         story.created_time = dbtime.get_time_from_str(record[3])
         stories.append(story)
     return stories
Example #6
0
 def find(cls, field_name, field_value):
     if field_name == 'author':
         field_name = 'author_id'
         field_value = field_value.id
     cur = conn.cursor()
     if field_name == 'all':
         cur.execute("SELECT * FROM comments")
     else:
         cur.execute("SELECT * FROM comments WHERE " + field_name + "= ?",(field_value,))
     records = cur.fetchall()
     comments = []
     for record in records:
         comment = Comment(*record)
         comment.created_time = dbtime.get_time_from_str(record[4])
         comments.append(comment)
     return comments