Пример #1
0
 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
 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
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 feedback_form():
    return {'form': MessageForm()}