コード例 #1
0
 def mutate(cls, _, info, badge_id, **kwargs):
     # assert caller is admin
     if not get_jwt_claims() == admin_claim:
         return UpdateBadge(badge=None, ok=BooleanField(boolean=False))
     # assert badge exists
     if not BadgeModel.objects(id=badge_id):
         return UpdateBadge(badge=None, ok=BooleanField(boolean=False))
     # get badge to modify
     badge = BadgeModel.objects.get(id=badge_id)
     # get optional parameters
     picture = kwargs.get('picture', None)
     name = kwargs.get('name', None)
     description = kwargs.get('description', None)
     cost = kwargs.get('cost', None)
     new_id = kwargs.get('new_id', None)
     if new_id is not None:
         # ensure new badge id is also unique
         if not BadgeModel.objects(id=new_id):
             badge.update(set__id=new_id)
         else:
             return UpdateBadge(badge=None, ok=BooleanField(boolean=False))
     if name is not None:
         badge.update(set__name=name)
     if cost is not None:
         badge.update(set__cost=cost)
     if description is not None:
         badge.update(set__description=description)
     if picture is not None:
         badge.picture.replace(picture, content_type='image/png')
     badge.save()
     # reload so updated object is returned
     badge.reload()
     return UpdateBadge(badge=badge, ok=BooleanField(boolean=True))
コード例 #2
0
 def mutate(cls, _, info, picture, description=None):
     if not get_jwt_claims() == admin_claim:
         return CreatePicture(ok=BooleanField(boolean=False), picture=None)
     # create document
     pic = PictureModel(description=description)
     # pass data to the FileField
     pic.picture.put(picture, content_type='image/jpeg')
     pic.save()
     return CreatePicture(ok=BooleanField(boolean=True), picture=pic)
コード例 #3
0
    def mutate(cls, _, info, username):
        if get_jwt_claims() == admin_claim:
            if UserModel.objects(username=username):
                user = UserModel.objects.get(username=username)
                user.delete()
            return DeleteUser(ok=BooleanField(boolean=True))

        else:
            return DeleteUser(ok=BooleanField(boolean=False))
コード例 #4
0
 def mutate(cls, _, info, feedback_id):
     if get_jwt_claims() == admin_claim:
         if not AppFeedbackModel.objects(id=feedback_id):
             return ReadFeedback(ok=BooleanField(boolean=False))
         else:
             feedback = AppFeedbackModel.objects.get(id=feedback_id)
             feedback.update(set__read=True)
             feedback.save()
             return ReadFeedback(ok=BooleanField(boolean=True))
     else:
         return ReadFeedback(ok=BooleanField(boolean=False))
コード例 #5
0
 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)
コード例 #6
0
 def mutate(cls, _, info, username):
     if get_jwt_claims() == admin_claim:
         if UserModel.objects(username=username):
             user = UserModel.objects.get(username=username)
             user.update(set__producer=False)
             user.save()
             user = UserModel.objects.get(username=username)
             return DemoteUser(ok=BooleanField(boolean=True), user=user)
         else:
             return DemoteUser(ok=BooleanField(boolean=False), user=None)
     else:
         return DemoteUser(ok=BooleanField(boolean=False), user=None)
コード例 #7
0
    def mutate(cls, _, info, object_id, category, sub_category, title,
               **kwargs):
        year = kwargs.get('year', None)
        picture = kwargs.get('picture', None)
        time_range = kwargs.get('time_range', None)
        art_type = kwargs.get('art_type', None)
        creator = kwargs.get('creator', None)
        material = kwargs.get('material', None)
        size = kwargs.get('size', None)
        location = kwargs.get('location', None)
        description = kwargs.get('description', None)
        additional_information = kwargs.get('additional_information', None)
        interdisciplinary_context = kwargs.get('interdisciplinary_context',
                                               None)

        if get_jwt_claims() == admin_claim:

            if not MuseumObjectModel.objects(object_id=object_id):
                museum_object = MuseumObjectModel(
                    object_id=object_id,
                    category=category,
                    sub_category=sub_category,
                    title=title,
                    time_range=time_range,
                    year=year,
                    art_type=art_type,
                    creator=creator,
                    material=material,
                    size_=size,
                    location=location,
                    description=description,
                    additional_information=additional_information,
                    interdisciplinary_context=interdisciplinary_context)
                if picture is not None:
                    pics = []
                    for pic in picture:
                        x = PictureModel()
                        x.picture.put(pic, content_type='image/jpeg')
                        x.save()
                        pics.append(x)
                    museum_object.update(set__picture=pics)
                museum_object.save()
                return CreateMuseumObject(ok=BooleanField(boolean=True),
                                          museum_object=museum_object)

            else:
                return CreateMuseumObject(ok=BooleanField(boolean=False),
                                          museum_object=None)
        else:
            return CreateMuseumObject(ok=BooleanField(boolean=False),
                                      museum_object=None)
