コード例 #1
0
ファイル: user.py プロジェクト: mzhang00/JoseMAD
 def join_qaf(self, qaf_id):
     qafs = self.qafs_joined.split(',')
     if qaf_id not in qafs:
         command = 'UPDATE users \
                     SET qafs_joined =  qafs_joined || "{}," \
                     WHERE id = {}'.format(qaf_id, self.id)
         execute(command)
コード例 #2
0
ファイル: post.py プロジェクト: mzhang00/JoseMAD
 def get_comments(self):
     command = f'SELECT id FROM comments WHERE post_id = {self.id}'
     data = execute(command).fetchall()
     comments = []
     for comment_id in data:
         comments.append(Comment(comment_id[0]))
     return comments
コード例 #3
0
 def get_posts(self):
     command = 'SELECT id FROM posts WHERE qaf_id = {} ORDER BY time_created DESC'.format(
         self.id)
     data = execute(command).fetchall()
     posts = []
     for post_id in data:
         posts.append(Post(post_id[0]))
     return posts
コード例 #4
0
 def __init__(self, id):
     command = 'SELECT * FROM qafs WHERE id={}'.format(id)
     data = execute(command).fetchall()
     self.id = int(data[0][0])
     self.name = str(data[0][1])
     self.owner_id = int(data[0][2])
     self.mode = str(data[0][3])
     self.owner = util.user.User(self.owner_id).username
コード例 #5
0
ファイル: user.py プロジェクト: mzhang00/JoseMAD
 def get_user(username):
     command = 'SELECT id from users WHERE username = "******"'.format(username)
     data = execute(command).fetchall()
     if len(data
            ) == 0:  # if no user exists with the username then return None
         return None
     else:
         return User(data[0][0])  #returns user object
コード例 #6
0
ファイル: user.py プロジェクト: mzhang00/JoseMAD
 def __init__(self, id):
     command = 'SELECT * FROM users WHERE id={}'.format(id)
     data = execute(command).fetchall()
     self.id = int(data[0][0])
     self.username = str(data[0][1])
     self.password = str(data[0][2])
     self.waffles = int(data[0][3])
     self.qafs_joined = str(data[0][4])
コード例 #7
0
def qafSearch():
    input = request.args.get("input", 0, type=str)
    if (input == ""):
        return jsonify(result="")
    output = execute(
        f"""SELECT * FROM 'qafs' WHERE name LIKE '%{input}%' AND mode = 'public';"""
    ).fetchall()
    print(output)
    return jsonify(result=output)
コード例 #8
0
 def __init__(self, id):
     command = 'SELECT * FROM comments WHERE id={}'.format(id)
     data = execute(command).fetchall()
     self.id = int(data[0][0])
     self.author_id = int(data[0][1])
     self.author = util.user.User(self.author_id).username
     self.content = str(data[0][2])
     self.post_id = int(data[0][3])
     self.qaf_id = int(data[0][4])
     self.time_created = str(data[0][5])
     self.net_vote = int(data[0][6])
コード例 #9
0
ファイル: post.py プロジェクト: mzhang00/JoseMAD
 def __init__(self, id):
     command = 'SELECT * FROM posts WHERE id={}'.format(id)
     data = execute(command).fetchall()
     self.id = int(data[0][0])
     self.author_id = int(data[0][1])
     self.title = str(data[0][2])
     self.content = str(data[0][3])
     self.qaf_id = int(data[0][4])
     self.tags = str(data[0][5]).split(',')
     self.tags_str = str(data[0][5])
     self.time_created = str(data[0][6])
     self.net_vote = int(data[0][7])
コード例 #10
0
ファイル: post.py プロジェクト: mzhang00/JoseMAD
 def downvoted(self):
     command = 'UPDATE posts \
                 SET net_vote = {} \
                 WHERE id = {}'.format(self.net_vote - 1, self.id)
     execute(command)
コード例 #11
0
ファイル: user.py プロジェクト: mzhang00/JoseMAD
 def new_user(username, password):
     command = f'INSERT INTO users (username, password, waffles, qafs_joined) VALUES ("{username}", "{password}", 0, "")'
     execute(command)
コード例 #12
0
ファイル: user.py プロジェクト: mzhang00/JoseMAD
 def username_avaliable(username):
     command = 'SELECT id FROM users WHERE username = "******"'.format(username)
     data = execute(command).fetchall()
     return len(data) == 0
コード例 #13
0
ファイル: user.py プロジェクト: mzhang00/JoseMAD
 def change_password(self, new_pass):
     command = 'UPDATE users \
                 SET password = "******" \
                 WHERE id = {}'.format(new_pass, self.id)
     execute(command)
コード例 #14
0
ファイル: post.py プロジェクト: mzhang00/JoseMAD
 def update(self, title, content, tags):
     command = f'UPDATE posts SET title =  "{title}", content = "{content}", tags = "{tags}" WHERE id = {self.id}'
     execute(command)
コード例 #15
0
ファイル: post.py プロジェクト: mzhang00/JoseMAD
 def new_post(author_id, title, content, qaf_id, tags):
     command = f'INSERT INTO posts (author_id, title, content, qaf_id, tags, net_vote) VALUES ("{author_id}", "{title}", "{content}", {qaf_id}, "{tags}", 0)'
     execute(command)
     util.user.User(author_id).join_qaf(qaf_id)
コード例 #16
0
 def new_qaf(name, owner_id, mode):
     command = 'INSERT INTO qafs (name, owner_id, mode) VALUES ("{}", "{}", "{}")'.format(
         name, owner_id, mode)
     cursor = execute(command)
     return cursor.lastrowid
コード例 #17
0
    def downvote(self):
        command = 'UPDATE comments \
					SET net_vote = "{}" \
					WHERE id = {}'.format(self.net_vote - 1, self.id)
        execute(command)
コード例 #18
0
 def new_comment(author_id, content, post_id, qaf_id):
     command = f'INSERT INTO comments (author_id, content, post_id, qaf_id, net_vote) VALUES ("{author_id}", "{content}","{post_id}","{qaf_id}", 0)'
     execute(command)
     util.user.User(author_id).join_qaf(qaf_id)
コード例 #19
0
 def update(self, content):
     command = f'UPDATE comments SET content = "{content}" WHERE id = {self.id}'
     execute(command)