Skip to content

Commit

Permalink
update comment
Browse files Browse the repository at this point in the history
  • Loading branch information
gothack329 committed Feb 27, 2018
1 parent 21f03c8 commit 478112a
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 10 deletions.
Binary file modified article/__pycache__/models.cpython-36.pyc
Binary file not shown.
Binary file modified article/__pycache__/views.cpython-36.pyc
Binary file not shown.
6 changes: 3 additions & 3 deletions article/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding=utf-8
from django.db import models
from tinymce.models import HTMLField
from tinymce.models import HTMLField,TinyMCE
from django.contrib.auth.models import User
from django.forms import ModelForm,Textarea
from userpage.models import *
Expand Down Expand Up @@ -77,7 +77,7 @@ class Meta:
class CommentForm(ModelForm):
class Meta:
model = Comment
fields = ('article','user','comment')
fields = ('article','user','comment','ip')
widgets = {
'comment':Textarea(),
'comment':TinyMCE(attrs={'cols':'100%','rows':10}),
}
30 changes: 29 additions & 1 deletion article/templates/article/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@

{% block header %}
<title>{{art.title}} - 物志</title>
<script type="text/javascript" src="/static/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init(
{
'height': 100,
'width': '100%',
'custom_undo_redo_levels': 20,
'selector': 'textarea',
'theme': 'modern',
'plugins': ' textcolor save link image media preview codesample contextmenu table code lists fullscreen insertdatetime nonbreaking contextmenu directionality searchreplace wordcount visualblocks visualchars code fullscreen autolink lists charmap print hr anchor pagebreak textpattern',
'toolbar1': 'fullscreen preview bold italic underline | fontselect, fontsizeselect | forecolor backcolor | alignleft alignright | aligncenter alignjustify | indent outdent | bullist numlist table | | link image media | codesample |',
'toolbar2': ' visualblocks visualchars | charmap hr pagebreak nonbreaking anchor | code |',
'contextmenu': 'formats | link image',
}

);
</script>

{% endblock %}

Expand Down Expand Up @@ -48,9 +65,20 @@ <h1>{% if art %}{{art.title}}{% endif %} </h1>
</div>

<div class="card">
{% if messages %}
<ul class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
<form method="post">
{% csrf_token %}
{{ comment_form.comment }}
<input type='hidden' name="article" value="{{art.id}}" />
<input type='hidden' name="user" value="{{request.user.id}}" />
<input type='hidden' name="ip" value="1.1.1.1" />

{{comment_form.comment}}
<button class="btn btn-default pull-right" type="submit">发表</button>
</form>

Expand Down
13 changes: 9 additions & 4 deletions article/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.shortcuts import render
from django.shortcuts import render,redirect
from django.http import HttpResponse,HttpResponseRedirect
from django.template import RequestContext,Template,Context,loader,defaultfilters
from django.shortcuts import render_to_response
from django.contrib import messages
from .models import *

Expand All @@ -12,13 +11,19 @@ def homepage(request):


def detail(request, article_id):

if request.user.is_authenticated :# and request.user.has_perm('cmdb.permit')):
username = request.user.username
else:
username = None

art = Article.objects.get(pk=article_id)
comments = Comment.objects.filter(article_id=article_id).order_by('comment_time')

if request.method == 'POST':
comment_form = CommentForm(request.POST,instance=None)
comment_form.save()
if comment_form.is_valid():
comment_form.save()
return redirect('.')
else:
messages.error(request, 'Please correct the error below.')
Expand All @@ -27,7 +32,7 @@ def detail(request, article_id):

secs = Section.objects.all()

return render(request,'article/detail.html',{'art':art,'comments':comments,'comment_form':comment_form,'secs':secs})
return render(request,'article/detail.html',{'username':username,'art':art,'comments':comments,'comment_form':comment_form,'secs':secs})
#return HttpResponse("You're looking at article %s." % article_id)


Expand Down
Binary file modified db.sqlite3
Binary file not shown.
4 changes: 2 additions & 2 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<a class="logo" href='/'>物志</a>
</li>
<li class="navbar-right">
{% if username %}
<a href="#">{{username}}</a>
{% if request.user %}
<a href="#">{{request.user.username}}</a>
{% else%}
<a href="#">登录</a>
{% endif %}
Expand Down

0 comments on commit 478112a

Please sign in to comment.