コード例 #8
0
 def mutate(cls, _, info):
     if get_jwt_claims() == admin_claim:
         letters = string.ascii_lowercase
         # generate random code
         code_string = ''.join(random.choice(letters) for i in range(5))
         # if the generated code already exists generate a new one
         while CodeModel.objects(code=code_string):
             code_string = ''.join(random.choice(letters) for i in range(5))
         code = CodeModel(code=code_string)
         code.save()
         return CreateCode(ok=BooleanField(boolean=True),
                           code=StringField(string=code_string))
     else:
         return CreateCode(ok=BooleanField(boolean=False), code=None)
コード例 #9
0
    def mutate(cls, _, info, object_id):
        if get_jwt_claims() == admin_claim:
            if MuseumObjectModel.objects(object_id=object_id):
                museum_object = MuseumObjectModel.objects.get(
                    object_id=object_id)
                pictures = museum_object.picture
                # delete associated pictures
                for picture in pictures:
                    picture.delete()
                # delete object from user favourites
                favourites = FavouritesModel.objects(
                    favourite_objects__contains=museum_object)
                for favourite in favourites:
                    objects = favourite.favourite_objects
                    objects.remove(museum_object)
                    favourite.update(set__favourite_objects=objects)
                    favourite.save()
                # delete object reference from questions
                questions = QuestionModel.objects(
                    linked_objects__contains=museum_object)
                for question in questions:
                    linked = question.linked_objects
                    linked.remove(museum_object)
                    question.update(set__linked_objects=linked)
                # delete checkpoints that reference the object
                checkpoints = ObjectCheckpointModel.objects(
                    museum_object=museum_object)
                for checkpoint in checkpoints:
                    # update tour accordingly
                    tour = checkpoint.tour
                    max_idx = tour.current_checkpoints
                    max_idx -= 1
                    # reduce number of current checkpoints
                    tour.update(set__current_checkpoints=max_idx)
                    tour.save()
                    index = checkpoint.index
                    tour_checkpoints = CheckpointModel.objects(tour=tour)
                    # adjust index of later checkpoints in the tour
                    for cp in tour_checkpoints:
                        if cp.index > index:
                            cpidx = cp.index
                            cpidx -= 1
                            cp.update(set__index=cpidx)
                            cp.save()
                    checkpoint.delete()
                museum_object.delete()
            return DeleteMuseumObject(ok=BooleanField(boolean=True))

        else:
            return DeleteMuseumObject(ok=BooleanField(boolean=False))
コード例 #10
0
 def mutate(cls, _, info, password):
     username = get_jwt_identity()
     user = AdminModel.objects.get(username=username)
     # password is again saved as a hash
     user.update(set__password=generate_password_hash(password))
     user.save()
     return ChangePassword(ok=BooleanField(boolean=True))
コード例 #11
0
 def mutate(cls, _, info, picture_id, picture):
     # assert caller is admin
     if not get_jwt_claims() == admin_claim:
         return UpdateProfilePicture(picture=None,
                                     ok=BooleanField(boolean=False))
     # assert object exists
     if not ProfilePictureModel.objects(id=picture_id):
         return UpdateProfilePicture(picture=None,
                                     ok=BooleanField(boolean=False))
     # get object to modify
     profile_picture = ProfilePictureModel.objects.get(id=picture_id)
     profile_picture.picture.replace(picture, content_type='image/jpeg')
     profile_picture.save()
     # reload so updated object is returned
     profile_picture.reload()
     return UpdateProfilePicture(picture=profile_picture,
                                 ok=BooleanField(boolean=True))
