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'}
Example #2
0
    def put(self, id):
        data = request.get_json()

        Survey = surveyModel.find_by_id(id)
        # print('ssssssssss',type(data['end_Date']))

        # datetime.strptime(ss, '%Y-%m-%d %H:%M:%S.%f')
        if Survey and Survey.Status == True:
            start = datetime.strptime(data['start_Date'],
                                      '%Y-%m-%d %H:%M:%S.%f')
            end = datetime.strptime(data['end_Date'], '%Y-%m-%d %H:%M:%S.%f')
            Survey.name = data['name']
            Survey.description = data['description']
            Survey.thank_you_message = data['thank_you_message']
            Survey.start_Date = start
            Survey.end_Date = end
            Survey.save_to_db()
            str1 = str(Survey.start_Date)
            str2 = str(Survey.end_Date)
            data = {"message": "survey updated", "id": Survey.id}

            return (data)

        else:
            return {"message": "no record found"}
Example #3
0
    def delete(self, id):
        survey = surveyModel.find_by_id(id)
        if survey and survey.Status == True:
            sur_que = surveyquestionModel.query.all()
            # print(sur_que)
            for x in sur_que:
                if x.survey_id == id:
                    x.Status = False

            deleted = surveyModel.update_by_status(id)

            str1 = str(survey.start_Date)
            str2 = str(survey.end_Date)
            data = {"message": "record deleted", "id": survey.id}

            return (data)
        else:
            return {'message': 'survey not found.'}, 404
Example #4
0
    def get(self, id):
        survey = surveyModel.find_by_id(id)

        if survey and survey.Status == True:
            str1 = str(survey.start_Date)
            str2 = str(survey.end_Date)
            data = {
                "id": survey.id,
                "name": survey.name,
                "description": survey.description,
                "thank_you_message": survey.thank_you_message,
                "end_Date": str2,
                "start_Date": str1
            }
            return (data)

        else:
            return {'message': 'survey not found'}, 404
        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!!!"}