How to use the restless.http.Http200 function in restless

To help you get started, we’ve selected a few restless examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github opencivicdata / imago / imago / helpers.py View on Github external
if 'fields' in params:
            fields = params.pop('fields').split(",")

        related, config = get_fields(self.serialize_config, fields=fields)

        self.start_debug()

        try:
            obj = self.model.objects.prefetch_related(*related).get(pk=pk)
        except ObjectDoesNotExist as e:
            raise HttpError(404, "Error: {}".format(e))

        serialized = serialize(obj, **config)
        serialized['debug'] = self.get_debug()

        response = Http200(serialized)
        response['Access-Control-Allow-Origin'] = "*"

        return response
github dobarkod / django-restless / restless / auth.py View on Github external
def get(self, request):
        return Http200(serialize(request.user, fields=self.user_fields))
github dobarkod / django-restless / restless / modelviews.py View on Github external
def put(self, request, *args, **kwargs):
        """Update the object represented by this endpoint."""

        if 'PUT' not in self.methods:
            raise HttpError(405, 'Method Not Allowed')

        Form = _get_form(self.form, self.model)
        instance = self.get_instance(request, *args, **kwargs)
        form = Form(request.data or None, request.FILES,
            instance=instance)
        if form.is_valid():
            obj = form.save()
            return Http200(self.serialize(obj))
        raise HttpError(400, 'Invalid data', errors=form.errors)
github dobarkod / django-restless / restless / views.py View on Github external
self._parse_body(request)
            authentication_required = self._process_authenticate(request)
            if authentication_required:
                return authentication_required

            response = super(Endpoint, self).dispatch(request, *args, **kwargs)
        except HttpError as err:
            response = err.response
        except Exception as ex:
            if settings.DEBUG:
                response = Http500(str(ex), traceback=traceback.format_exc())
            else:
                raise

        if not isinstance(response, HttpResponse):
            response = Http200(response)
        return response
github opencivicdata / imago / imago / helpers.py View on Github external
"total_count": count,
            }, "results": [
                serialize(x, **config) for x in data_page.object_list
            ]
        }

        if settings.DEBUG:
            response['debug'] = self.get_debug()
            response['debug'].update({
                "prefetch_fields": list(related),
                "page": page,
                "sort": sort_by,
                "field": fields,
            })

        response = Http200(response)

        response['Access-Control-Allow-Origin'] = "*"
        return response