コード例 #12
0
    def mutate(cls, _, info, picture_id, **kwargs):
        # assert caller is admin
        if not get_jwt_claims() == admin_claim:
            return UpdatePicture(picture=None, ok=BooleanField(boolean=False))
        # assert picture exists
        if not PictureModel.objects(id=picture_id):
            return UpdatePicture(picture=None, ok=BooleanField(boolean=False))
        # get object to modify
        picture_object = PictureModel.objects.get(id=picture_id)
        # get optional parameters
        picture = kwargs.get('picture', None)
        description = kwargs.get('description', None)

        if description is not None:
            picture_object.update(set__description=description)
        if picture is not None:
            picture_object.picture.replace(picture, content_type='image/jpeg')
        picture_object.save()
        # reload so updated object is returned
        picture_object.reload()
        return UpdatePicture(picture=picture_object,
                             ok=BooleanField(boolean=True))
コード例 #13
0
 def mutate(cls, _, info, name, badge_id, picture, description, cost):
     # ensure caller is admin
     if get_jwt_claims() == admin_claim:
         # ensure badge id is unique
         if not BadgeModel.objects(id=badge_id):
             badge = BadgeModel(id=badge_id,
                                name=name,
                                description=description,
                                cost=cost)
             badge.picture.put(picture, content_type='image/png')
             badge.save()
             badge.reload()
             # add badge to the progress dict of all users.
             for user in UserModel.objects.all():
                 badges = user.badge_progress
                 badges[badge_id] = 0
                 user.update(set__badge_progress=badges)
                 user.save()
             return CreateBadge(badge=badge, ok=BooleanField(boolean=True))
         else:
             return CreateBadge(badge=None, ok=BooleanField(boolean=False))
     else:
         return CreateBadge(badge=None, ok=BooleanField(boolean=False))
コード例 #14
0
 def mutate(cls, _, info, checkpoint_id, **kwargs):
     # assert caller is admin
     if not get_jwt_claims() == admin_claim:
         return EditCheckpoint(checkpoint=None,
                               ok=BooleanField(boolean=False))
     # assert checkpoint exists
     if not CheckpointModel.objects(id=checkpoint_id):
         return EditCheckpoint(checkpoint=None,
                               ok=BooleanField(boolean=False))
     # get checkpoint object
     checkpoint = CheckpointModel.objects.get(id=checkpoint_id)
     # get all the optional arguments
     text = kwargs.get('text', None)
     object_id = kwargs.get('object_id', None)
     picture_id = kwargs.get('picture_id', None)
     question = kwargs.get('question', None)
     linked_objects = kwargs.get('linked_objects', None)
     possible_answers = kwargs.get('possible_answers', None)
     correct_answers = kwargs.get('correct_answers', None)
     max_choices = kwargs.get('max_choices', None)
     show_text = kwargs.get('show_text', False)
     show_picture = kwargs.get('show_picture', False)
     show_details = kwargs.get('show_details', False)
     # handle fields that all checkpoints share first
     if text is not None:
         checkpoint.update(set__text=text)
     if show_text != checkpoint.show_text:
         checkpoint.update(set__show_text=show_text)
     if show_picture != checkpoint.show_picture:
         checkpoint.update(set__show_picture=show_picture)
     if show_details != checkpoint.show_details:
         checkpoint.update(set__show_details=show_details)
     checkpoint.save()
     checkpoint.reload()
     # treat checkpoint update depending on the type of the checkpoint
     if isinstance(checkpoint, ObjectCheckpointModel):
         # assert new object exists
         if object_id is not None:
             if not MuseumObjectModel.objects(object_id=object_id):
                 return EditCheckpoint(checkpoint=None,
                                       ok=BooleanField(boolean=False))
             museum_object = MuseumObjectModel.objects.get(
                 object_id=object_id)
             checkpoint.update(set__museum_object=museum_object)
         checkpoint.save()
         checkpoint.reload()
         return EditCheckpoint(checkpoint=checkpoint,
                               ok=BooleanField(boolean=True))
     elif isinstance(checkpoint, PictureCheckpointModel):
         # assert new picture exists
         if picture_id is not None:
             if not PictureModel.objects(id=picture_id):
                 return EditCheckpoint(checkpoint=None,
                                       ok=BooleanField(boolean=False))
             pic = PictureModel.objects.get(id=picture_id)
             checkpoint.update(set__picture=pic)
         if text is not None:
             checkpoint.update(set__text=text)
         checkpoint.save()
         checkpoint.reload()
         return EditCheckpoint(checkpoint=checkpoint,
                               ok=BooleanField(boolean=True))
     # check MCQuestion first because a MCQuestion would pass the check for isinstance(checkpoint,QuestionModel)
     elif isinstance(checkpoint, MCQuestionModel):
         # question text is inherited from question
         if question is not None:
             checkpoint.update(set__question=question)
         if possible_answers is not None:
             checkpoint.update(set__possible_answers=possible_answers)
         if correct_answers is not None:
             checkpoint.update(set__correct_answers=correct_answers)
         if max_choices is not None:
             checkpoint.update(set__max_choices=max_choices)
         # linked objects are also inherited from question
         if linked_objects is not None:
             new_links = []
             for oid in linked_objects:
                 if not MuseumObjectModel.objects(object_id=oid):
                     return EditCheckpoint(checkpoint=None,
                                           ok=BooleanField(boolean=False))
                 else:
                     new_links.append(
                         MuseumObjectModel.objects.get(object_id=oid))
             checkpoint.update(set__linked_objects=new_links)
         checkpoint.save()
         checkpoint.reload()
         return EditCheckpoint(checkpoint=checkpoint,
                               ok=BooleanField(boolean=True))
     elif isinstance(checkpoint, QuestionModel):
         if question is not None:
             checkpoint.update(set__question=question)
         if linked_objects is not None:
             new_links = []
             for oid in linked_objects:
                 if not MuseumObjectModel.objects(object_id=oid):
                     return EditCheckpoint(checkpoint=None,
                                           ok=BooleanField(boolean=False))
                 else:
                     new_links.append(
                         MuseumObjectModel.objects.get(object_id=oid))
             checkpoint.update(set__linked_objects=new_links)
         checkpoint.save()
         checkpoint.reload()
         return EditCheckpoint(checkpoint=checkpoint,
                               ok=BooleanField(boolean=True))
     # last remaining choice is the checkpoint was a simple text checkpoint
     else:
         return EditCheckpoint(checkpoint=checkpoint,
                               ok=BooleanField(boolean=True))
