Пример #1
0
    def get(self, survey_id, user_id):
        survey = surveyresponseModel.find3_by_id(survey_id, user_id)
        # print(survey.id)
        # question=questionModel.find3_by_id()
        data1 = []
        if survey:
            for x in survey:
                question = questionModel.find_by_id(x.question_id)
                user = userModel.find_by_id(x.user_id)
                survey1 = surveyModel.find_by_id(x.survey_id)
                option1 = optionsModel.find_by_id(x.option)
                print("sarathsssss", option1.options)
                # print(question.description)
                que_des = question.description
                user_name = user.name
                survey1 = survey1.name
                option = option1.options
                data5 = {
                    "questionID": x.question_id,
                    "question": question.description
                }
                data6 = {"optionID": x.option, "option": option1.options}

                # print(survey.user_id)
                data = {"id": x.id, "question": data5, "option": data6}
                data1.append(data)
            data2 = {
                "employee name": user_name,
                "survey name": survey1,
                "results": data1
            }
            return (data2)
        else:
            return {"message": 'user have no option on respective survey'}
Пример #2
0
    def get(self, id):
        # print(id)
        question_data = questionModel.find_by_id(id)
        options_data = list(
            map(lambda x: x.json(),
                optionsModel.query.filter_by(Status=True, question_id=id)))
        li = []
        if question_data and options_data:
            if question_data.Status == True:
                # print(len(options_data))
                for i in range(len(options_data)):
                    op = options_data[i]['options']
                    op1 = options_data[i]['id']
                    print(op1)
                    data3 = {"id": op1, "option": op}
                    li.append(data3)
                    # print(li)
                question_list = question_data.json()

                data = {
                    "id": question_list['id'],
                    "question": question_list['description'],
                    "options": li,
                    "Status": question_list['Status']
                }
                # print(data)
                return data
        return {'message': 'not found'}, 404
Пример #3
0
    def put(self, id):
        data = request.get_json()
        # print(data)
        question_data = questionModel.find_by_id(id)
        if question_data and question_data.Status == True:
            question_data.question = data['description']
            question_data.save_to_db()

        options = data['options']

        option_data = list(
            map(lambda x: x.json(),
                optionsModel.query.filter_by(Status=True, question_id=id)))
        print(len(option_data))
        if option_data:
            li = []
            for k in option_data:
                li.append(k['id'])
            print(len(li))
            if len(options) == len(li):
                for i in range(len(options)):
                    # print("hh",li[i])
                    # print("f",li[i],options[i])
                    optionsModel.optionUpdate(li[i], options[i])
            else:
                return ("error"), 404
        else:
            return {'message': 'not found.'}, 404

        return {"message": "Updated successfully!!!"}, 201
Пример #4
0
    def delete(self, id):
        question_data = questionModel.find_by_id(id)
        print(question_data.json())
        if question_data and question_data.Status == True:

            question_data = questionModel.update_by_status(id)
            sur_data = surveyquestionModel.update2_by_status(id)
            sur_que_data = list(
                map(lambda x: x.json(), optionsModel.find_by_qid(id)))

            for x in sur_que_data:
                print(x['question_id'])
                if x['Status'] == True:

                    s_del_data = optionsModel.update_by_status(
                        x['id'], x['question_id'])

            return {'id': id, 'message': 'deleted.'}
        return {'message': 'not found.'}, 404
Пример #5
0
    def put(self, id):
        data = Options.parser.parse_args()
        options = data['options']
        q1 = optionsModel.find_by_id1(id)
        q2 = questionModel.find_by_id(id)
        # for i in range(len(options)):
        #         print("kkk", options[i])
        #
        # if optionsModel.find_by_option(options[i]) and id==x.question_id:
        #     return {"message": "Already exists"}, 400
        try:

            for i in range(len(options)):
                # print("kkk", options[i])
                option_set = optionsModel(options[i], id)
                option_set.save_to_db()
        except:
            return {"message": "An error occurred inserting the item."}, 500

        return {
            "message": "inserted successfully"
            # "data":data
        }, 201
Пример #6
0
        def get(self,id):
            status = True
            # args = request.args
            # if "Status" in args and args.get("Status") != '':
            #
            #     status = args.get("Status")
            sur_que_data = list(map(lambda x: x.json(), surveyquestionModel.query.filter_by(survey_id=id,Status = status).order_by(surveyquestionModel.id)))


            if sur_que_data !=[] :


                s_data = surveyModel.find_by_id(id)
                data = {
                        "id": s_data.id,
                        "name": s_data.name,

                    }
                su_list = []
                for s in sur_que_data:
                    q_list = s['question_id']
                    # print("id",q_list)
                    q_data = questionModel.find_by_id(s['question_id'])
                    # que_res_data = q_data.json()
                    # print(que_res_data)

                    o_data = list(map(lambda x: x.json(), optionsModel.query.filter_by(Status=True, question_id=s['question_id'])))
                    li = []
                    if q_data and o_data:
                        if q_data.Status == True:
                            # print(len(o_data))
                            for i in range(len(o_data)):
                                op1 = o_data[i]['options']
                                op2 = o_data[i]['id']
                                print("ssssssssssss",op1)
                                data3={
                                "id":op2,"option":op1
                                }
                                li.append(data3)
                                # print(li)
                            q_li = q_data.json()

                            data1 = {
                                "id": q_li['id'],
                                "question": q_li['description'],
                                "options": li,
                                "Status": q_li['Status'],
                            }
                        # Survey_question_list = {
                        # # "surveyid":data,
                        #     "questions":data1
                        #     # "order":s['order']
                        #     }

                        su_list.append(data1)



                last = {
                        "survey":data,
                        "question data":su_list
                    }

                return ( last)

            if sur_que_data == []:
                # print("www")
                return {"message": "No survey found!!!"}