Skip to content

Commit

Permalink
add comment review function
Browse files Browse the repository at this point in the history
  • Loading branch information
hustlzp committed Feb 26, 2013
1 parent b4a8da0 commit 5a28985
Show file tree
Hide file tree
Showing 9 changed files with 389 additions and 75 deletions.
333 changes: 272 additions & 61 deletions xcz.sublime-workspace

Large diffs are not rendered by default.

Binary file modified xichuangzhu/controllers/love.pyc
Binary file not shown.
17 changes: 15 additions & 2 deletions xichuangzhu/controllers/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,38 @@
from xichuangzhu.models.collection_model import Collection
from xichuangzhu.models.dynasty_model import Dynasty
from xichuangzhu.models.review_model import Review
from xichuangzhu.models.comment_model import Comment

import markdown2

# page single review
#--------------------------------------------------

# view
@app.route('/review/<int:review_id>')
def single_review(review_id):
review = Review.get_review(review_id)
review['Content'] = markdown2.markdown(review['Content'])
return render_template('single_review.html', review=review)
comments = Comment.get_comments_by_review(review_id)
return render_template('single_review.html', review=review, comments=comments)

# proc - add comment
@app.route('/review/add_comment/<int:user_id>/<int:review_id>', methods=['POST'])
def add_comment(user_id, review_id):
comment = request.form['comment']
Comment.add_comment(user_id, review_id, comment, 0, 0)
return redirect(url_for('single_review', review_id=review_id))

# page all reviews
#--------------------------------------------------

# view
@app.route('/reviews')
def reviews():
reviews = Review.get_hot_reviews()
return render_template('reviews.html', reviews=reviews)

# page add review to a work
# page add review
#--------------------------------------------------

@app.route('/review/add/<int:work_id>', methods=['GET', 'POST'])
Expand Down
Binary file modified xichuangzhu/controllers/review.pyc
Binary file not shown.
25 changes: 25 additions & 0 deletions xichuangzhu/models/comment_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from xichuangzhu import conn, cursor

class Comment:

# GET

# get comments by review
@staticmethod
def get_comments_by_review(review_id):
query = '''SELECT comment.CommentID, comment.Comment, comment.Time, user.UserID, user.Name, user.Avatar\n
FROM comment, user\n
WHERE comment.UserID = user.UserID
AND comment.ReviewID = %d''' % review_id
cursor.execute(query)
return cursor.fetchall()

# NEW

