Example #1
0
    def save(self):
        cur = conn.cursor()
        if not self.id:
            now = dbtime.make_time_str()
            cur.execute(
                'INSERT INTO paragraphs VALUES'
                '(NULL, ?, ?, ?, ?, ?, ?, ?);',
                (self.content, self.parent_id, self.votes,
                 self.author_id, self.approved,
                 self.story_id, now))
            self.id = cur.lastrowid
            self.created = now
        else:
            cur.execute(
                '''UPDATE paragraphs 
SET content = ?,
parent_id = ?,
votes = ?,
author_id = ?,
approved = ?,
story_id = ?
WHERE id = ?''', (self.content, self.parent_id, self.votes,
                  self.author_id, self.approved, self.story_id,
                  self.id))
        # Commit data
        conn.commit()
        # Return this object
        return self
Example #2
0
 def create(fname, lname, username, password, dob, email, location, bio):
     s = sha_hash()
     unhashed = username+password
     unhashed = bytes(unhashed, encoding='utf8')
     s.update(unhashed)
     password = s.hexdigest()
     joindate = dbtime.make_time_str()
     return User(None, fname, lname, username, password, dob, email, joindate, location, bio, admin_level)
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()
 def create(cls, fname, lname, username, password, dob, email, location, bio, admin_level=0):
     password = cls._hash(username, password)
     joindate = dbtime.make_time_str()
     return User(None, fname, lname, username, password, dob, email, joindate, location, bio, admin_level)