Ejemplo n.º 1
0
 def detailPost(self, idPost, titlePost):
     if Post().checkPost(idPost, titlePost):
         OtherEvent().eventViewPost(idPost)
         OtherEvent().updateTotalViewDefault()
         OtherEvent().updateTotalFavoriteDefaultupdateTotalFavoriteDefault()
         return render_template('detail-post.html')
     return
Ejemplo n.º 2
0
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')
Ejemplo n.º 3
0
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')
Ejemplo n.º 4
0
 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')
Ejemplo n.º 5
0
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')
Ejemplo n.º 6
0
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')
Ejemplo n.º 7
0
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')
Ejemplo n.º 8
0
 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"
Ejemplo n.º 9
0
def isFavoritePost(idPost):
    return app.response_class(json.dumps(OtherEvent().isFavoritePost(
        session["username"], idPost)),
                              mimetype='application/json')
Ejemplo n.º 10
0
def adminThongKeTuKhoaVaThongKeViewNhanh():
    if session["type_account"] == "admin":
        return app.response_class(json.dumps(
            OtherEvent().statisticalDateHighestView()),
                                  mimetype='application/json')
Ejemplo n.º 11
0
def thongKeCoCauTrangThaiBaiDang():
    return app.response_class(json.dumps(OtherEvent().statisticalPost(
        session["username"])),
                              mimetype='application/json')
Ejemplo n.º 12
0
def adminGetTop3Post():
    if session["type_account"] == "admin":
        return app.response_class(json.dumps(OtherEvent().adminGetTop3Post()),
                                  mimetype='application/json')
Ejemplo n.º 13
0
 def deleteHistoryView(self, usernameRenter, idPost):
     OtherEvent().deleteHistoryPost(usernameRenter, idPost)
     return {"message": "ok"}
Ejemplo n.º 14
0
def adminGetReports(status):
    if session["type_account"] == "admin":
        return app.response_class(json.dumps(
            OtherEvent().adminGetAllReport(status)),
                                  mimetype='application/json')
Ejemplo n.º 15
0
 def getHistoryFavorite(self, usernameRenter):
     return OtherEvent().getFavoritePost(usernameRenter)
Ejemplo n.º 16
0
 def getHistoryView(self, usernameRenter):
     return OtherEvent().getHistoryPost(usernameRenter)
Ejemplo n.º 17
0
def getReport(idPost):
    return app.response_class(json.dumps(
        OtherEvent().renterOrGuestGetReview(idPost)),
                              mimetype='application/json')
Ejemplo n.º 18
0
def ownerThongKeNhanhView():
    if session["type_account"] == "owner":
        return app.response_class(json.dumps(
            OtherEvent().statisticalDateHighestView(session["username"])),
                                  mimetype='application/json')
Ejemplo n.º 19
0
def recommendSearch(stringSearch):
    return app.response_class(json.dumps(OtherEvent().fuzzywuzzySearch(
        stringSearch, 5)),
                              mimetype='application/json')
Ejemplo n.º 20
0
    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]
        }
Ejemplo n.º 21
0
 def detailPost(self, idPost, titlePost):
     if Post().checkPost(idPost, titlePost):
         OtherEvent().updateTotalViewDefault()
         OtherEvent().updateTotalFavoriteDefaultupdateTotalFavoriteDefault()
         return Post().getAllInfomationPost(idPost)
     return
Ejemplo n.º 22
0
def ownerThongKeCoCauPost():
    if session["type_account"] == "owner":
        return app.response_class(json.dumps(OtherEvent().statisticalOwner(
            session["username"])),
                                  mimetype='application/json')
Ejemplo n.º 23
0
 def UPDATE(self):
     OtherEvent().updateTotalViewDefault()
     OtherEvent().updateTotalFavoriteDefault()