diff --git a/article/__pycache__/models.cpython-36.pyc b/article/__pycache__/models.cpython-36.pyc
index 35a5cb0..bbb3ebe 100644
Binary files a/article/__pycache__/models.cpython-36.pyc and b/article/__pycache__/models.cpython-36.pyc differ
diff --git a/article/__pycache__/views.cpython-36.pyc b/article/__pycache__/views.cpython-36.pyc
index 1ebde1b..57f3fd5 100644
Binary files a/article/__pycache__/views.cpython-36.pyc and b/article/__pycache__/views.cpython-36.pyc differ
diff --git a/article/models.py b/article/models.py
index 14b022e..6df8184 100644
--- a/article/models.py
+++ b/article/models.py
@@ -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 *
@@ -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}),
}
diff --git a/article/templates/article/detail.html b/article/templates/article/detail.html
index bef1be3..5223725 100644
--- a/article/templates/article/detail.html
+++ b/article/templates/article/detail.html
@@ -2,6 +2,23 @@
{% block header %}
{{art.title}} - 物志
+
+
{% endblock %}
@@ -48,9 +65,20 @@ {% if art %}{{art.title}}{% endif %}
+ {% if messages %}
+
+ {% for message in messages %}
+ - {{ message }}
+ {% endfor %}
+
+ {% endif %}
diff --git a/article/views.py b/article/views.py
index b53ec54..5b516e4 100644
--- a/article/views.py
+++ b/article/views.py
@@ -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 *
@@ -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.')
@@ -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)
diff --git a/db.sqlite3 b/db.sqlite3
index 0074135..b572d43 100644
Binary files a/db.sqlite3 and b/db.sqlite3 differ
diff --git a/templates/base.html b/templates/base.html
index 3ca6408..5c1e74f 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -25,8 +25,8 @@
物志
- {% if username %}
- {{username}}
+ {% if request.user %}
+ {{request.user.username}}
{% else%}
登录
{% endif %}