You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.4 KiB
44 lines
1.4 KiB
import urllib
|
|
|
|
import datetime
|
|
|
|
from finance.models import ServiceRequest, RequestAlert
|
|
from lms.decors import out_api_decor
|
|
|
|
|
|
@out_api_decor(without_auth=True, method='POST', need_keys=['lead_name'])
|
|
def new_request(request, context):
|
|
date = datetime.datetime.now()
|
|
last = ServiceRequest.objects.filter(send=False).order_by('date').last()
|
|
if last and last.send_date:
|
|
if last.send_date > datetime.datetime.now():
|
|
date = last.send_date + datetime.timedelta(minutes=1)
|
|
|
|
s = ServiceRequest.objects.create(
|
|
lead_name=urllib.parse.unquote(request.POST['lead_name'], encoding='utf8').replace("+", " "),
|
|
send_date=date,
|
|
data=str({i: urllib.parse.unquote(n, encoding='utf8').replace("+", " ") for i, n in request.POST.items()}).replace('"', '')
|
|
)
|
|
if request.META.get('HTTP_REFERER'):
|
|
s.host = request.META.get('HTTP_REFERER')
|
|
s.save()
|
|
|
|
r, c = RequestAlert.objects.get_or_create(title=s.lead_name)
|
|
|
|
if not c:
|
|
r.up_count(s)
|
|
|
|
try:
|
|
if request.POST.get('name'):
|
|
s.name = urllib.parse.unquote(request.POST.get('name').replace("+", " "), encoding='utf8')
|
|
|
|
if request.POST.get('phone'):
|
|
s.phone = urllib.parse.unquote(request.POST.get('phone'), encoding='utf8')
|
|
|
|
if request.POST.get('email'):
|
|
s.email = urllib.parse.unquote(request.POST.get('email'), encoding='utf8')
|
|
|
|
finally:
|
|
s.save()
|
|
|
|
return context
|
|
|