def detailPost(self, idPost, titlePost): if Post().checkPost(idPost, titlePost): OtherEvent().eventViewPost(idPost) OtherEvent().updateTotalViewDefault() OtherEvent().updateTotalFavoriteDefaultupdateTotalFavoriteDefault() return render_template('detail-post.html') return
def updateReport(status, id): if status not in ["accept", "deny", "handling"]: return if session["type_account"] == "admin": OtherEvent().changeStatusReport(id, status) if status == "accept": idPost = OtherEvent().getIdPostFromReport(id) Post().blockPost(idPost) return app.response_class(json.dumps({"message": "ok"}), mimetype='application/json')
def updateFavoritePost(idPost, status): # status in ["add", "remove"] try: if status == "add": OtherEvent().eventFavoritePost(idPost, session["username"], "add") elif status == "remove": OtherEvent().unFavoritePost(session["username"], idPost) return app.response_class(json.dumps({"result": "success"}), mimetype='application/json') except: 1 return app.response_class(json.dumps({"result": "fail"}), mimetype='application/json')
def managerPost(self): if 'type_account' not in session: return redirect('/dang-nhap') elif session['type_account'] == "owner": OtherEvent().updateTotalViewDefault() OtherEvent().updateTotalViewDefault() return render_template('post-manager-owner.html') elif session['type_account'] == "renter": return redirect('/') else: # type_account is "admin" OtherEvent().updateTotalViewDefault() OtherEvent().updateTotalViewDefault() return render_template('post-manager-admin.html')
def updateReview(status, id, star, content): if status not in ["accept", "deny", "handling"]: return if session["type_account"] == "admin": OtherEvent().updateReview(id, status, star, content) return app.response_class(json.dumps({"message": "ok"}), mimetype='application/json')
def sendReview(idPost, star, content): if "type_account" not in session: return redirect("/dang-nhap") if session["type_account"] == "renter": OtherEvent().createReview(session["username"], star, content, idPost, session['type_avatar']) return app.response_class(json.dumps({"message": "ok"}), mimetype='application/json')
def adminThongKeView(groupTime, arg1, arg2): # groupTime = "inDay" => arg1 = yyyy-mm-dd, arg2 = cái gì cũng được # groupTime = "inMonth" => arg1 = yyyy, arg2 = mm # groupTime = "inWeek" => arg1, arg2 = cái gì cũng được # groupTime = "dayToDay" => arg1 = yyyy-mm-dd(start), arg2 = yyyy-mm-dd(end) if session["type_account"] == "admin": return app.response_class(json.dumps(OtherEvent().statisticalView( username="******", groupTime=groupTime, arg1=arg1, arg2=arg2)), mimetype='application/json')
def renterSendReport(self, idPost, fakeInfo, fakePrice): try: content = request.form["content"] except: try: content = request.get_json()["content"] except: content = "" if (fakeInfo != 1 and fakeInfo != 0) or (fakePrice != 1 and fakePrice != 0) or ( 'type_account' not in session or session['type_account'] != "renter"): time.sleep(10) return "fail" # print(content) OtherEvent().renterSendReport(idPost, session["username"], fakeInfo, fakePrice, content) return "success"
def isFavoritePost(idPost): return app.response_class(json.dumps(OtherEvent().isFavoritePost( session["username"], idPost)), mimetype='application/json')
def adminThongKeTuKhoaVaThongKeViewNhanh(): if session["type_account"] == "admin": return app.response_class(json.dumps( OtherEvent().statisticalDateHighestView()), mimetype='application/json')
def thongKeCoCauTrangThaiBaiDang(): return app.response_class(json.dumps(OtherEvent().statisticalPost( session["username"])), mimetype='application/json')
def adminGetTop3Post(): if session["type_account"] == "admin": return app.response_class(json.dumps(OtherEvent().adminGetTop3Post()), mimetype='application/json')
def deleteHistoryView(self, usernameRenter, idPost): OtherEvent().deleteHistoryPost(usernameRenter, idPost) return {"message": "ok"}
def adminGetReports(status): if session["type_account"] == "admin": return app.response_class(json.dumps( OtherEvent().adminGetAllReport(status)), mimetype='application/json')
def getHistoryFavorite(self, usernameRenter): return OtherEvent().getFavoritePost(usernameRenter)
def getHistoryView(self, usernameRenter): return OtherEvent().getHistoryPost(usernameRenter)
def getReport(idPost): return app.response_class(json.dumps( OtherEvent().renterOrGuestGetReview(idPost)), mimetype='application/json')
def ownerThongKeNhanhView(): if session["type_account"] == "owner": return app.response_class(json.dumps( OtherEvent().statisticalDateHighestView(session["username"])), mimetype='application/json')
def recommendSearch(stringSearch): return app.response_class(json.dumps(OtherEvent().fuzzywuzzySearch( stringSearch, 5)), mimetype='application/json')
def search(self, stringSearch, itemType, priceItemMin, priceItemMax, area, sort, statusItem, type, usernameRenter="", numPage=1): # default: itemType(""), area(0), sort("", "price DESC", "price", "area DESC", "area"), statusItem(0, 1: "chungchu", 2:"khongchungchu") # type=0: không click # type=1: địa chỉ đã click if type == 0: data = OtherEvent().fuzzywuzzySearch(stringSearch) if data == []: return {"hasPrev": False, "hasNext": False, "listPost": []} stringSearch = data[0]["address"] # lưu địa điểm OtherEvent().saveHistorySearch(stringSearch, usernameRenter) address = stringSearch.split(', ') if len(address) == 1: filterAddress = " addressProvince = ? " else: filterAddress = " addressDistrict = ? and addressProvince = ? " connectDatabase = ConnectDatabase() query_str = """ SELECT idPost, titlePost, priceItem, concat(addressWard, ", ", addressDistrict, ", ", addressProvince) AS "address", area, numOfRoom, priceWater, priceElectric FROM post WHERE priceItem >= ? AND priceItem <= ? AND area >= ? AND statusPost = ? AND """ query_str += filterAddress if itemType != "": query_str += " AND itemType = \"" + str(itemType) + "\" " if statusItem != 0: statusItem = {1: "chungchu", 2: "khongchungchu"}[statusItem] query_str += " AND statusItem = \"" + str(statusItem) + "\" " if sort != "": query_str += "ORDER BY " + sort query_str += " LIMIT 10 OFFSET ? " if len(address) == 1: rows = connectDatabase.cursor.execute( query_str, priceItemMin, priceItemMax, area, "active", address[0], (numPage - 1) * 10).fetchall() else: rows = connectDatabase.cursor.execute( query_str, priceItemMin, priceItemMax, area, "active", address[0], address[1], (numPage - 1) * 10).fetchall() query_str = """ SELECT COUNT(*) FROM post WHERE priceItem >= ? AND priceItem <= ? AND area >= ? AND """ query_str += filterAddress if itemType != "": query_str += " AND itemType = \"" + str(itemType) + "\" " if statusItem != 0: statusItem = {1: "chungchu", 2: "khongchungchu"}[statusItem] query_str += " AND statusItem = \"" + str(statusItem) + "\" " if len(address) == 1: count = connectDatabase.cursor.execute(query_str, priceItemMin, priceItemMax, area, address[0]).fetchval() else: count = connectDatabase.cursor.execute(query_str, priceItemMin, priceItemMax, area, address[0], address[1]).fetchval() connectDatabase.close() hasPrev = False if numPage == 1 else True if count == 0: hasNext = False hasPrev = False else: maxPage = ((count - 1) // 10 * 10 + 10) // 10 hasNext = True if numPage < maxPage else False return { "hasPrev": hasPrev, "hasNext": hasNext, "listPost": [{ "idPost": row.idPost, "titlePost": row.titlePost, "priceItem": row.priceItem, "address": row.address, "area": row.area, "numOfRoom": row.numOfRoom, "priceWater": row.priceWater, "priceElectric": row.priceElectric } for row in rows] }
def detailPost(self, idPost, titlePost): if Post().checkPost(idPost, titlePost): OtherEvent().updateTotalViewDefault() OtherEvent().updateTotalFavoriteDefaultupdateTotalFavoriteDefault() return Post().getAllInfomationPost(idPost) return
def ownerThongKeCoCauPost(): if session["type_account"] == "owner": return app.response_class(json.dumps(OtherEvent().statisticalOwner( session["username"])), mimetype='application/json')
def UPDATE(self): OtherEvent().updateTotalViewDefault() OtherEvent().updateTotalFavoriteDefault()