Skip to content

Commit

Permalink
update user profile
Browse files Browse the repository at this point in the history
  • Loading branch information
gothack329 committed Mar 1, 2018
1 parent 7506c4b commit 71abb09
Show file tree
Hide file tree
Showing 23 changed files with 175 additions and 167 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.
2 changes: 1 addition & 1 deletion article/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':"标题"}),
Expand Down
9 changes: 5 additions & 4 deletions article/templates/article/detail.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "base.html" %}

{% load timetonow %}
{% block header %}
<title>{{art.title}} - 物志</title>

Expand Down Expand Up @@ -41,12 +41,12 @@ <h1>{% if art %}{{art.title}}{% endif %} </h1>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span class="fad">评论数:{{comments|length}}</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span class="fad">发表于:{{art.publish_time}}</span>
<span class="fad">发表于:{{art.publish_time|timetonow}}前</span>
{% ifequal request.user.id art.author_id.id %}
<span class="fad pull-right" ><button class="btn btn-primary" onclick="window.location.href='/article/update/{{art.id}}/'">编辑</button></span>
{% endifequal %}
<p></p>
<span class="fad">标签:{{art.tag}}</span>
<span class="fad">标签:{% if arg.tag %}{{art.tag}}{% endif %}</span>
<span class="sep margintop" ></span>
<div class="ad1"> <h3>广告位</h3> </div>
{{art.detail|safe }}
Expand All @@ -62,7 +62,7 @@ <h1>{% if art %}{{art.title}}{% endif %} </h1>
</div>
<div class="comment-info ">

<span class="glyphicon glyphicon-time fad"> </span>&nbsp;<span class="fad">{{i.comment_time}}</span> &nbsp;&nbsp;
<span class="glyphicon glyphicon-time fad"> </span>&nbsp;<span class="fad">{{i.comment_time|timetonow}}前</span> &nbsp;&nbsp;
{% ifequal request.user.id i.user.id %}
<span class="ico fad" style="padding:2px;border:1px solid gray">作者</span>
{% endifequal %}
Expand Down Expand Up @@ -113,6 +113,7 @@ <h1>{% if art %}{{art.title}}{% endif %} </h1>
{% csrf_token %}
<input type='hidden' name="article" value="{{art.id}}" />
<input type='hidden' name="user" value="{{request.user.id}}" />
<input type='hidden' name="invalid" value="N" />
{{comment_form.comment}}
<p></p>
<button class="btn btn-default pull-right" type="submit">发布</button>
Expand Down
Binary file not shown.
Binary file modified article/templatetags/__pycache__/upto.cpython-36.pyc
Binary file not shown.
26 changes: 26 additions & 0 deletions article/templatetags/timetonow.py
Original file line number Diff line number Diff line change
@@ -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
10 changes: 0 additions & 10 deletions article/templatetags/upto.py

This file was deleted.

13 changes: 7 additions & 6 deletions article/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
Binary file modified db.sqlite3
Binary file not shown.
2 changes: 0 additions & 2 deletions static/bootstrap/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ html,body {

a,a:hover {
text-decoration:none;
color:#5555aa;

}

img{
Expand Down
Binary file added static/image/notice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 6 additions & 10 deletions templates/base.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!DOCTYPE html>
{% load staticfiles %}

{% load timetonow %}
<html>
<head>
<meta charset="utf-8">
Expand Down Expand Up @@ -70,8 +70,8 @@ <h1>{% if title %}{{title}}{% endif %} </h1>
{% ifnotequal user.id None %}
<div class="usercard row">

<div class="usercard-avatar" style="background:url(/{{user.avatar}}) no-repeat;background-size:80px 80px;">
</div>
<a href="/userpage/member/{{user.user}}/"><div class="usercard-avatar" style="background:url(/{{user.avatar}}) no-repeat;background-size:80px 80px;">
</div></a>
<div class="usercard-info">
<p>
<a href="/userpage/member/{{user.user}}/"><span class="glyphicon glyphicon-user fad"> </span>&nbsp;<span class="fad">
Expand All @@ -82,13 +82,9 @@ <h1>{% if title %}{{title}}{% endif %} </h1>
<img src="/static/image/coin16.png" style="display:inline-block;padding-bottom: 4px" alt="金币" > <span class="fad">
{{user.point}}
</span> &nbsp;&nbsp;&nbsp;
{% ifnotequal user.msg 0 %}
<span class="glyphicon glyphicon-bell fad" alt="未读提醒" style="color:gold"> </span>&nbsp;<span class="fad" alt="未读提醒">
{% else %}
<span class="glyphicon glyphicon-bell fad" alt="未读提醒" > </span>&nbsp;<span class="fad" alt="未读提醒">
{% endifnotequal %}

{{user.msg}}
<img src="/static/image/notice.png" width="16" height="16" style="display:inline-block;padding-bottom: 2px;width:16px;height:20px" alt="未读提醒" >
<span class="fad" alt="未读提醒">
0{{user.msg}}
</span> &nbsp;&nbsp;&nbsp;
</p>
</div>
Expand Down
4 changes: 2 additions & 2 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'base.html' %}

{% load timetonow %}

{% block banner %}
<div class="banner" style="background:url(/static/upload/{{cover}}) no-repeat;background-position:center;background-size:cover;">
Expand All @@ -21,7 +21,7 @@ <h1>{% if title %}{{title}}{% endif %} </h1>
<a href="/article/{{i.id}}/"><h2>{{i.title}}</h2></a>
<p class="fad">{{i.detail|striptags|truncatechars:500|safe}} </p>
<p></p>
<span class="glyphicon glyphicon-time fad"> </span>&nbsp;<span class="fad">{{i.publish_time}}</span>
<span class="glyphicon glyphicon-time fad"> </span>&nbsp;<span class="fad">{{i.publish_time|timetonow}}前</span>
&nbsp;&nbsp;&nbsp;
<a href="/userpage/member/{{i.author_id}}/"><span class="glyphicon glyphicon-user fad"> </span>&nbsp;<span class="fad">{{i.author}}</span></a>
&nbsp;&nbsp;&nbsp;
Expand Down
Binary file modified userpage/__pycache__/models.cpython-36.pyc
Binary file not shown.
Binary file modified userpage/__pycache__/urls.cpython-36.pyc
Binary file not shown.
Binary file modified userpage/__pycache__/views.cpython-36.pyc
Binary file not shown.
4 changes: 2 additions & 2 deletions userpage/models.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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':"头像"}),
}
Loading

0 comments on commit 71abb09

Please sign in to comment.