Exemplo n.º 1
0
def feedback():
    if request.method == 'POST':
        member_username = "******"
        feedback = request.form['feedback']
        if session['logged_in']:
            member_username = current_user.username

        newFeedback = Feedbacks(member_username=member_username,
                                feedback=feedback)
        db.session.add(newFeedback)
        db.session.commit()

        flash('Submission successful! Thank you for your feedback.', 'success')
        return render_template('feedback.html')
    else:
        return render_template('feedback.html')
Exemplo n.º 2
0
def add_feedback(username):
    if "username" not in session or username != session['username']:
        # raise Unauthorized()
        return render_template('404.html'), 404

    form = FeedbackForm()

    if form.validate_on_submit():
        title=form.title.data
        content=form.content.data

        feedback=Feedbacks(title=title,content=content,username_id=username)

        db.session.add(feedback)
        db.session.commit()

        return redirect(f"/users/{feedback.username_id}")

    else:

        return render_template("feedback/add.html", form=form, username=username)
Exemplo n.º 3
0
    def salvaFeedback(
        self,
        vTipoMensagem,
        vMensagem,
        vListaNotas,
        vData=str(datetime.datetime.today())[:19],
        vRemetente=None,
        vDestinatario=None,
        vIDProjeto=None,
    ):
        try:
            iProjeto = ProjetoControle().obtemProjetoReal(vIDProjeto)

            iMensagem = Mensagens()
            iMensagem.data = vData
            iMensagem.id_destinatario = vDestinatario
            iMensagem.id_remetente = vRemetente
            iMensagem.id_tipo_mensagem = Tipo_de_Mensagem.objects.filter(id_tipo_mensagem=vTipoMensagem)[0]
            iMensagem.mensagem = vMensagem
            iMensagem.save()

            iFeedback = Feedbacks()
            iFeedback.id_mensagem = iMensagem
            iFeedback.id_projeto = iProjeto
            iFeedback.id_usuario = vDestinatario
            iFeedback.save()

            for i in range(len(vListaNotas)):
                iFeedback_Criterio = Feedaback_Criterio()
                iFeedback_Criterio.id_tipo_criterio = Tipo_de_Criterio.objects.filter(id_tipo_criterio=i + 1)[0]
                iFeedback_Criterio.id_feedback = iFeedback
                iFeedback_Criterio.nota = vListaNotas[i]
                iFeedback_Criterio.save()

            iProjeto.tem_feedback = True
            iProjeto.save()

            return True
        except Exception, e:
            self.getLogger().error("Nao foi possivel salvar o feedback: " + str(e))
            return False
Exemplo n.º 4
0
def book(request,isbn):
    q = Books.objects.filter(isbn=isbn)
    p = Feedbacks.objects.filter(isbn=isbn)

    #default values for the bookform and the feedbackform
    bookdefault = {'qty':1}
    feedbackdefault = {'feedback':1,'comment':''}
    viewdefault = {'num':1}
    num = 0

    #if it's a post request
    if request.method == 'POST':

        #If it's a feedbackform request
        if 'feedback' in  request.POST:
            feedbackform = FeedbackForm(request.POST)
            bookform = BookForm(bookdefault)
            viewform = ViewForm(bookdefault)


            if feedbackform.is_valid():
                if "loginid" in request.session:
                    review = feedbackform.cleaned_data['feedback']
                    comment = feedbackform.cleaned_data['comment']
                    customer = Customers.objects.get(loginid=request.session["loginid"])
                    book = Books.objects.get(isbn=isbn)
                    f = Feedbacks(loginid=customer,isbn=book,review=review,optionalcomment=comment,feedback_date=str(datetime.now()))
                    f.save()
                    print ('Feedback posted!')
                else:
                    print ('Login to give feedback')

        elif 'num' in request.POST:
            feedbackform = FeedbackForm(feedbackdefault)
            bookform = BookForm(bookdefault)
            viewform = ViewForm(request.POST)

            if viewform.is_valid():
                num = viewform.cleaned_data['num']

        #If it's a bookform request
        elif 'qty' in request.POST:
            bookform = BookForm(request.POST)
            feedbackform = FeedbackForm(feedbackdefault)
            feedbackform = FeedbackForm(feedbackdefault)


            if bookform.is_valid():
                if "loginid" in request.session and "login" in request.session:
                    qty = bookform.cleaned_data['qty']
                    book = Books.objects.get(isbn=isbn)

                    print ('Processing order')

                    temp = request.session["orders"]
                    if isbn in temp:
                        temp[isbn] = temp[isbn]+qty
                    else:
                        temp[isbn]= qty


                    if temp[isbn] > book.stock:
                        print 'Insufficient Stock!'

                    else:
                        print temp
                        request.session["orders"] = temp
                        return HttpResponseRedirect('/homepage/checkout')

                else:
                    return HttpResponseRedirect('/homepage/login')

        #Else if it's a rating request
        else:
            bookform = BookForm(bookdefault)
            feedbackform = FeedbackForm(feedbackdefault)


            if "loginid" in request.session and request.session['loginid'] != request.POST['loginid']:

                rating = request.POST['rating']
                ratingid = Customers.objects.get(loginid=request.session['loginid'])
                feedbackid = Customers.objects.get(loginid=request.POST['loginid'])
                book = Books.objects.get(isbn=isbn)
                p = Ratings(isbn=book,feedbackid=feedbackid,ratingid=ratingid,rating=rating)
                p.save()
                print 'Ratings posted!'
                return HttpResponseRedirect('/homepage/')

            elif request.session['loginid'] == request.POST['loginid']:
                print 'You cannot review yourself!'
            else:
                print 'Please login first'


    #If it's not a post request
    else:
        #create the default forms
        bookform = BookForm(bookdefault)
        feedbackform = FeedbackForm(feedbackdefault)
        viewform = ViewForm(viewdefault)

    #If user is logged in render the page with the Welcome ___! and signout options
    if "login" in request.session and "loginid" in request.session:
        login = request.session["login"]
        loginid = request.session["loginid"]
        user = Customers.objects.filter(loginid=loginid).values()[0]
        cursor = connection.cursor()
        print isbn
        viewform = ViewForm(viewdefault)
        cursor.execute("SELECT feedbacks.loginID, feedbacks.review, feedbacks.optionalComment from feedbacks where (feedbacks.ISBN = %s) AND feedbacks.loginID IN (select feedbackID from (select * from ratings where ratings.ISBN=%s) group by feedbackID ORDER BY avg(rating) DESC LIMIT %s)",[isbn,isbn,num])
        views = cursor.fetchall()
        cursor.close()

        return render(request,'book.html',{'bookform':bookform, 'feedbackform':feedbackform, 'viewform': viewform,'login':login,'loginid':loginid, 'book':q[0], 'feedbacks':p, 'views':views})

    #Else rendeer the page with the register and login options
    return render(request,'book.html',{'bookform':bookform, 'feedbackform':feedbackform, 'book':q[0], 'feedbacks':p})