コード例 #1
0
ファイル: views.py プロジェクト: derris/whhhy
 def feedback(self,request):
     template='feedback.html'
     para=BaseView().para
     para['repeat'] = False
     para['messages'] = Message.objects.filter(show=True)[:20]
     try:
         Message.objects.filter(show=True)[20]
         para['more'] = True
     except:pass
 
     if request.method == 'POST':
         form = MessageForm(request.POST)
         para['form'] = form
         if form.is_valid():
             content = form.cleaned_data['content']
             name    = form.cleaned_data['name']
             email   = form.cleaned_data['email']
             ip      = request.META['REMOTE_ADDR']
             at      = None
             m       = Message(customer=Customer.objects.get(name=name),content=content,ip=ip,at=at)
             try:
                 if content==para['messages'][0].content:
                     para['repeat']=True
                     return render_to_response(template, para)
                 else:
                     m.save()
                     para['ok']=True
                     return render_to_response(template, para)
             except:
                 para['ok']=True
                 m.save()
                 return render_to_response(template, para)
         else:
             wrong = request.POST
             wrong.name = form['name']
             wrong.email = form['email']
             wrong.content = form['content']
             para['worng'] = wrong
             return render_to_response(template, para)
     else:
         para['form'] = MessageForm()
         return render_to_response(template, para)
コード例 #2
0
ファイル: views.py プロジェクト: Crackpot/gftop
 def daily(cls,request,date):
     "daily detail and form system"
     template ='daily.html'
     para = BaseView().para
     para['repeat'] = False
     para['daily'] = Daily.objects.filter(show=True).get(date=date)
     para['messages'] = para['daily'].message_set.filter(show=True).order_by('date')
     if request.method == 'POST':
         form = MessageForm(request.POST)
         para['form'] = form
         if form.is_valid():
             content = form.cleaned_data['content']
             name = form.cleaned_data['name']
             email = form.cleaned_data['email']
             ip = request.META['REMOTE_ADDR']
             at = para['daily']
             m = Message(customer=Customer.objects.get(name=name),content=content,ip=ip,at=at)
             try:
                 if content==Message.objects.filter(at=para['daily'])[0].content:
                     para['repeat']=True
                     return render_to_response(template, para)
                 else:
                     m.save()
                     para['ok']=True
                     return render_to_response(template, para)
             except:
                 para['ok']=True
                 m.save()
                 return render_to_response(template, para)
         else:
             wrong = request.POST
             wrong.name = form['name']
             wrong.email = form['email']
             wrong.content = form['content']
             para['worng'] = wrong
             return render_to_response(template, para)
     else:
         para['form'] = MessageForm()
         return render_to_response(template, para)
コード例 #3
0
ファイル: views.py プロジェクト: derris/whhhy
def ajax(request):
    if request.method == 'POST':
        url  = request.META['HTTP_REFERER']
        date = url[-11:-1]
        form = MessageForm(request.POST)
        try:
            daily = Daily.objects.get(date=date)
        except:
            daily = None
        if form.is_valid():
            content = form.cleaned_data['content']
            name    = form.cleaned_data['name']
            email   = form.cleaned_data['email']
            ip      = request.META['REMOTE_ADDR']
            at      = daily
            m       = Message(customer=Customer.objects.get(name = name),content = content,ip = ip,at = at)
            m.save()
            number=Message.objects.filter(at=daily).count()
            return render_to_response('ajax.xml', {'form':form,'message':m,'number':number,'ok':True})
        else:
            return render_to_response('ajax.xml', {'form':form,'ok':False})
    else:
        return render_to_response('ajax.xml', {'ok':False})
コード例 #4
0
def getresponse(request):
    print('in response')
    cnt = request.GET.get('count', None)
    print('cnt--' + cnt)
    count = int(cnt)

    response_data = {}

    if (count == 12):
        response_data['res'] = 'Okay we are done then...Thank you!! :)'
        fobj = Feedback.objects.get(id=request.session['f_id'])
        msgObj = Message(f_id=fobj,
                         msg="" + request.GET.get('responseString', ""),
                         status=request.session['sentiment'])
        msgObj.save()
        feedbackObj = Feedback.objects.get(id=request.session['f_id'])
        feedbackObj.q1 = request.session['q'][0]
        feedbackObj.q2 = request.session['q'][1]
        feedbackObj.q3 = request.session['q'][2]
        feedbackObj.q4 = request.session['q'][3]
        feedbackObj.q5 = request.session['q'][4]
        feedbackObj.q6 = request.session['q'][5]

        feedbackObj.save()  # this will update only
        return HttpResponse(json.dumps(response_data),
                            content_type="application/json")

    if (count > 12):
        response_data[
            'res'] = 'We have collected your feedback... You can exit the window now!! :)'
        return HttpResponse(json.dumps(response_data),
                            content_type="application/json")

    row = int(count / 2)

    if (count == 0):
        response_data['res'] = getQuestion(row, 0)
        return HttpResponse(json.dumps(response_data),
                            content_type="application/json")

    if (count % 2 == 0):
        col = 0
        fobj = Feedback.objects.get(id=request.session['f_id'])
        msgObj = Message(f_id=fobj,
                         msg="" + request.GET.get('responseString', ""),
                         status=request.session['sentiment'])
        msgObj.save()
    else:
        request.session['lastResponse'] = "" + request.GET.get(
            'responseString', "")

        pos, neg = sentiment2.predict(request.session['lastResponse'])
        print('sentiment analysis on--' + request.session['lastResponse'])

        if (pos > neg):
            request.session['q'][row] = 1
            request.session['sentiment'] = 1
            col = 1
        else:
            request.session['q'][row] = 0
            request.session['sentiment'] = 0
            col = 2

    response_data['res'] = getQuestion(row, col)
    #response_data['message'] = 'Some error message'
    #return HttpResponse({'record':'str data'}, content_type='json')
    return HttpResponse(json.dumps(response_data),
                        content_type="application/json")