Beispiel #1
0
    def _update_status(self, status_update, extra_fields, **kwargs):
        """Update the fields of the StatusUpdate model.

        Args:
            status_update (reviewboard.reviews.models.StatusUpdate):
                The status update to modify.

            extra_fields (dict):
                Any additional fields to update into the status update's
                ``extra_data`` field.

            **kwargs (dict):
                A dictionary of field names and new values to update.
        """
        for field_name in ('description', 'service_id', 'summary', 'timeout',
                           'url', 'url_text'):
            if field_name in kwargs:
                setattr(status_update, field_name, kwargs[field_name])

        if 'state' in kwargs:
            status_update.state = StatusUpdate.string_to_state(kwargs['state'])

        if 'change_id' in kwargs:
            status_update.change_description = \
                ChangeDescription.objects.get(pk=kwargs['change_id'])

        if 'review_id' in kwargs:
            status_update.review = Review.objects.get(pk=kwargs['review_id'])

        self.import_extra_data(status_update, status_update.extra_data,
                               extra_fields)
Beispiel #2
0
    def _update_status(self, status_update, extra_fields, **kwargs):
        """Update the fields of the StatusUpdate model.

        Args:
            status_update (reviewboard.reviews.models.StatusUpdate):
                The status update to modify.

            extra_fields (dict):
                Any additional fields to update into the status update's
                ``extra_data`` field.

            **kwargs (dict):
                A dictionary of field names and new values to update.
        """
        for field_name in ('description', 'service_id', 'summary', 'timeout',
                           'url', 'url_text'):
            if field_name in kwargs:
                setattr(status_update, field_name, kwargs[field_name])

        if 'state' in kwargs:
            status_update.state = StatusUpdate.string_to_state(kwargs['state'])

        if 'change_id' in kwargs:
            try:
                status_update.change_description = \
                    ChangeDescription.objects.get(pk=kwargs['change_id'])
            except ChangeDescription.DoesNotExist:
                return INVALID_FORM_DATA, {
                    'fields': {
                        'change_id': ['Invalid change description ID'],
                    },
                }

        if 'review_id' in kwargs:
            try:
                status_update.review = \
                    Review.objects.get(pk=kwargs['review_id'])
            except Review.DoesNotExist:
                return INVALID_FORM_DATA, {
                    'fields': {
                        'review_id': ['Invalid review ID'],
                    },
                }

        try:
            self.import_extra_data(status_update, status_update.extra_data,
                                   extra_fields)
        except ImportExtraDataError as e:
            return e.error_payload

        if status_update.pk is None:
            code = 201
        else:
            code = 200

        status_update.save()

        return code, {
            self.item_result_key: status_update,
        }
Beispiel #3
0
    def _update_status(self, status_update, extra_fields, **kwargs):
        """Update the fields of the StatusUpdate model.

        Args:
            status_update (reviewboard.reviews.models.StatusUpdate):
                The status update to modify.

            extra_fields (dict):
                Any additional fields to update into the status update's
                ``extra_data`` field.

            **kwargs (dict):
                A dictionary of field names and new values to update.
        """
        for field_name in ('description', 'service_id', 'summary', 'timeout',
                           'url', 'url_text'):
            if field_name in kwargs:
                setattr(status_update, field_name, kwargs[field_name])

        if 'state' in kwargs:
            status_update.state = StatusUpdate.string_to_state(kwargs['state'])

        if 'change_id' in kwargs:
            status_update.change_description = \
                ChangeDescription.objects.get(pk=kwargs['change_id'])

        if 'review_id' in kwargs:
            status_update.review = Review.objects.get(pk=kwargs['review_id'])

        self.import_extra_data(status_update, status_update.extra_data,
                               extra_fields)
Beispiel #4
0
    def _update_status(self, status_update, extra_fields, **kwargs):
        """Update the fields of the StatusUpdate model.

        Args:
            status_update (reviewboard.reviews.models.StatusUpdate):
                The status update to modify.

            extra_fields (dict):
                Any additional fields to update into the status update's
                ``extra_data`` field.

            **kwargs (dict):
                A dictionary of field names and new values to update.
        """
        for field_name in ('description', 'service_id', 'summary', 'timeout',
                           'url', 'url_text'):
            if field_name in kwargs:
                setattr(status_update, field_name, kwargs[field_name])

        if 'state' in kwargs:
            status_update.state = StatusUpdate.string_to_state(kwargs['state'])

        if 'change_id' in kwargs:
            try:
                status_update.change_description = \
                    ChangeDescription.objects.get(pk=kwargs['change_id'])
            except ChangeDescription.DoesNotExist:
                return INVALID_FORM_DATA, {
                    'fields': {
                        'change_id': ['Invalid change description ID'],
                    },
                }

        if 'review_id' in kwargs:
            try:
                status_update.review = \
                    Review.objects.get(pk=kwargs['review_id'])
            except Review.DoesNotExist:
                return INVALID_FORM_DATA, {
                    'fields': {
                        'review_id': ['Invalid review ID'],
                    },
                }

        try:
            self.import_extra_data(status_update, status_update.extra_data,
                                   extra_fields)
        except ImportExtraDataError as e:
            return e.error_payload

        if status_update.pk is None:
            code = 201
        else:
            code = 200

        status_update.save()

        return code, {
            self.item_result_key: status_update,
        }
