示例#1
0
def showComments(request):
    try:
        params = json.loads(request.body)
        token = params['token']
        TYPE = int(params['TYPE'])
        if(TYPE!=1 and TYPE!=0 and TYPE !=-1):
            response = JsonResponse({"error_code": 1, "msg": "params error"})
            return ret(response)
        pagenum = params['pageNum']      # 每页多少条
        pagesize = params['pageSize']    # 第几页
        result = verifyToken(token)
        if(result==True):
            data = []
            qs = models.comments.objects.filter(vet=TYPE)
            pgnt = Paginator(qs, pagesize)
            page = pgnt.page(pagenum)
            for i in page:
                comment = {
                    "commentId": i.id,
                    "commentContent": str(i.content)[0:10],
                    "commentTime": i.modifytime
                }
                data.append(comment)

            response = JsonResponse({"error_code": 0, "msg": "success", "data": data, "nums": pgnt.count,"pages": max(1,math.ceil(pgnt.count // pagesize))})
            return ret(response)
        else:
            response = JsonResponse({"error_code": 1, "msg": result})
            return ret(response)
    except:
        response = JsonResponse({"error_code": 1, "msg": "params error"})
        return ret(response)
示例#2
0
def getPostInfo(request):
    try:
        params = json.loads(request.body)
        token = params['token']
        postid = params['postId']

        result = verifyToken(token)
        if(result==True):
            try:
                post = models.posts.objects.get(id=postid)
                response = JsonResponse({"error_code": 0, "msg": "success", "data": {
                                                                                    "postId": post.id,
                                                                                    "postTitle": post.title,
                                                                                    "postContent": post.content,
                                                                                    "urlList": post.urllist,
                                                                                    "catId": post.catid,
                                                                                    "username": post.username,
                                                                                    "postTime": post.modifytime,
                                                                                    "postVet": post.vet
                                                                                    }})
                return ret(response)
            except:
                response = JsonResponse({"error_code": 1, "msg": "ID error"})
                return ret(response)
        else:
            response = JsonResponse({"error_code": 1, "msg": result})
            return ret(response)
    except:
        response = JsonResponse({"error_code": 1, "msg": "params error"})
        return ret(response)
示例#3
0
def login(request):
    try:
        params = json.loads(request.body)
        username = params['username']
        password = str(params['password']) + salt_passwd
        password = hashlib.md5(password.encode())
        password = password.hexdigest()
        user = models.user.objects.get(username=username)
        passwd = user.password
        if (password == passwd):
            headers = {
                "typ": "jwt_",
                "alg": "HS256",
            }
            payload = {
                "user_type":
                "admin",
                "exp":
                datetime.datetime.utcnow() + datetime.timedelta(minutes=1440)
            }
            token = jwt.encode(payload=payload, key=salt_jwt,
                               headers=headers).decode("utf-8")
            response = JsonResponse({"error_code": 0, "token": token})
            return ret(response)
        else:
            response = JsonResponse({
                "error_code": 1,
                "msg": "username or password wrong"
            })
            return ret(response)
    except:
        response = JsonResponse({"error_code": 1, "msg": "params error"})
        return ret(response)
示例#4
0
def modifyPostInfo(request):
    try:
        params = json.loads(request.body)
        token = params['token']
        postid = params['postId']
        posttitle = params['postTitle']
        postcontent = params['postContent']
        urllist = str(params['urlList'])
        postvet = int(params['postVet'])

        result = verifyToken(token)
        if (result == True):
            try:
                post = models.posts.objects.get(id=postid)
                post.title = posttitle
                post.content = postcontent
                post.urllist = urllist
                post.vet = postvet
                post.save()
                response = JsonResponse({"error_code": 0, "msg": "success"})
                return ret(response)
            except:
                response = JsonResponse({"error_code": 1, "msg": "ID error"})
                return ret(response)
        else:
            response = JsonResponse({"error_code": 1, "msg": result})
            return ret(response)
    except:
        response = JsonResponse({"error_code": 1, "msg": "params error"})
        return ret(response)
示例#5
0
def modifyCommentInfo(request):
    try:
        params = json.loads(request.body)
        token = params['token']
        commentid = params['commentId']
        commentcontent = params['commentContent']
        commentvet = int(params['commentVet'])

        result = verifyToken(token)
        if (result == True):
            try:
                comment = models.comments.objects.get(id=commentid)
                comment.content = commentcontent
                comment.vet = commentvet
                comment.save()
                response = JsonResponse({"error_code": 0, "msg": "success"})
                return ret(response)
            except:
                response = JsonResponse({"error_code": 1, "msg": "ID error"})
                return ret(response)
        else:
            response = JsonResponse({"error_code": 1, "msg": result})
            return ret(response)
    except:
        response = JsonResponse({"error_code": 1, "msg": "params error"})
        return ret(response)
示例#6
0
def getCommentInfo(request):
    try:
        params = json.loads(request.body)
        token = params['token']
        commentid = params['commentId']

        result = verifyToken(token)
        if (result == True):
            try:
                comment = models.comments.objects.get(id=commentid)
                response = JsonResponse({
                    "error_code": 0,
                    "msg": "success",
                    "data": {
                        "commentId": comment.id,
                        "commentContent": comment.content,
                        "username": comment.username,
                        "commentTime": comment.modifytime,
                        "commentVet": comment.vet
                    }
                })
                return ret(response)
            except:
                response = JsonResponse({"error_code": 1, "msg": "ID error"})
                return ret(response)
        else:
            response = JsonResponse({"error_code": 1, "msg": result})
            return ret(response)
    except:
        response = JsonResponse({"error_code": 1, "msg": "params error"})
        return ret(response)
def modifyFeedbackInfo(request):
    try:
        params = json.loads(request.body)
        token = params['token']
        feedbackid = params['feedbackId']
        feedbackanswer = params['feedbackAnswer']
        feedbackvet = int(params['feedbackVet'])

        result = verifyToken(token)
        if (result == True):
            try:
                feedback = models.feedbacks.objects.get(id=feedbackid)
                feedback.answer = feedbackanswer
                feedback.vet = feedbackvet
                feedback.save()
                response = JsonResponse({"error_code": 0, "msg": "success"})
                return ret(response)
            except:
                response = JsonResponse({"error_code": 1, "msg": "ID error"})
                return ret(response)
        else:
            response = JsonResponse({"error_code": 1, "msg": result})
            return ret(response)
    except:
        response = JsonResponse({"error_code": 1, "msg": "params error"})
        return ret(response)
示例#8
0
def getCatInfo(request):
    try:
        params = json.loads(request.body)
        token = params['token']
        catid = params['catId']

        result = verifyToken(token)
        if(result==True):
            try:
                cat = models.cats.objects.get(id=catid)
                response = JsonResponse({"error_code": 0, "msg": "success", "data": {
                                                                                    "catId": cat.id,
                                                                                    "catName": cat.name,
                                                                                    "catColor": cat.color,
                                                                                    "catSex": cat.sex,
                                                                                    "catCharacter": cat.character,
                                                                                    "catStatus": cat.status,
                                                                                    "catAddress": cat.address,
                                                                                    "catUrl": cat.url,
                                                                                    "urlList": cat.urllist,
                                                                                    "catVet": cat.vet,
                                                                                    "username": cat.username
                                                                                    }})
                return ret(response)
            except:
                response = JsonResponse({"error_code": 1, "msg": "ID error"})
                return ret(response)
        else:
            response = JsonResponse({"error_code": 1, "msg": result})
            return ret(response)
    except:
        response = JsonResponse({"error_code": 1, "msg": "params error"})
        return ret(response)
示例#9
0
def isLogin(request):
    try:
        params = json.loads(request.body)
        token = params['token']
        result = verifyToken(token)
        if(result==True):
            response = JsonResponse({"error_code": 0, "msg": "success"})
            return ret(response)
        else:
            response = JsonResponse({"error_code": 1, "msg": result})
            return ret(response)
    except:
        response = JsonResponse({"error_code": 1, "msg": "params error"})
        return ret(response)
示例#10
0
def getFeedbackInfo(request):
    try:
        params = json.loads(request.body)
        token = params['token']
        feedbackid = params['feedbackId']

        result = verifyToken(token)
        if (result == True):
            try:
                feedback = models.feedbacks.objects.get(id=feedbackid)
                if (feedback.feedbacktype == 1):
                    ID = feedback.catid
                elif (feedback.feedbacktype == 2):
                    ID = feedback.postid
                elif (feedback.feedbacktype == 3):
                    ID = feedback.commentid
                elif (feedback.feedbacktype == 4):
                    ID = 0
                response = JsonResponse({
                    "error_code": 0,
                    "msg": "success",
                    "data": {
                        "feedbackId": feedback.id,
                        "feedbackContent": feedback.content,
                        "urlList": feedback.urllist,
                        "feedbackAnswer": feedback.answer,
                        "feedbackType": feedback.feedbacktype,
                        "ID": ID,
                        "feedbackTime": feedback.time,
                        "feedbackVet": feedback.vet
                    }
                })
                return ret(response)
            except:
                response = JsonResponse({"error_code": 1, "msg": "ID error"})
                return ret(response)
        else:
            response = JsonResponse({"error_code": 1, "msg": result})
            return ret(response)
    except:
        response = JsonResponse({"error_code": 1, "msg": "params error"})
        return ret(response)
示例#11
0
def modifyCatInfo(request):
    try:
        params = json.loads(request.body)
        token = params['token']
        catid = params['catId']
        catname = params['catName']
        catcolor = params['catColor']
        catsex = params['catSex']
        catcharacter = params['catCharacter']
        catstatus = params['catStatus']
        cataddress = params['catAddress']
        caturl = params['catUrl']
        catvet = params['catVet']
        urllist = str(params['urlList'])

        result = verifyToken(token)
        if(result==True):
            try:
                cat = models.cats.objects.get(id=catid)
                cat.name = catname
                cat.color = catcolor
                cat.sex = catsex
                cat.character = catcharacter
                cat.status = catstatus
                cat.address = cataddress
                cat.url = caturl
                cat.urllist = urllist
                cat.vet = catvet
                cat.save()
                response = JsonResponse({"error_code": 0, "msg": "success"})
                return ret(response)
            except:
                response = JsonResponse({"error_code": 1, "msg": "ID error"})
                return ret(response)
        else:
            response = JsonResponse({"error_code": 1, "msg": result})
            return ret(response)
    except:
        response = JsonResponse({"error_code": 1, "msg": "params error"})
        return ret(response)