def post(self, record_id):
        """Attach a list of tags to a record.

        If a tag in the list exists in database then it is attached
        to the record else the tag is created an then it is attached
        to the record
        :param record_id: the identifier of the record
        """
        json_data = request.get_json()
        attach_tags_validator = RESTValidator(add_tags_schema)
        if attach_tags_validator.validate(json_data) is False:
            raise TagValidationError(
                error_msg="Validation error in attaching tags on record",
                status_code=400,
                error_list=attach_tags_validator.get_errors())
        uid = current_user.get_id()
        tags_just_attached = tags_api.attach_tags_to_record(uid,
                                                            json_data['tags'],
                                                            record_id)
        if len(tags_just_attached) == 0:
            return []
        else:
            return map(
                lambda t: TagRepresenation(t).marshal(), tags_just_attached
            )
    def post(self):
        """Create a new tag.

        Creates a new tag and sets as owner the current user.
        """
        json_data = request.get_json()
        v = RESTValidator(tag_post_schema)
        if v.validate(json_data) is False:
            raise TagValidationError(
                error_msg="Validation error for tag creation",
                status_code=400,
                error_list=v.get_errors())
        uid = current_user.get_id()
        tag_to_create = tags_api.create_tag_for_user(uid, json_data['name'])
        tag_to_return = TagRepresenation(tag_to_create)
        return tag_to_return.marshal(), 201
    def post(self):
        """Create a new tag.

        Creates a new tag and sets as owner the current user.
        """
        json_data = request.get_json()
        v = RESTValidator(tag_post_schema)
        if v.validate(json_data) is False:
            raise TagValidationError(
                error_msg="Validation error for tag creation",
                status_code=400,
                error_list=v.get_errors())
        uid = current_user.get_id()
        tag_to_create = tags_api.create_tag_for_user(uid, json_data['name'])
        tag_to_return = TagRepresenation(tag_to_create)
        return tag_to_return.marshal(), 201
    def patch(self, tag_name):
        """Update a tag.

        The attributes that can be updated are:
        - group name
        - group access rights
        - show_in_description
        :param tag_name: the name of the tag to update
        """
        json_data = request.get_json()
        v = RESTValidator(tag_update_schema)
        if v.validate(json_data) is False:
            raise TagValidationError(
                error_msg="Validation for tag update failed",
                status_code=400,
                error_list=v.get_errors())
        uid = current_user.get_id()
        tag_retrieved = tags_api.update_tag_of_user(uid, tag_name, json_data)
        tag = TagRepresenation(tag_retrieved)
        return tag.marshal(), 201
    def patch(self, tag_name):
        """Update a tag.

        The attributes that can be updated are:
        - group name
        - group access rights
        - show_in_description
        :param tag_name: the name of the tag to update
        """
        json_data = request.get_json()
        v = RESTValidator(tag_update_schema)
        if v.validate(json_data) is False:
            raise TagValidationError(
                error_msg="Validation for tag update failed",
                status_code=400,
                error_list=v.get_errors())
        uid = current_user.get_id()
        tag_retrieved = tags_api.update_tag_of_user(uid, tag_name, json_data)
        tag = TagRepresenation(tag_retrieved)
        return tag.marshal(), 201
    def post(self, record_id):
        """Attach a list of tags to a record.

        If a tag in the list exists in database then it is attached
        to the record else the tag is created an then it is attached
        to the record
        :param record_id: the identifier of the record
        """
        json_data = request.get_json()
        attach_tags_validator = RESTValidator(add_tags_schema)
        if attach_tags_validator.validate(json_data) is False:
            raise TagValidationError(
                error_msg="Validation error in attaching tags on record",
                status_code=400,
                error_list=attach_tags_validator.get_errors())
        uid = current_user.get_id()
        tags_just_attached = tags_api.attach_tags_to_record(
            uid, json_data['tags'], record_id)
        if len(tags_just_attached) == 0:
            return []
        else:
            return map(lambda t: TagRepresenation(t).marshal(),
                       tags_just_attached)