コード例 #15
0
    def mutate(cls, _, info, object_id, **kwargs):
        if get_jwt_claims() == admin_claim:
            if not MuseumObjectModel.objects(object_id=object_id):
                return UpdateMuseumObject(ok=BooleanField(boolean=False),
                                          museum_object=None)
            else:
                museum_object = MuseumObjectModel.objects.get(
                    object_id=object_id)
                category = kwargs.get('category', None)
                sub_category = kwargs.get('sub_category', None)
                title = kwargs.get('title', None)
                time_range = kwargs.get('time_range', None)
                year = kwargs.get('year', None)
                picture = kwargs.get('picture', None)
                art_type = kwargs.get('art_type', None)
                creator = kwargs.get('creator', None)
                material = kwargs.get('material', None)
                size = kwargs.get('size', None)
                location = kwargs.get('location', None)
                description = kwargs.get('description', None)
                additional_information = kwargs.get('additional_information',
                                                    None)
                interdisciplinary_context = kwargs.get(
                    'interdisciplinary_context', None)

                if category is not None:
                    museum_object.update(set__category=category)
                if sub_category is not None:
                    museum_object.update(set__sub_category=sub_category)
                if title is not None:
                    museum_object.update(set__title=title)
                if year is not None:
                    museum_object.update(set__year=year)
                if picture is not None:
                    pics = []
                    for pid in picture:
                        if PictureModel.objects(id=pid):
                            pic = PictureModel.objects.get(id=pid)
                            pics.append(pic)
                        else:
                            return UpdateMuseumObject(
                                ok=BooleanField(boolean=False),
                                museum_object=None)
                    museum_object.update(set__picture=pics)
                if art_type is not None:
                    museum_object.update(set__art_type=art_type)
                if time_range is not None:
                    museum_object.update(set__time_range=time_range)
                if additional_information is not None:
                    museum_object.update(
                        set__additional_information=additional_information)
                if creator is not None:
                    museum_object.update(set__creator=creator)
                if material is not None:
                    museum_object.update(set__material=material)
                if size is not None:
                    museum_object.update(set__size_=size)
                if location is not None:
                    museum_object.update(set__location=location)
                if description is not None:
                    museum_object.update(set__description=description)
                if interdisciplinary_context is not None:
                    museum_object.update(
                        set__interdisciplinary_context=interdisciplinary_context
                    )
                museum_object.save()
                museum_object.reload()
                return UpdateMuseumObject(ok=BooleanField(boolean=True),
                                          museum_object=museum_object)
        else:
            return UpdateMuseumObject(ok=BooleanField(boolean=False),
                                      museum_object=None)