Skip to content

Commit

Permalink
update choicefiled display name
Browse files Browse the repository at this point in the history
  • Loading branch information
gothack329 committed Mar 5, 2018
1 parent af1b606 commit cb9c42d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
Binary file modified article/__pycache__/views.cpython-36.pyc
Binary file not shown.
19 changes: 19 additions & 0 deletions article/templates/article/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@ <h1>{% if art %}{{art.title}}{% endif %} </h1>
{% endfor %}
{% endif %}

{% if errors %}
{% for error in errors %}
<script type="text/javascript">
$.notify({
// options
message: '{{ error|escape }}',
},{
// settings
type: 'danger',
delay: 5000,
timer: 1000,
animate: {
enter: 'animated flipInY',
exit: 'animated flipOutX'
},
},);
</script>
{% endfor %}
{% endif %}
<form class="textarea" method="post" novalidate>
{% csrf_token %}
<input type='hidden' name="article" value="{{art.id}}" />
Expand Down
12 changes: 9 additions & 3 deletions article/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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)


Expand Down
Binary file modified db.sqlite3
Binary file not shown.
2 changes: 1 addition & 1 deletion userpage/templates/userpage/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
<p></p>
{% for i in points %}
<div class="row member_comments">
<p>{{i.record_time|timetonow}},{{i.event}},{{i.point_record}}</p>
<p>{{i.record_time|timetonow}},{{i.get_event_display}},{{i.point_record}}</p>
</div>
{% endfor %}
</div>
Expand Down

0 comments on commit cb9c42d

Please sign in to comment.