diff --git a/article/__pycache__/models.cpython-36.pyc b/article/__pycache__/models.cpython-36.pyc index 8791d41..7ed3163 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 b4d040d..ff3fc18 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 95acb89..c001a75 100644 --- a/article/models.py +++ b/article/models.py @@ -66,7 +66,7 @@ class Meta: } widgets = { 'detail':TinyMCE(attrs={'cols':'100%','rows':30}), - 'cover':ClearableFileInput(attrs={'style':'width:50%','class':'form-control','placeholder':"封面"}), + 'cover':FileInput(attrs={'style':'width:50%','class':'form-control','placeholder':"封面"}), 'tag':TextInput(attrs={'class':'form-control','placeholder':"添加标签,回车确认",'data-role':'tagsinput'}), 'author':TextInput(attrs={'class':'form-control','placeholder':"署名"}), 'title':TextInput(attrs={'style':'width:50%','class':'form-control','placeholder':"标题"}), diff --git a/article/templates/article/detail.html b/article/templates/article/detail.html index 890bbfb..1bcefed 100644 --- a/article/templates/article/detail.html +++ b/article/templates/article/detail.html @@ -1,5 +1,5 @@ {% extends "base.html" %} - +{% load timetonow %} {% block header %}
{% if art %}{{art.title}}{% endif %}
{% csrf_token %} + {{comment_form.comment}} diff --git a/article/templatetags/__pycache__/timetonow.cpython-36.pyc b/article/templatetags/__pycache__/timetonow.cpython-36.pyc new file mode 100644 index 0000000..b2fa207 Binary files /dev/null and b/article/templatetags/__pycache__/timetonow.cpython-36.pyc differ diff --git a/article/templatetags/__pycache__/upto.cpython-36.pyc b/article/templatetags/__pycache__/upto.cpython-36.pyc index e2e5b1e..354d52d 100644 Binary files a/article/templatetags/__pycache__/upto.cpython-36.pyc and b/article/templatetags/__pycache__/upto.cpython-36.pyc differ diff --git a/article/templatetags/timetonow.py b/article/templatetags/timetonow.py new file mode 100644 index 0000000..12f58db --- /dev/null +++ b/article/templatetags/timetonow.py @@ -0,0 +1,26 @@ +from django import template +from django.template.defaultfilters import stringfilter +import datetime +from django.utils import timezone + +register = template.Library() + +@register.filter +@stringfilter +def timetonow(value): + # value: 2018-02-28 07:53:04.802169+00:00 + valuetime = datetime.datetime.strptime(value, "%Y-%m-%d %H:%M:%S.%f+00:00") + now = timezone.now() + now = now.replace(tzinfo=None) + delta = now-valuetime + s = delta.seconds + if s>86400: + return '%d天' % (int(s/86400)) + elif s>3600: + return '%d小时' % (int(s/3600)) + elif s>120: + return '%d分钟' % (int(s/120)) + else: + return '刚刚' + +timetonow.is_safe = True \ No newline at end of file diff --git a/article/templatetags/upto.py b/article/templatetags/upto.py deleted file mode 100644 index c8d5b18..0000000 --- a/article/templatetags/upto.py +++ /dev/null @@ -1,10 +0,0 @@ -from django import template -from django.template.defaultfilters import stringfilter - -register = template.Library() - -@register.filter -@stringfilter -def upto(value, delimiter=None): - return value.split(delimiter)[0] -upto.is_safe = True \ No newline at end of file diff --git a/article/views.py b/article/views.py index 2869b9d..d7ddf35 100644 --- a/article/views.py +++ b/article/views.py @@ -20,13 +20,14 @@ def detail(request, article_id): if request.method == 'POST': comment_form = CommentForm(request.POST,instance=None) - instance = comment_form.save(commit=False) - instance.ip = request.META['REMOTE_ADDR'] + if comment_form.is_valid(): + instance = comment_form.save(commit=False) + instance.ip = request.META['REMOTE_ADDR'] - instance.save() - return redirect('.') - #else: - # messages.error(request, 'Please correct the error below.') + instance.save() + return redirect('.') + else: + messages.error(request, comment_form.errors) else: art.readtime = art.readtime + 1 art.save(update_fields=['readtime']) diff --git a/db.sqlite3 b/db.sqlite3 index 16a8c56..13c3287 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/static/bootstrap/css/style.css b/static/bootstrap/css/style.css index ff4cb2f..8408566 100755 --- a/static/bootstrap/css/style.css +++ b/static/bootstrap/css/style.css @@ -7,8 +7,6 @@ html,body { a,a:hover { text-decoration:none; - color:#5555aa; - } img{ diff --git a/static/image/notice.png b/static/image/notice.png new file mode 100644 index 0000000..903ff3a Binary files /dev/null and b/static/image/notice.png differ diff --git a/static/upload/internet_facebook_twitter_myspace_wikipedia_deviantart_youtube_google_4cha_hLZhJie.jpg b/static/upload/internet_facebook_twitter_myspace_wikipedia_deviantart_youtube_google_4cha_hLZhJie.jpg new file mode 100644 index 0000000..dc4b971 Binary files /dev/null and b/static/upload/internet_facebook_twitter_myspace_wikipedia_deviantart_youtube_google_4cha_hLZhJie.jpg differ diff --git a/templates/base.html b/templates/base.html index 0d94e31..1ac51c7 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,6 +1,6 @@ {% load staticfiles %} - +{% load timetonow %} @@ -70,8 +70,8 @@{% if title %}{{title}}{% endif %}
{% ifnotequal user.id None %}@@ -82,13 +82,9 @@
{% if title %}{{title}}{% endif %}
{{user.point}} - {% ifnotequal user.msg 0 %} - - {% else %} - - {% endifnotequal %} - - {{user.msg}} + + + 0{{user.msg}}{% if title %}{{title}}{% endif %}
{{i.title}}
{{i.detail|striptags|truncatechars:500|safe}}
- {{i.publish_time}} + {{i.publish_time|timetonow}}前 {{i.author}} diff --git a/userpage/__pycache__/models.cpython-36.pyc b/userpage/__pycache__/models.cpython-36.pyc index 9b1e159..9aa0cc4 100644 Binary files a/userpage/__pycache__/models.cpython-36.pyc and b/userpage/__pycache__/models.cpython-36.pyc differ diff --git a/userpage/__pycache__/urls.cpython-36.pyc b/userpage/__pycache__/urls.cpython-36.pyc index c0a37bb..33b830c 100644 Binary files a/userpage/__pycache__/urls.cpython-36.pyc and b/userpage/__pycache__/urls.cpython-36.pyc differ diff --git a/userpage/__pycache__/views.cpython-36.pyc b/userpage/__pycache__/views.cpython-36.pyc index f9547bc..68f5bd5 100644 Binary files a/userpage/__pycache__/views.cpython-36.pyc and b/userpage/__pycache__/views.cpython-36.pyc differ diff --git a/userpage/models.py b/userpage/models.py index 7f0bd69..277a7da 100644 --- a/userpage/models.py +++ b/userpage/models.py @@ -1,6 +1,6 @@ from django.db import models from django.contrib.auth.models import User -from django.forms import ModelForm,Textarea,TextInput,ClearableFileInput +from django.forms import ModelForm,Textarea,TextInput,ClearableFileInput,FileInput from django.db.models.signals import post_save from django.dispatch import receiver @@ -46,5 +46,5 @@ class Meta: 'avatar':{'required': '请上传头像'}, } widgets = { - 'avatar':ClearableFileInput(attrs={'style':'width:50%','class':'form-control','placeholder':"头像"}), + 'avatar':ClearableFileInput(attrs={'class':'form-control','placeholder':"头像"}), } diff --git a/userpage/templates/userpage/profile.html b/userpage/templates/userpage/profile.html index 5691900..fc84c9b 100644 --- a/userpage/templates/userpage/profile.html +++ b/userpage/templates/userpage/profile.html @@ -1,17 +1,41 @@ {% extends "base.html"%} -{% load upto %} +{% load timetonow %} {% block header %} -- - {{member.username}} - -
-- - {{member.profile.point}} - - {% ifequal member.id user.id %} - {% ifnotequal user.msg 0 %} - - {% else %} - - {% endifnotequal %} - {{user.msg}} - - {% endifequal %} -
-本站第 {{member.id}} 位会员,于 {{member.date_joined}} 注册,最近一次登录于 {{member.last_login}}. -
+ + {{member.username}} + +
++ + + {{member.profile.point}} + + {% ifequal member.id user.id %} + + + 0{{user.msg}} + + {% endifequal %} +
+本站第 {{member.id}} 位会员,于 {{member.date_joined}} 加入,最近一次登录于 {{member.last_login}}. +
--
- 文章列表{{arts|length}}
-
- -
- 评论列表{{comments|length}}
-
- {% ifequal member.id user.id %}
- -
- 消息提醒
-
- -
- 编辑资料
-
- {% endifequal %}
-
-+-
+ 文章列表{{arts|length}}
+
+ -
+ 评论列表{{comments|length}}
+
+ {% ifequal member.id user.id %}
+ -
+ 消息提醒
+
+ -
+ 编辑资料
+
+ {% endifequal %}
+
+{{i.title}}
{{i.detail|striptags|truncatechars:500|safe}}
- {{i.publish_time|timesince}}前 + {{i.publish_time|timetonow}}前 {{i.author}} @@ -89,38 +111,47 @@于 {{i.comment_time}}前 评论了 {{i.article.author_id}} 的文章【 {{i.article}} 】
-{{i.comment|safe|escape}}
-于 {{i.comment_time|timesince}} 评论了 {{i.article.author_id}} 的文章【 {{i.article}} 】 -
{{i.comment|safe|escape}}
-于 {{i.comment_time}} 评论了 {{i.article.author_id}} 的文章【 {{i.article}} 】 -
{{i.comment|safe|escape}}
-于 {{i.comment_time|timetonow}} 评论了 {{i.article.author_id}} 的文章【 {{i.article}} 】
+{{i.comment|safe|escape}}
+