Beispiel #5
0
    def get_queryset(self, request, is_list=False, *args, **kwargs):
        """Return a queryset for StatusUpdate models.

        Args:
            request (django.http.HttpRequest):
                The HTTP request.

            is_list (boolean):
                Whether this query is for the list resource (which supports
                additional query options).

            *args (tuple):
                Additional arguments to be passed to parent resources.

            **kwargs (dict):
                Additional keyword arguments to be passed to parent resources.

        Returns:
            django.db.models.query.QuerySet:
            A QuerySet containing the matching status updates.
        """
        review_request = resources.review_request.get_object(
            request, *args, **kwargs)

        q = Q()

        if is_list:

            if 'change' in request.GET:
                q = q & Q(change_description=int(request.GET.get('change')))

            if 'service-id' in request.GET:
                q = q & Q(service_id=request.GET.get('service-id'))

            if 'state' in request.GET:
                q = q & Q(state=StatusUpdate.string_to_state(
                    request.GET.get('state')))

        return review_request.status_updates.filter(q)
Beispiel #6
0
    def get_queryset(self, request, is_list=False, *args, **kwargs):
        """Return a queryset for StatusUpdate models.

        Args:
            request (django.http.HttpRequest):
                The HTTP request.

            is_list (boolean):
                Whether this query is for the list resource (which supports
                additional query options).

            *args (tuple):
                Additional arguments to be passed to parent resources.

            **kwargs (dict):
                Additional keyword arguments to be passed to parent resources.

        Returns:
            django.db.models.query.QuerySet:
            A QuerySet containing the matching status updates.
        """
        review_request = resources.review_request.get_object(
            request, *args, **kwargs)

        q = Q()

        if is_list:

            if 'change' in request.GET:
                q = q & Q(change_description=int(request.GET.get('change')))

            if 'service-id' in request.GET:
                q = q & Q(service_id=request.GET.get('service-id'))

            if 'state' in request.GET:
                q = q & Q(state=StatusUpdate.string_to_state(
                    request.GET.get('state')))

        return review_request.status_updates.filter(q)
Beispiel #7
0
    def _update_status(self, status_update, extra_fields, **kwargs):
        """Update the fields of the StatusUpdate model.

        Args:
            status_update (reviewboard.reviews.models.StatusUpdate):
                The status update to modify.

            extra_fields (dict):
                Any additional fields to update into the status update's
                ``extra_data`` field.

            **kwargs (dict):
                A dictionary of field names and new values to update.
        """
        for field_name in ('description', 'service_id', 'summary', 'timeout',
                           'url', 'url_text'):
            if field_name in kwargs:
                setattr(status_update, field_name, kwargs[field_name])

        state = kwargs.get('state')

        if state is not None:
            # request-run is special in that it does not correspond to a stored
            # state. Instead, it will attempt to trigger a run of the
            # associated tool.
            if state == 'request-run':
                if status_update.can_run:
                    status_update.run()
                else:
                    return INVALID_FORM_DATA, {
                        'fields': {
                            'state': ['This status update cannot be run'],
                        },
                    }
            else:
                status_update.state = \
                    StatusUpdate.string_to_state(state)

        if 'change_id' in kwargs:
            try:
                status_update.change_description = \
                    ChangeDescription.objects.get(pk=kwargs['change_id'])
            except ChangeDescription.DoesNotExist:
                return INVALID_FORM_DATA, {
                    'fields': {
                        'change_id': ['Invalid change description ID'],
                    },
                }

        if 'review_id' in kwargs:
            try:
                status_update.review = \
                    Review.objects.get(pk=kwargs['review_id'])
            except Review.DoesNotExist:
                return INVALID_FORM_DATA, {
                    'fields': {
                        'review_id': ['Invalid review ID'],
                    },
                }

        try:
            self.import_extra_data(status_update, status_update.extra_data,
                                   extra_fields)
        except ImportExtraDataError as e:
            return e.error_payload

        if status_update.pk is None:
            code = 201
        else:
            code = 200

        status_update.save()

        return code, {
            self.item_result_key: status_update,
        }