示例#1
0
 def resolve_tour_feedback(cls, _, info, tour_id):
     if get_jwt_claims() == admin_claim:
         if TourModel.objects(id=tour_id):
             tour = TourModel.objects.get(id=tour_id)
             if TourFeedbackModel.objects(tour=tour):
                 return list(TourFeedbackModel.objects(tour=tour))
     return []
示例#2
0
 def resolve_checkpoints_by_tour(cls, _, info, tour_id):
     if get_jwt_claims() == admin_claim:
         if TourModel.objects(id=tour_id):
             tour = TourModel.objects.get(id=tour_id)
             if CheckpointModel.objects(tour=tour):
                 return list(CheckpointModel.objects(tour=tour))
     return []
示例#3
0
    def resolve_export_answers(cls, _, info, tour_id, username):
        if UserModel.objects(username=username):
            user = UserModel.objects.get(username=username)
            if TourModel.objects(id=tour_id):
                tour = TourModel.objects.get(id=tour_id)
                report = 'Antworten für den Nutzer {} im Rundgang {}.\n'.format(
                    user.username, tour.name)
                questions = QuestionModel.objects(tour=tour)
                for question in questions:
                    if AnswerModel.objects(user=user, question=question):
                        answer = AnswerModel.objects.get(user=user,
                                                         question=question)
                        if type(answer) == MCAnswerModel:
                            text_answers = []
                            for index in answer.answer:
                                text_answers.append(
                                    question.possible_answers[index])
                            report = report + 'Frage: {}\n'.format(
                                question.question)
                            for ta in text_answers:
                                report = report + 'Antwort: {}'.format(
                                    ta) + '\n'

                        else:
                            report = report + 'Frage: {}\n Antwort: {}\n'.format(
                                question.question, answer.answer)

                return report
        return ""
示例#4
0
 def resolve_checkpoints_tour(cls, _, info, tour_id):
     user = UserModel.objects.get(username=get_jwt_identity())
     if TourModel.objects(id=tour_id):
         tour = TourModel.objects.get(id=tour_id)
         if user in tour.users:
             if CheckpointModel.objects(tour=tour):
                 return list(CheckpointModel.objects(tour=tour))
     return []
示例#5
0
 def resolve_tour_search_id(cls, _, info, search_id):
     """ NOTE: This only returns the tour id, not the tour object.
     The id can be used in combination with the session id to join the tour. Users that are a member of a tour can
      use the id of the tour to get the tour object which allows for further retrieval of tour fields and checkpoints
      """
     if TourModel.objects(search_id=search_id):
         tour = TourModel.objects.get(search_id=search_id)
         return [tour.id]
     return []
示例#6
0
 def resolve_feedback(cls, _, info, tour_id):
     username = get_jwt_identity()
     if UserModel.objects(username=username):
         user = UserModel.objects.get(username=username)
         if TourModel.objects(id=tour_id):
             tour = TourModel.objects.get(id=tour_id)
         if tour.owner == user:
             return list(TourFeedbackModel.objects(tour=tour))
     return []
示例#7
0
 def resolve_tour(cls, _, info, tour_id):
     username = get_jwt_identity()
     if UserModel.objects(username=username):
         user = UserModel.objects.get(username=username)
         if TourModel.objects(id=tour_id):
             tour = TourModel.objects.get(id=tour_id)
             if user in tour.users:
                 return [tour]
     return []
示例#8
0
 def resolve_question_id(cls, _, info, tour_id, index):
     if TourModel.objects(id=tour_id):
         tour = TourModel.objects.get(id=tour_id)
         if CheckpointModel.objects(tour=tour, index=index):
             checkpoint = CheckpointModel.objects.get(tour=tour,
                                                      index=index)
             if type(checkpoint) == MCQuestionModel or type(
                     checkpoint) == QuestionModel:
                 return [checkpoint.id]
     return []
示例#9
0
 def resolve_answers_in_tour(cls, _, info, tour_id):
     if TourModel.objects(id=tour_id):
         tour = TourModel.objects.get(id=tour_id)
         questions = QuestionModel.objects(tour=tour)
         answers = []
         if questions:
             for question in questions:
                 answers.extend(AnswerModel.objects(question=question))
         return answers
     else:
         return []
 def mutate(cls, _, info, tour_id):
     if get_jwt_claims() == admin_claim:
         if TourModel.objects(id=tour_id):
             tour = TourModel.objects.get(id=tour_id)
             tour.update(set__status='featured')
             tour.save()
             tour.reload()
             return AcceptReview(ok=BooleanField(boolean=True), tour=tour)
         else:
             return AcceptReview(ok=BooleanField(boolean=False), tour=None)
     else:
         return AcceptReview(ok=BooleanField(boolean=False), tour=None)
示例#11
0
 def resolve_answers_by_user(cls, _, info, username, tour_id):
     if UserModel.objects(username=username):
         user = UserModel.objects.get(username=username)
         if TourModel.objects(id=tour_id):
             tour = TourModel.objects.get(id=tour_id)
             owner = UserModel.objects.get(username=get_jwt_identity())
             if tour.owner == owner:
                 answers = []
                 for answer in AnswerModel.objects(user=user):
                     if answer.question.tour == tour:
                         answers.append(answer)
                 return answers
     return []
示例#12
0
 def resolve_featured(cls, _, info):
     if get_jwt_claims() == admin_claim:
         return list(TourModel.objects(status='featured'))
     else:
         return []
示例#13
0
 def resolve_tour(cls, _, info, tour_id):
     if get_jwt_claims() == admin_claim:
         if TourModel.objects(id=tour_id):
             return list(TourModel.objects(id=tour_id))
     return []
示例#14
0
 def resolve_pending(cls, _, info):
     if get_jwt_claims() == admin_claim:
         return list(TourModel.objects(status='pending'))
     else:
         return []
示例#15
0
 def resolve_my_tours(cls, _, info):
     username = get_jwt_identity()
     if UserModel.objects(username=username):
         user = UserModel.objects.get(username=username)
         return list(TourModel.objects(users__contains=user))
     return []
示例#16
0
 def resolve_featured(cls, _, info):
     return list(TourModel.objects(status='featured'))
示例#17
0
 def resolve_owned_tours(cls, _, info):
     username = get_jwt_identity()
     if UserModel.objects(username=username):
         user = UserModel.objects.get(username=username)
         return list(TourModel.objects(owner=user))
     return []