Exemplo n.º 1
0
    def post(self, request, goal_slug, suggestion_slug):  # noqa
        self._get_data(request, goal_slug, suggestion_slug)
        if not self.review:
            self._create_review()

        data = ReviewSerializer(self.review).data
        data.update(request.data)

        serializer = ReviewSerializer(instance=self.review, data=data)
        if serializer.is_valid():
            self.review = serializer.save(is_draft=False)
            update_rating_and_save(self.review.revision.suggestion)
            self.review.comments.filter(is_draft=False).delete()
            notification = Notification.create_for_review(self.review)
            if notification.owner != self.review.owner:
                notification.save()
            return Response(
                {'success': 1},
                status=status.HTTP_200_OK
            )
        else:
            return Response(
                {
                    'success': 0,
                    'errors': serializer.errors
                },
                status=status.HTTP_200_OK
            )
Exemplo n.º 2
0
    def post(self, request, goal_slug, suggestion_slug):  # noqa
        self._get_data(request, goal_slug, suggestion_slug)
        if not self.review:
            self._create_review()

        data = ReviewSerializer(self.review).data
        data.update(request.data)

        serializer = ReviewSerializer(instance=self.review, data=data)
        if serializer.is_valid():
            self.review = serializer.save(is_draft=False)
            update_rating_and_save(self.review.revision.suggestion)
            self.review.comments.filter(is_draft=False).delete()
            notification = Notification.create_for_review(self.review)
            if notification.owner != self.review.owner:
                notification.save()
            return Response({'success': 1}, status=status.HTTP_200_OK)
        else:
            return Response({
                'success': 0,
                'errors': serializer.errors
            },
                            status=status.HTTP_200_OK)
Exemplo n.º 3
0
    def __update_review_and_save(self, review, form, submit):
        is_form_valid = form.is_valid()

        if 'rating' in form.cleaned_data:
            review.rating = form.cleaned_data['rating']
        if 'experience' in form.cleaned_data:
            review.experience = form.cleaned_data['experience']
        if 'description' in form.cleaned_data:
            review.description = form.cleaned_data['description']

        if is_form_valid and submit == 'save':
            review.is_draft = False
            review.save()
            update_rating_and_save(review.revision.suggestion)

            review.comments.filter(is_draft=False).delete()

            notification = Notification.create_for_review(review)
            if notification.owner != review.owner:
                notification.save()
        else:
            review.save()

        return is_form_valid
Exemplo n.º 4
0
def update_avg_rating(modeladmin, request, queryset):
    for suggestion in queryset:
        update_rating_and_save(suggestion)
Exemplo n.º 5
0
def update_avg_rating(modeladmin, request, queryset):
    for suggestion in queryset:
        update_rating_and_save(suggestion)