django.http.response.JsonResponse - python examples

Here are the examples of the python api django.http.response.JsonResponse taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

40 Examples 7

3 View Complete Implementation : views.py
Copyright MIT License
Author : abarto
    def post(self, request, *args, **kwargs):
        with PyTessBaseAPI() as api:
            with Image.open(request.FILES['image']) as image:
                sharpened_image = image.filter(ImageFilter.SHARPEN)
                api.SetImage(sharpened_image)
                utf8_text = api.GetUTF8Text()

        return JsonResponse({'utf8_text': utf8_text})

3 View Complete Implementation : connections.py
Copyright MIT License
Author : abelardopardo
def toggle(
    request: HttpRequest,
    conn: models.Connection,
    toggle_url: str,
) -> JsonResponse:
    """Toggle the enable field in the given connection."""
    if not conn:
        messages.error(
            request,
            _('Incorrect invocation of toggle question change function.'))
        return JsonResponse({}, status=404)

    conn.enabled = not conn.enabled
    conn.save()
    conn.log(request.user, conn.toggle_event, enabled=conn.enabled)
    return JsonResponse({'is_checked': conn.enabled, 'toggle_url': toggle_url})

3 View Complete Implementation : views.py
Copyright MIT License
Author : Blueshoe
    def post(self, request, *args, **kwargs):
        # If a post is placed here, toggle the layouter_grid in the session.
        # This causes the button in the toolbar to be active or inactive and the grid to be shown or hidden.
        request.session['layouter_grid'] = not bool(request.session.get('layouter_grid'))
        # Return the result as JSON.
        res = {'show_grid': request.session['layouter_grid']}
        return JsonResponse(res, status=200)

3 View Complete Implementation : views.py
Copyright GNU Affero General Public License v3.0
Author : botshot
    def post(self, request, *args, **kwargs):
        from botshot.core.interfaces.google import GoogleActionsInterface
        body = json.loads(self.request.body.decode('utf-8'))
        logging.info(body)
        resp = GoogleActionsInterface.accept_request(body)
        return JsonResponse(resp)

3 View Complete Implementation : views.py
Copyright Apache License 2.0
Author : brownchenk
    def post(self, request, *args, **kwargs):
        uid = request.POST.get('user_id', -1)
        satle = request.POST.get('satle', '')
        startday = request.POST.get('startday', '')
        endday = request.POST.get('endday', '')

        Memo.objects.create(user_id=uid, satle=satle, startday=startday, endday=endday)

        return JsonResponse({'code': 200, 'text': 'success', 'result': None, 'errors':{}})

3 View Complete Implementation : views.py
Copyright Apache License 2.0
Author : brownchenk
    def post(self, request, *args, **kwargs):
        id = request.POST.get('memo_id', -1)
        satle = request.POST.get('memo_satle', '')


        Memo.objects.filter(id=id).update(satle=satle)

        return JsonResponse({'code': 200, 'text': 'success', 'result': None, 'errors':{}})

3 View Complete Implementation : views.py
Copyright Apache License 2.0
Author : brownchenk
    def post(self, request, *args, **kwargs):
        id = request.POST.get('memo_id', -1)

        Memo.objects.filter(id=id).delete()

        return JsonResponse({'code': 200, 'text': 'success', 'result': None, 'errors':{}})

3 View Complete Implementation : response.py
Copyright MIT License
Author : datosgobar
    def run(self, query, query_args):
        """Genera una respuesta JSON"""

        response = query.run()
        response['params'] = self._generate_params_field(query, query_args)
        return JsonResponse(response)

3 View Complete Implementation : views.py
Copyright MIT License
Author : DivineITLimited
    def get(self, request, chooser_type, *args, **kwargs):
        chooser_cls = get_chooser_for(chooser_type)
        q = request.GET.get('q')
        page = request.GET.get('page', 1)

        if chooser_cls:
            chooser = chooser_cls()
            result = chooser.paginate(request, q, page=page)

            return JsonResponse(result, status=200)
        else:
            return JsonResponse({'message': 'Invalid chooser'}, status=400)

3 View Complete Implementation : views.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : harvard-vpal
    def form_valid(self, form):
        """
        Return status code as Accepted and JSON {'status': 'ok} as submission result of the valid form.
        """
        super().form_valid(form)
        return JsonResponse(status=202, data={'status': 'ok'})