diff --git a/article/__pycache__/views.cpython-36.pyc b/article/__pycache__/views.cpython-36.pyc index c6e8e2b..bb84aa1 100644 Binary files a/article/__pycache__/views.cpython-36.pyc and b/article/__pycache__/views.cpython-36.pyc differ diff --git a/article/templates/article/detail.html b/article/templates/article/detail.html index 52c8a4d..ff1ce1e 100644 --- a/article/templates/article/detail.html +++ b/article/templates/article/detail.html @@ -118,6 +118,25 @@

{% if art %}{{art.title}}{% endif %}

{% endfor %} {% endif %} +{% if errors %} + {% for error in errors %} + + {% endfor %} +{% endif %}
{% csrf_token %} diff --git a/article/views.py b/article/views.py index f86f373..c16a223 100644 --- a/article/views.py +++ b/article/views.py @@ -17,18 +17,24 @@ def detail(request, article_id): art = Article.objects.get(pk=article_id) comments = Comment.objects.filter(article_id=article_id).order_by('comment_time') + errors = [] if request.method == 'POST': comment_form = CommentForm(request.POST,instance=None) + commenter = User.objects.get(pk=request.user.id) + - if comment_form.is_valid(): + user_p = Profile.objects.get(user=commenter) + if user_p.point < 1: + errors.append('您没有足够的积分进行评论!') + elif comment_form.is_valid(): instance = comment_form.save(commit=False) instance.ip = request.META['REMOTE_ADDR'] instance.save() point=1 author = User.objects.get(pk=art.author_id.id) - commenter = User.objects.get(pk=request.user.id) + updatepoint = Point.objects.create(user=author,point_record=point,event="commented") updatepoint = Point.objects.create(user=commenter,point_record=-point,event="comment") @@ -42,7 +48,7 @@ def detail(request, article_id): comment_form = CommentForm(instance=None) - return render(request,'article/detail.html',{'art':art,'comments':comments,'comment_form':comment_form}) + return render(request,'article/detail.html',{'art':art,'comments':comments,'comment_form':comment_form,'errors':errors}) #return HttpResponse("You're looking at article %s." % article_id) diff --git a/db.sqlite3 b/db.sqlite3 index d6d464c..2a388d1 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/userpage/templates/userpage/profile.html b/userpage/templates/userpage/profile.html index ad038c1..73f9f3c 100644 --- a/userpage/templates/userpage/profile.html +++ b/userpage/templates/userpage/profile.html @@ -145,7 +145,7 @@

{% for i in points %}
-

{{i.record_time|timetonow}},{{i.event}},{{i.point_record}}

+

{{i.record_time|timetonow}},{{i.get_event_display}},{{i.point_record}}

{% endfor %}