2.1.26 check_post_request_and_get_data

This commit is contained in:
SDE
2025-01-18 13:55:49 +03:00
parent 2a7a666f7d
commit 2f0e1bb396
3 changed files with 103 additions and 23 deletions

View File

@@ -1,6 +1,12 @@
from asgiref.sync import async_to_sync
from django.http import HttpResponse, Http404, FileResponse
from django.conf import settings
from BaseModels.exceptions import exception_processing
from BaseModels.print_funcs import print_ext
def get_and_set_lang(request):
from django.utils.translation import activate, get_language
@@ -30,6 +36,27 @@ def get_and_set_lang(request):
return lang
import json
from urllib.parse import unquote
def check_post_request_and_get_data(request, allow_unauthorized=False):
if request.method != 'POST':
return None
if not allow_unauthorized:
if not request.user or not request.user.is_authenticated:
return None
try:
data = request.POST.dict()
if not data and request.body:
data = json.loads(unquote(request.body))
except Exception as e:
msg, status_code = async_to_sync(exception_processing)(e, request.user)
return msg
return data
def get_add_to_ajax_response_Dict(user):
context_Dict = {}