# add comment to a review
@staticmethod
def add_comment(user_id, review_id, comment, is_root=0, parent_comment_id=0):
query = '''INSERT INTO comment (UserID, ReviewID, Comment, IsRoot, ParentCommentID)\n
VALUES (%d, %d, '%s', %d, %d)''' % (user_id, review_id, comment, is_root, parent_comment_id)
cursor.execute(query)
return conn.commit()
Binary file added xichuangzhu/models/comment_model.pyc
Binary file not shown.
7 changes: 5 additions & 2 deletions xichuangzhu/static/style/page.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ body #main-wap .tooltip{font-family:'arial','宋体';text-indent:0;font-weight:n
#page-single-dynasty .dynasty-introduction{font-size:14px;}
#page-single-dynasty .author-item{margin-bottom:10px;}#page-single-dynasty .author-item .author{font-size:16px;font-weight:bold;}
#page-single-dynasty .author-item .author-introduction{font-size:14px;}
#page-single-review .user-avatar{float:left;margin-top:5px;}
#page-single-review .review-wap{margin-left:65px;}#page-single-review .review-wap .review-extra-info{margin-bottom:10px;}
#page-single-review .review-extra-info{margin-bottom:10px;}
#page-single-review .user-avatar{float:left;margin-top:15px;}
#page-single-review .review-wap{margin-left:65px;}#page-single-review .review-wap .review-content{margin-bottom:20px;}
#page-single-review .review-wap .comment-item{margin-bottom:15px;clear:both;}#page-single-review .review-wap .comment-item .comment-user-avatar{float:left;margin-top:5px;}
#page-single-review .review-wap .comment-item .comment-wap{margin-left:60px;font-size:12px;}#page-single-review .review-wap .comment-item .comment-wap .comment-extra-info{line-height:22px;}
#page-reviews .review-item{margin-bottom:15px;}#page-reviews .review-item .user-avatar{float:left;margin-top:5px;}
#page-reviews .review-item .review-wap{margin-left:60px;}#page-reviews .review-item .review-wap .review-title{font-size:16px;font-weight:bold;}
#page-reviews .review-item .review-wap .review-content{font-size:12px;line-height:22px;}
Expand Down
43 changes: 40 additions & 3 deletions xichuangzhu/static/style/page.less
Original file line number Diff line number Diff line change
Expand Up @@ -466,16 +466,47 @@ body{
//-----------------------------------------------------
#page-single-review{

.review-extra-info{
margin-bottom: 10px;
}

.user-avatar{
float: left;
margin-top: 5px;
margin-top: 15px;
}

.review-wap{
margin-left: 65px;

.review-extra-info{
margin-bottom: 10px;
// .review-extra-info{
// margin-bottom: 10px;
// }

.review-content{
margin-bottom: 20px;
}

.comment-item{
margin-bottom: 15px;
clear: both;

.comment-user-avatar{
float: left;
margin-top: 5px;
}

.comment-wap{
margin-left: 60px;
font-size: 12px;

.comment-extra-info{
line-height: 22px;
}

.comment-body{

}
}
}
}
}
Expand All @@ -486,6 +517,12 @@ body{
.review-item{
margin-bottom: 15px;

// .review-extra-info{
// font-size: 12px;
// line-height: 22px;
// margin-bottom: 20px;
// }

.user-avatar{
float: left;
margin-top: 5px;
Expand Down
39 changes: 32 additions & 7 deletions xichuangzhu/templates/single_review.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,49 @@
{% if session.user_id == review.UserID %}
<a class="btn btn-small pull-right" href="{{ url_for('edit_review', review_id=review.ReviewID) }}">编辑 <span class="icon-edit"></span></a>
{% endif %}

<h1 class="review-title">{{ review.Title }}</h1>

<a href="#" class="user-avatar">

<a href="{{ url_for('people', user_id=review.UserID) }}" class="user-avatar">
<img src="{{ review.Avatar }}">
</a>

<div class="review-wap">
<h1 class="review-title">{{ review.Title }}</h1>

<div class="review-extra-info">
<a href="#">{{ review.Name }}</a>
<a href="{{ url_for('people', user_id=review.UserID) }}">{{ review.Name }}</a>
评论
<a href="{{ url_for('single_work', work_id=review.WorkID) }}">{{ review.WorkTitle }}〔{{ review.Author }}〕</a>
{{ review.Time }}
</div>

<div>{{ review.Content|safe }}</div>
</div>
<div class="review-content">{{ review.Content|safe }}</div>

<!-- <h2>回复</h2> -->

{% for comment in comments %}
<div class="comment-item clearfix">
<a class="comment-user-avatar" href="{{ url_for('people', user_id=comment.UserID) }}">
<img src="{{ comment.Avatar }}">
</a>

<div class="comment-wap">
<div class="comment-extra-info">
<a href="{{ url_for('people', user_id=comment.UserID) }}">{{ comment.Name }}</a>
{{ comment.Time }}
</div>

<div class="comment-body">{{ comment.Comment }}</div>
</div>
</div>
{% endfor %}

<form id="add-review-comment" method="post" action="{{ url_for('add_comment', review_id=review.ReviewID, user_id=session.user_id) }}">

<textarea name="comment" class="input-xxlarge" rows="4"></textarea>

<input type="submit" class="btn btn-small" value="提交" />
</form>
</div>

</div>

Expand Down

0 comments on commit 5a28985

Please sign in to comment.