def remove_follows(email1, email2): follows = selectQuery('SELECT id FROM Followers WHERE follower = %s AND followee = %s', (email1, email2, )) if len(follows) != 0: ins_upd_delQuery('DELETE FROM Followers WHERE follower = %s AND followee = %s', (email1, email2, )) else: raise Exception("No such following") return users.details(email1)
def details(short_name, related): forum = selectQuery('SELECT id, name, short_name, user FROM Forums WHERE short_name = %s', (short_name, )) if len(forum) == 0: raise ("No forum with exists short_name=" + short_name) forum = forums_info(forum) if "user" in related: forum["user"] = users.details(forum["user"]) return forum
def add_follows(email1, email2): verify(table_name="Users", param="email", val=email1) verify(table_name="Users", param="email", val=email2) if email1 == email2: raise Exception("User with email=" + email1 + " can't follow himself") follows = selectQuery('SELECT id FROM Followers WHERE follower = %s AND followee = %s', (email1, email2, )) if len(follows) == 0: ins_upd_delQuery('INSERT INTO Followers (follower, followee) VALUES (%s, %s)', (email1, email2, )) user = users.details(email1) return user
def details(id, related): post = posts_query(id) if post is None: raise Exception("no post with id = "+id) if "user" in related: post["user"] = users.details(post["user"]) if "forum" in related: post["forum"] = forums.details(short_name=post["forum"], related=[]) if "thread" in related: post["thread"] = threads.details(id=post["thread"], related=[]) return post
def details(request): if request.method == "GET": request_info = GET_parameters(request) required_info = ["user"] try: test_require(data=request_info, required=required_info) user_details = users.details(email=request_info["user"]) except Exception as e: return return_error(e.message) return return_response(user_details) else: return HttpResponse(status=400)
def details(id, related): thread = selectQuery( 'select date, forum, id, isClosed, isDeleted, message, slug, title, user, dislikes, likes, points, posts ' 'FROM Threads WHERE id = %s', (id, ) ) if len(thread) == 0: raise Exception('No thread exists with id=' + str(id)) thread = threads_info(thread) if "user" in related: thread["user"] = users.details(thread["user"]) if "forum" in related: thread["forum"] = forums.details(short_name=thread["forum"], related=[]) return thread
def list_users(short_name, opt): verify(table_name="Forums", param="short_name", val=short_name) query = "SELECT distinct email FROM Users, Posts, Forums WHERE Posts.user = Users.email " \ " and Forums.short_name = Posts.forum and Posts.forum = %s " if "since_id" in opt: query += " AND Users.id >= " + str(opt["since_id"]) if "order" in opt: query += " ORDER BY Users.id " + opt["order"] if "limit" in opt: query += " LIMIT " + str(opt["limit"]) users_tuple = selectQuery(query, (short_name, )) user_array = [] for user in users_tuple: user = user[0] user_array.append(users.details(user)) return user_array
def followers_list(email, type, params): verify(table_name="Users", param="email", val=email) if type == "follower": where = "followee" if type == "followee": where = "follower" query = "SELECT "+type+" FROM Followers, Users WHERE Users.email = Followers."+type+\ " AND "+where+" = %s " if "since_id" in params: query += " AND Users.id >= "+str(params["since_id"]) if "order" in params: query += " ORDER BY Users.name "+params["order"] else: query += " ORDER BY Users.name DESC " if "limit" in params: query += " LIMIT "+str(params["limit"]) followers_ids_tuple = selectQuery(query=query, params=(email, )) followers_array = [] for id in followers_ids_tuple: id = id[0] followers_array.append(users.details(email=id)) return followers_array