Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
gothack329 committed Mar 10, 2018
1 parent ae85cab commit c6da3a9
Show file tree
Hide file tree
Showing 26 changed files with 114 additions and 42 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.
4 changes: 2 additions & 2 deletions article/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Article(models.Model):
detail = HTMLField()
ip = models.GenericIPAddressField(blank=True,null=True)
tag = models.CharField(max_length=128, blank=True, null=True)
visible = models.CharField(choices=(('Y','是'),('N','否')),max_length=64,default='N')
visible = models.CharField(choices=(('Y','是'),('N','否')),max_length=64,default='Y')
readtime = models.IntegerField(default=0)
comment_count = models.IntegerField(default=0)
#update_time = models.DateTimeField(auto_now=True,blank=True,null=True)
Expand Down Expand Up @@ -93,7 +93,7 @@ class Meta:
model = Comment
fields = ('article','user','comment','ip','invalid')
error_messages = {
'user':{'required': '请先登录','invalid_choice':'请先登录!'},
'user':{'required': '请先登录!','invalid_choice':'用户名不正确!'},
}
widgets = {
'comment':TinyMCE(attrs={'cols':'100%','rows':10}),
Expand Down
13 changes: 7 additions & 6 deletions article/templates/article/detail.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{% extends "base.html" %}
{% load timetonow %}
{% block header %}
<title>{% ifnotequal user.unread 0%} ({{user.unread}}) {% endifnotequal %} 物志 › {{art.title}} </title>

{% block title %}
- {{art.title}}
{% endblock %}

{% block header %}
<script type="text/javascript" src="/static/tinymce/tinymce.min.js"></script>
<script type="text/javascript">
tinyMCE.init(
{

'custom_undo_redo_levels': 20,
'selector': 'textarea',
'theme': 'modern',
Expand All @@ -17,7 +19,6 @@
'menubar': false,
'statusbar': false,
}

);
</script>
<script type="text/javascript">
Expand Down Expand Up @@ -49,7 +50,7 @@ <h1>{% if art %}{{art.title}}{% endif %} </h1>
<span class="fad">评论数:{{comments|length}}</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

{% ifequal request.user.id art.author_id.id %}
{% ifequal request.user.id art.author_id.user.id %}
<span class="fad pull-right" ><button class="btn btn-primary" onclick="window.location.href='/article/update/{{art.id}}/'">编辑</button></span>
{% endifequal %}
<p></p>
Expand Down Expand Up @@ -140,7 +141,7 @@ <h1>{% if art %}{{art.title}}{% endif %} </h1>
<form class="textarea" method="post" novalidate>
{% csrf_token %}
<input type='hidden' name="article" value="{{art.id}}" />
<input type='hidden' name="user" value="{{request.user.id}}" />
<input type='hidden' name="user" value="{{user.id}}" />
<input type='hidden' name="invalid" value="N" />
{{comment_form.comment}}
<p></p>
Expand Down
2 changes: 1 addition & 1 deletion article/templates/article/publish.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ <h4>{{operation}}文章</h4>

<form method="post" class="form-inline textarea" data-ajax="false" enctype="multipart/form-data" novalidate>
{% csrf_token %}
<input type="hidden" name="author_id" value="{{request.user.id}}">
<input type="hidden" name="author_id" value="{{user.id}}">
<p>{{article_form.section}} - {{article_form.title}}</p>
<p>上传封面图片 : {{article_form.cover}}</p>
<span class="sep margintop"></span>
Expand Down
18 changes: 12 additions & 6 deletions article/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ def detail(request, article_id):
comments = Comment.objects.filter(article_id=article_id).order_by('comment_time')
errors = []

if request.method == 'POST':

if request.method == 'GET':
art.readtime = art.readtime + 1
art.save(update_fields=['readtime'])
comment_form = CommentForm(instance=None)
elif request.method == 'POST' and request.user.is_authenticated:
#Profile.objects.get()
comment_form = CommentForm(request.POST,instance=None)
commenter = User.objects.get(pk=request.user.id)


user_p = Profile.objects.get(user=commenter)
if user_p.point < 1:
Expand All @@ -33,7 +38,7 @@ def detail(request, article_id):
instance.save()

point=1
author = User.objects.get(pk=art.author_id.id)
author = User.objects.get(username=art.author_id.user.username)

updatepoint = Point.objects.create(user=author,point_record=point,event="commented")
updatepoint = Point.objects.create(user=commenter,point_record=-point,event="comment")
Expand All @@ -42,10 +47,11 @@ def detail(request, article_id):
return redirect('.')
else:
messages.error(request, comment_form.errors)

else:
art.readtime = art.readtime + 1
art.save(update_fields=['readtime'])
comment_form = CommentForm(instance=None)
errors.append('请先登录!')



return render(request,'article/detail.html',{'art':art,'comments':comments,'comment_form':comment_form,'errors':errors})
Expand All @@ -62,7 +68,7 @@ def publish(request):
art = instance.save()

point=2
u = User.objects.get(pk=instance.author_id.id)
u = User.objects.get(pk=request.user.id)
updatepoint = Point.objects.create(user=u,point_record=point,event="publish")
#updatepoint.save()

Expand Down
Binary file modified db.sqlite3
Binary file not shown.
Binary file modified edconline/__pycache__/views.cpython-36.pyc
Binary file not shown.
8 changes: 7 additions & 1 deletion edconline/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.http import HttpResponse,HttpResponseRedirect
from django.db.models import Q
from django.template import Template,defaultfilters,RequestContext
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.shortcuts import render_to_response
from article.models import *
import os,random
Expand All @@ -17,6 +18,7 @@ def homepage(request):
for i in query:
data[i[0]]=i[1]

print(data)
#if request.user.is_authenticated :# and request.user.has_perm('cmdb.permit')):
# username = request.user.username
#else:
Expand All @@ -38,7 +40,11 @@ def homepage(request):
arts = Article.objects.filter(visible='Y').order_by('-publish_time')
search_keywords = None

return render(request,'index.html',{'cover':cover,'arts':arts,'keywords':search_keywords})
paginator = Paginator(arts,15)
page = request.GET.get('page')
articles = paginator.get_page(page)

return render(request,'index.html',{'cover':cover,'arts':articles,'keywords':search_keywords})



Expand Down
Binary file modified notification/__pycache__/models.cpython-36.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions notification/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ class Msg(models.Model):
@receiver(post_save, sender=Comment)
def mentioned_user(sender, created, instance, **kwargs):
s = bs(str(instance) , "html.parser")

mu = [i.text for i in s.find_all('a',attrs={'class':'mentioned_user'})]
mu.append(instance.article.author_id.user.username)
mu = list(set(mu))
print(mu)
if len(mu) > 0 and created:
msg = Msg.objects.create(comment=instance,unread='Y',comment_time=instance.comment_time)
for user in mu:
Expand Down
Binary file added static/avatar/WechatIMG473.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/avatar/WechatIMG473_UKHFrnB.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/image/favicon.ico
Binary file not shown.
Binary file added static/upload/canon_in_d_3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="shortcut icon" href="/static/image/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="EDC online">
<meta name="author" content="物志">
Expand All @@ -17,8 +18,14 @@
<script type="text/javascript" src="/static/bootstrap/js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="/static/bootstrap/js/bootstrap-notify.js"></script>
<link href='http://cdn.webfont.youziku.com/webfonts/nomal/114602/46453/5a919786f629d911e0099415.css' rel='stylesheet' type='text/css' />
<title>
{% if user.id %}
{% ifnotequal user.unread 0 %} ({{user.unread}}) {% endifnotequal %}
{% endif %}
物志 {%block title%} {% endblock %}
</title>
{% block header %}
<title>{% ifnotequal user.unread 0%} ({{user.unread}}) {% endifnotequal %} 物志 {% if title %}› {{title}} {% endif %} </title>

{% endblock %}
</head>
<body>
Expand Down
28 changes: 28 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,33 @@ <h1>{% if title %}{{title}}{% endif %} </h1>
</div>
{% endfor %}


<ul class="pager" style="margin-left:20px">
{% if arts.has_previous %}
<li class="previous"><a href="?page={{ arts.previous_page_number }}">&larr; 更新文章</a></li>
{% endif %}
{% if arts.has_next %}
<li class="next"><a href="?page={{ arts.paginator.num_pages }}">更早文章 &rarr;</a></li>
{% endif %}
</ul>


{% endblock %}

<div class="pagination">
<span class="step-links">
{% if arts.has_previous %}
<a href="?page=1">&laquo; first</a>
<a href="?page={{ arts.previous_page_number }}">previous</a>
{% endif %}

<span class="current">
Page {{ arts.number }} of {{ arts.paginator.num_pages }}.
</span>

{% if arts.has_next %}
<a href="?page={{ arts.next_page_number }}">next</a>
<a href="?page={{ arts.paginator.num_pages }}">last &raquo;</a>
{% endif %}
</span>
</div>
Binary file modified userpage/__pycache__/admin.cpython-36.pyc
Binary file not shown.
Binary file modified userpage/__pycache__/models.cpython-36.pyc
Binary file not shown.
Binary file modified userpage/__pycache__/views.cpython-36.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion userpage/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Register your models here.
class ProfileAdmin(admin.ModelAdmin):
list_display = ('user','address','avatar','invite_code','mobile','wechat','weibo','facebook','twitter','instagram')
list_display = ('user','address','avatar','point','invite_code','mobile','wechat','weibo','facebook','twitter','instagram')
admin.site.register(Profile,ProfileAdmin)


Expand Down
6 changes: 4 additions & 2 deletions userpage/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Meta:
class ProfileForm(ModelForm):
class Meta:
model = Profile
fields = ('avatar',)
fields = ('avatar','mobile','weibo','wechat','facebook','twitter','instagram','telegram')
error_messages = {
'avatar':{'required': '请上传头像'},
}
Expand All @@ -64,14 +64,15 @@ class Point(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
point_record = models.IntegerField()
record_time = models.DateTimeField(auto_now_add=True,editable=False)
event = models.CharField(choices=(('publish','发布文章'),('comment','发表评论'),('commented','文章被评论'),('register','新用户注册')),max_length=16)
event = models.CharField(choices=(('invite','邀请新用户'),('publish','发布文章'),('comment','发表评论'),('commented','文章被评论'),('register','新用户注册')),max_length=16)

def __str__(self):
return '%s %s %d' % (self.user,self.event,self.point_record)


@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
print(instance)
if created:
Profile.objects.create(user=instance)

Expand All @@ -85,3 +86,4 @@ def update_user_point(sender, instance, created, **kwargs):
user = Profile.objects.get(user=instance.user)
user.point += instance.point_record
user.save()

7 changes: 3 additions & 4 deletions userpage/templates/userpage/change.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{% extends 'base.html' %}
{% load timetonow %}

{% block header %}
<title> 物志 › {{request.user}} </title>


{% block title %}
› {{request.user}}
{% endblock %}

{% block banner %}
Expand All @@ -19,6 +17,7 @@
<a href="/">物志</a> › 修改密码
<hr>
{{change_form.as_p}}
<p> <a href="/userpage/member/{{request.user}}/">返回</a></p>
<p style="text-align:center">
<button class="btn btn-primary" type="submit" >确认修改</button>
</p>
Expand Down
7 changes: 4 additions & 3 deletions userpage/templates/userpage/login.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% extends 'base.html' %}
{% load timetonow %}

{% block header %}
<title> 物志 › 登录 </title>
{% block title %}
› 登录
{% endblock %}

{% block banner %}
Expand All @@ -28,7 +28,8 @@

<p style="text-align:center">
<label style="width:100px;text-align:right"></label>
<img style="display:inline-block;" id="check_code_img" src="/utils/check_code/" onclick="refresh_check_code(this)"></p>
<img style="display:inline-block;" id="check_code_img" src="/utils/check_code/" onclick="refresh_check_code(this)">
</p>
<p style="text-align:center">
<label style="width:100px;text-align:right" for="check_code">验证码:</label>
<input type="text" class="form-control" name="check_code" id="check_code" placeholder="请输入验证码">
Expand Down
16 changes: 12 additions & 4 deletions userpage/templates/userpage/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
{% load timetonow %}
{% load displayName %}

{% block title %}
› {{request.user}}
{% endblock %}

{% block header %}
<title> {% ifnotequal user.unread 0%} ({{user.unread}}) {% endifnotequal %} 物志 › {{request.user}} </title>

<script type="text/javascript">
$(function(){
$(".detail-tab").find(".profile-tab:first").show();
Expand Down Expand Up @@ -46,6 +50,8 @@
{% endblock %}
{% block content%}
<div class="card">
<p><a href="/">物志</a> › {{member.username}}</p>
<span class="sep"></span>
<div class="usercard row">

<div class="usercard-avatar" style="background:url(/{{member.profile.avatar}}) no-repeat;background-size:80px 80px;">
Expand Down Expand Up @@ -81,7 +87,8 @@
<li role="presentation" >
<a href="javascript:;">评论列表 &nbsp;<span class="badge">{{comments|length}}</span></a>
</li>
{% ifequal member.id user.id %}

{% ifequal member.username user.user.username %}
<li role="presentation" >
<a href="javascript:;">消息提醒 &nbsp; {% ifnotequal unread 0 %}<span class="badge" style="background-color:#d73a49">{{unread}}</span>{% endifnotequal %}</a>
</li>
Expand Down Expand Up @@ -129,7 +136,7 @@
{% endfor %}
</div>

{% ifequal member.id user.id %}
{% ifequal member.username user.user.username %}
<div class="profile-tab" >
{# 消息提醒 #}
<p></p>
Expand All @@ -145,9 +152,10 @@
<table class="table">
<thead>
<th>时间</th>
<th>记录</th>
<th>操作</th>
<th>积分</th>
</thead>

{% for i in points %}
<tr>
<td>{{i.record_time}}</td>
Expand Down
Loading

0 comments on commit c6da3a9

Please sign in to comment.