def dashboard_unanswered _new request today datetime datetime today st

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
def dashboard_unanswered_new(request):
today = datetime.datetime.today()
start_date = datetime.datetime(today.year, today.month, today.day)
week_ago = start_date - datetime.timedelta(days=21)
customer = get_object_or_404(Customer, uuid=request.COOKIES['uuid'])
unanswered_questions = Question.objects.filter(customer=customer,
date__gte=week_ago,
is_published=True).annotate(answers_counter=Count("answer",
distinct=True)).filter(answers_counter=0).order_by("-date")
if request.method == "POST":
return HttpResponse(json.dumps([{'question_facebook_id':
question.user.facebook_id, 'question_name': question.user.name,
'question_id': question.id, 'content': question.content} for question
in unanswered_questions]))
else:
return HttpResponse(request.GET['callback']+"("+json.dumps([{'question_facebook_id':
question.user.facebook_id, 'question_name': question.user.name,
'question_id': question.id, 'content': question.content} for question
in unanswered_questions])+")")