0.1.11
create_ticket def
This commit is contained in:
@@ -5,7 +5,7 @@ from django.core.exceptions import ValidationError
|
|||||||
from .models import *
|
from .models import *
|
||||||
|
|
||||||
|
|
||||||
class CreateTicketForm(forms.ModelForm):
|
class TicketForm(forms.ModelForm):
|
||||||
text = forms.CharField(required=True)
|
text = forms.CharField(required=True)
|
||||||
# files = forms.CharField(required=True)
|
# files = forms.CharField(required=True)
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ from django.contrib.auth import views
|
|||||||
from RoutesApp.js_views import new_route_view_ajax
|
from RoutesApp.js_views import new_route_view_ajax
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('support_create_ticket_ajax/', support_create_ticket_ajax, name='support_create_ticket_ajax'),
|
path('support_create_ticket_form/', support_create_ticket_form_ajax, name='support_create_ticket_form_ajax'),
|
||||||
|
path('create_ticket/', create_ticket_ajax, name='create_ticket_ajax'),
|
||||||
# path('create_/', registration_ajax, name='registration_ajax'),
|
# path('create_/', registration_ajax, name='registration_ajax'),
|
||||||
|
|
||||||
]
|
]
|
||||||
@@ -13,7 +13,7 @@ from django.template.loader import render_to_string
|
|||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
@login_required(login_url='/profile/login/')
|
@login_required(login_url='/profile/login/')
|
||||||
def support_create_ticket_ajax(request):
|
def support_create_ticket_form_ajax(request):
|
||||||
from ChatServiceApp.forms import CreateTicketForm
|
from ChatServiceApp.forms import CreateTicketForm
|
||||||
|
|
||||||
if request.method != 'POST':
|
if request.method != 'POST':
|
||||||
@@ -25,3 +25,51 @@ def support_create_ticket_ajax(request):
|
|||||||
|
|
||||||
html = render_to_string('blocks/profile/b_create_ticket.html', Dict, request=request)
|
html = render_to_string('blocks/profile/b_create_ticket.html', Dict, request=request)
|
||||||
return JsonResponse({'html': html}, status=200)
|
return JsonResponse({'html': html}, status=200)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required(login_url='/profile/login/')
|
||||||
|
def create_ticket_ajax(request):
|
||||||
|
from ChatServiceApp.forms import TicketForm
|
||||||
|
|
||||||
|
if request.method != 'POST':
|
||||||
|
raise Http404
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
data = request.POST
|
||||||
|
|
||||||
|
form = TicketForm(data)
|
||||||
|
if not form.is_valid():
|
||||||
|
form.initial = form.cleaned_data
|
||||||
|
Dict = {'form': form}
|
||||||
|
html = render_to_string('blocks/profile/b_create_ticket.html', Dict, request=request)
|
||||||
|
return JsonResponse({'html': html}, status=400)
|
||||||
|
|
||||||
|
obj = form.save(commit=False)
|
||||||
|
obj.owner = request.user
|
||||||
|
obj.save()
|
||||||
|
|
||||||
|
Dict = {
|
||||||
|
'ticket': obj
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
html = render_to_string('blocks/profile/b_support_chat.html', Dict, request=request)
|
||||||
|
|
||||||
|
res_Dict = {
|
||||||
|
'html': html
|
||||||
|
}
|
||||||
|
|
||||||
|
return JsonResponse(res_Dict)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
|
||||||
|
errors_Dict = {
|
||||||
|
'errors': {
|
||||||
|
'all__': f'ошибка в запросе = {str(e)}'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Dict = {'form': errors_Dict}
|
||||||
|
html = render_to_string('blocks/profile/b_create_ticket.html', Dict, request=request)
|
||||||
|
return JsonResponse({'html': html}, status=400)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user