コード例 #1
0
    def update(self, **kwargs):
        """Update contents of this review.

        Returns:
            New revision of this review.
        """
        license_id = kwargs.pop('license_id', None)
        if license_id is not None:
            if not self.is_draft:  # If trying to convert published review into draft.
                raise BadRequest(gettext("Changing license of a published review is not allowed."))
            self.license_id = license_id

        language = kwargs.pop('language', None)
        if language is not None:
            self.language = language

        is_draft = kwargs.pop('is_draft', None)
        if is_draft is not None:  # This should be done after all changes that depend on review being a draft.
            if not self.is_draft and is_draft:  # If trying to convert published review into draft.
                raise BadRequest(gettext("Converting published reviews back to drafts is not allowed."))
            self.is_draft = is_draft

        new_revision = Revision.create(self.id, kwargs.pop('text'))
        cache.invalidate_namespace(Review.CACHE_NAMESPACE)

        if kwargs:
            # FIXME: Revision creation and other changes need to be rolled back
            # there, but there's a `commit` in Revision.create.
            raise TypeError('Unexpected **kwargs: %r' % kwargs)

        return new_revision
コード例 #2
0
    def create(cls, **kwargs):
        if 'release_group' in kwargs:
            entity_id = kwargs.pop('release_group')
            entity_type = 'release_group'
        else:
            entity_id = kwargs.pop('entity_id')
            entity_type = kwargs.pop('entity_type')

        review = Review(
            entity_id=entity_id,
            entity_type=entity_type,
            user=kwargs.pop('user'),
            language=kwargs.pop('language', None),
            is_draft=kwargs.pop('is_draft', False),
            license_id=kwargs.pop('license_id', DEFAULT_LICENSE_ID),
            source=kwargs.pop('source', None),
            source_url=kwargs.pop('source_url', None)
        )
        db.session.add(review)
        db.session.flush()
        db.session.add(Revision(review_id=review.id, text=kwargs.pop('text')))

        if kwargs:
            db.session.rollback()
            raise TypeError('Unexpected **kwargs: %r' % kwargs)

        db.session.commit()
        cache.invalidate_namespace(Review.CACHE_NAMESPACE)

        return review
コード例 #3
0
    def create(cls, **kwargs):
        if 'release_group' in kwargs:
            entity_id = kwargs.pop('release_group')
            entity_type = 'release_group'
        else:
            entity_id = kwargs.pop('entity_id')
            entity_type = kwargs.pop('entity_type')

        review = Review(entity_id=entity_id,
                        entity_type=entity_type,
                        user=kwargs.pop('user'),
                        language=kwargs.pop('language', None),
                        is_draft=kwargs.pop('is_draft', False),
                        license_id=kwargs.pop('license_id',
                                              DEFAULT_LICENSE_ID),
                        source=kwargs.pop('source', None),
                        source_url=kwargs.pop('source_url', None))
        db.session.add(review)
        db.session.flush()
        db.session.add(Revision(review_id=review.id, text=kwargs.pop('text')))

        if kwargs:
            db.session.rollback()
            raise TypeError('Unexpected **kwargs: %r' % kwargs)

        db.session.commit()
        cache.invalidate_namespace(Review.CACHE_NAMESPACE)

        return review
コード例 #4
0
    def update(self, **kwargs):
        """Update contents of this review.

        Returns:
            New revision of this review.
        """
        license_id = kwargs.pop('license_id', None)
        if license_id is not None:
            if not self.is_draft:  # If trying to convert published review into draft.
                raise BadRequest(
                    lazy_gettext(
                        "Changing license of a published review is not allowed."
                    ))
            self.license_id = license_id

        language = kwargs.pop('language', None)
        if language is not None:
            self.language = language

        is_draft = kwargs.pop('is_draft', None)
        if is_draft is not None:  # This should be done after all changes that depend on review being a draft.
            if not self.is_draft and is_draft:  # If trying to convert published review into draft.
                raise BadRequest(
                    lazy_gettext(
                        "Converting published reviews back to drafts is not allowed."
                    ))
            self.is_draft = is_draft

        new_revision = Revision.create(self.id, kwargs.pop('text'))
        cache.invalidate_namespace(Review.CACHE_NAMESPACE)

        if kwargs:
            # FIXME: Revision creation and other changes need to be rolled back
            # there, but there's a `commit` in Revision.create.
            raise TypeError('Unexpected **kwargs: %r' % kwargs)

        return new_revision