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 %} {{art.title}} - 物志 @@ -41,12 +41,12 @@

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

          评论数:{{comments|length}}           - 发表于:{{art.publish_time}} + 发表于:{{art.publish_time|timetonow}}前 {% ifequal request.user.id art.author_id.id %} {% endifequal %}

- 标签:{{art.tag}} + 标签:{% if arg.tag %}{{art.tag}}{% endif %}

广告位

{{art.detail|safe }} @@ -62,7 +62,7 @@

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

-  {{i.comment_time}}    +  {{i.comment_time|timetonow}}前    {% ifequal request.user.id i.user.id %} 作者 {% endifequal %} @@ -113,6 +113,7 @@

{% 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 %}
-
-
+
+
diff --git a/templates/index.html b/templates/index.html index 38b7929..2bf5680 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,5 +1,5 @@ {% extends 'base.html' %} - +{% load timetonow %} {% block banner %} {% endblock %} {% block content%} -
-
- -
-
-
-

-   - {{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}}. +

+
+
-
- -
-
- {% for i in arts %} +
+ +
+
+ {% for i in arts %}

{{i.title}}

{{i.detail|striptags|truncatechars:500|safe}}

-  {{i.publish_time|timesince}}前 +  {{i.publish_time|timetonow}}前      {{i.author}}     @@ -89,38 +111,47 @@
- {% endfor %} -
- -
-

- {% for i in comments %} -
-

于 {{i.comment_time}}前 评论了 {{i.article.author_id}} 的文章【 {{i.article}}

-

{{i.comment|safe|escape}}

-
- - {% endfor %} -
- - {% ifequal member.id user.id %} -
- {# 消息提醒 #} -
-

于 {{i.comment_time|timesince}} 评论了 {{i.article.author_id}} 的文章【 {{i.article}} 】 -

{{i.comment|safe|escape}}

-
-
- - - {% endifequal %} -
-
+ {% endfor %} +
+ + + + {% ifequal member.id user.id %} +
+ {# 消息提醒 #} +
+ +
+
+ +
+ {# 编辑资料 #} +

+
+ {% csrf_token %} + + +

{{ profile_form.avatar }}

+
+

{{ user_form.first_name}}

+

{{ user_form.last_name}}

+

{{ user_form.email}}

+ + +
+
+ + {% endifequal %} +
+
{% endblock %} diff --git a/userpage/templates/userpage/update.html b/userpage/templates/userpage/update.html index 28e6ac5..0a714a8 100644 --- a/userpage/templates/userpage/update.html +++ b/userpage/templates/userpage/update.html @@ -1,36 +1,5 @@ {% block content%} - {% if user_form.errors %} - {% for field in user_form %} - {% for error in field.errors %} - - {% endfor %} - {% endfor %} - {% endif %} - -
-

-
- {% csrf_token %} - {{ user_form.as_p }} - {{ profile_form.as_p }} - -
-
{% endblock %} \ No newline at end of file diff --git a/userpage/urls.py b/userpage/urls.py index cc958a6..69c7369 100644 --- a/userpage/urls.py +++ b/userpage/urls.py @@ -4,5 +4,5 @@ urlpatterns = [ path('member//', views.profile, name='profile'), - path('update/', views.update_profile, name='update_profile'), + #path('update/', views.update_profile, name='update_profile'), ] diff --git a/userpage/views.py b/userpage/views.py index b22f60a..41ea3b5 100644 --- a/userpage/views.py +++ b/userpage/views.py @@ -18,29 +18,25 @@ def profile(request, username): arts = Article.objects.filter(author_id=inst_profile) comments = Comment.objects.filter(user=inst_profile).filter(invalid='N') - return render(request, 'userpage/profile.html', {'member':inst_user,'arts':arts,'comments':comments}) + -@login_required -@transaction.atomic -def update_profile(request): - if request.method == 'POST': user_form = UserForm(request.POST, instance=request.user) profile_form = ProfileForm(request.POST, instance=request.user.profile) + if user_form.is_valid() and profile_form.is_valid(): user_form.save() profile_form.save() - messages.success(request, '用户资料更新成功!') + #messages.success(request, '用户资料更新成功!') return redirect('.') #return redirect('settings:profile') else: - messages.error(request, 'Please correct the error below.') + messages.error(request, user_form.errors) #messages.error(request, _('Please correct the error below.')) else: user_form = UserForm(instance=request.user) profile_form = ProfileForm(instance=request.user.profile) - return render(request, 'userpage/profile.html', { - 'user_form': user_form, - 'profile_form': profile_form - }) + + return render(request, 'userpage/profile.html', {'member':inst_user,'arts':arts,'comments':comments,'user_form': user_form, +'profile_form': profile_form}) \ No newline at end of file