Beispiel #1
0
def addDiagnoseComment():
    form = CommentsForm(request.form)
    resultForm=form.validate()
    if resultForm.status==rs.SUCCESS.status:
        #session['remember_me'] = form.remember_me.data
        # login and validate the user...
        diagnoseComment=Comment(form.userId,form.receiverId,form.diagnoseId,form.content)
        db_session.add(diagnoseComment)
        db_session.commit()
        db_session.flush()
        score=constant.DiagnoseScore[form.score]
        diagnose=Diagnose.getDiagnoseById(form.diagnoseId)
        diagnose.score=form.score
        Diagnose.save(diagnose)
        #为医生添加一些冗余字段
        if hasattr(diagnose,'doctor'):
            doctor=diagnose.doctor
            if score!=0:
                if doctor.goodFeedbackCount:
                    doctor.goodFeedbackCount+=1
                else:
                    doctor.goodFeedbackCount=1
            if doctor.feedbackCount:
                doctor.feedbackCount+=1
            else:
                doctor.feedbackCount=1
            Doctor.save(doctor)
        #flash('成功添加诊断评论')
        return jsonify(rs.SUCCESS.__dict__)
    return jsonify(rs.FAILURE.__dict__)
Beispiel #2
0
def addDiagnoseComment():
    form = CommentsForm(request.form)
    resultForm = form.validate()
    if resultForm.status == rs.SUCCESS.status:
        #session['remember_me'] = form.remember_me.data
        # login and validate the user...
        diagnoseComment = Comment(form.userId, form.receiverId,
                                  form.diagnoseId, form.content)
        db_session.add(diagnoseComment)
        db_session.commit()
        db_session.flush()
        score = constant.DiagnoseScore[form.score]
        diagnose = Diagnose.getDiagnoseById(form.diagnoseId)
        diagnose.score = form.score
        Diagnose.save(diagnose)
        #为医生添加一些冗余字段
        if hasattr(diagnose, 'doctor'):
            doctor = diagnose.doctor
            if score != 0:
                if doctor.goodFeedbackCount:
                    doctor.goodFeedbackCount += 1
                else:
                    doctor.goodFeedbackCount = 1
            if doctor.feedbackCount:
                doctor.feedbackCount += 1
            else:
                doctor.feedbackCount = 1
            Doctor.save(doctor)
        #flash('成功添加诊断评论')
        return jsonify(rs.SUCCESS.__dict__)
    return jsonify(rs.FAILURE.__dict__)
Beispiel #3
0
def discussion_page(id):
    #POSSIBLE BUG HERE
    form = CommentsForm(request.form)
    # Create cursor
    c, conn = connection()

    # select current article page that was clicked
    c.execute("SELECT * FROM articles WHERE id = %s", [id])

    article = c.fetchone()

    # article title is need so you can put inside comment table
    current_title = article['title']

    # Fetch all comments for html page
    c.execute("SELECT * FROM comments WHERE article_title=%s AND common_id=%s",
              [current_title, id])

    # fetch all into variable for later use
    comments = c.fetchall()

    # if post means comment is being added
    if request.method == 'POST' and form.validate():
        # get form body data as this is post method and create cursor dont need if post as this is post already at the top
        # THIS IS RETURNING AN EMPTY STRING WHY~~~~ answer: compare login html input and discussion html render field
        new_comment = form.comment.data

        # Create Cursor
        c, conn = connection()

        # Execute query
        c.execute(
            "INSERT INTO comments(article_title, comment, author, common_id) VALUES(%s, %s, %s, %s)",
            (current_title, new_comment, session['username'], id))

        # Commit to DB
        conn.commit()

        # Close connection
        c.close()
        conn.close()

        flash('Comment added!', 'success')
        return redirect(url_for('discussion_page', id=id))

    return render_template('discussion.html',
                           article=article,
                           form=form,
                           comments=comments)
Beispiel #4
0
def view(id):
    if request.method == "GET":
        info = blogs.get(blogs.c.id == id)
        form = CommentsForm()
        comment = comments.filter(comments.c.blog_id == id)
        return {'form':form, 'info':info, 'comment':comment}

    if request.method == "POST":
        form = CommentsForm()
        flag = form.validate(request.params)
        if flag:
            info = comments(**form.data)
            info.blog_id = id
            info.save()
        return redirect('/view/%s' % id)
Beispiel #5
0
def edit_comment(id):
    # Create Cursor
    c, conn = connection()

    # Get comment by id
    c.execute("SELECT * FROM comments WHERE id = %s", [id])

    # represents all rows of 1 comment of given id
    comment = c.fetchone()

    # Get form
    form = CommentsForm(request.form)

    # Populate comment form fields
    form.comment.data = comment['comment']

    # Before Post check if author of comment is the one editing
    comment_author = comment['author']
    # this variable is made so the redirect can be directed to correct article id
    comment_common_id = comment['common_id']
    if session['username'] == comment_author:
        pass
    else:
        flash('Cannot edit must be appropriate author', 'danger')
        return redirect(url_for('discussion_page', id=comment_common_id))

    if request.method == 'POST' and form.validate():
        new_comment = request.form['comment']

        # Execute
        c.execute("UPDATE comments SET comment=%s WHERE id = %s",
                  (new_comment, id))

        # Commit to DB
        conn.commit()

        # Close connection
        c.close()
        conn.close()

        flash('Comment Updated', 'success')

        return redirect(url_for('discussion_page', id=comment_common_id))

    return render_template('edit_comment.html', form=form, comment=comment)