Skip to content

Commit

Permalink
add notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
gothack329 committed Mar 2, 2018
1 parent d748dc7 commit b2b8be8
Show file tree
Hide file tree
Showing 29 changed files with 204 additions and 51 deletions.
Binary file modified article/__pycache__/models.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 @@ -2,8 +2,8 @@
from django.db import models
from tinymce.models import HTMLField,TinyMCE
from django.contrib.auth.models import User
from django.forms import *
from userpage.models import *
from django.forms import ModelForm,TextInput,FileInput,widgets
from userpage.models import Profile
from django.db.models.signals import post_save
from django.dispatch import receiver
#from django.conf import settings
Expand Down
16 changes: 12 additions & 4 deletions article/templates/article/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@
'selector': 'textarea',
'theme': 'modern',
'plugins': ' textcolor save link image media preview codesample contextmenu table code lists fullscreen insertdatetime nonbreaking contextmenu directionality searchreplace wordcount visualblocks visualchars code fullscreen autolink lists charmap print hr anchor pagebreak textpattern',
'toolbar1': 'bold italic underline fontsizeselect forecolor alignleft alignright aligncenter alignjustify | indent outdent bullist numlist link image media hr codesample preview',
'toolbar1': 'bold italic underline fontsizeselect forecolor | alignleft alignright aligncenter alignjustify indent outdent bullist numlist | link image media hr codesample preview',
'contextmenu': 'formats | link image',
'menubar': false,
'statusbar': false,
}

);
</script>
<script type="text/javascript">
function atuser(arg){
const content = tinyMCE.activeEditor.getContent();
tinyMCE.activeEditor.setContent(content+arg);
tinyMCE.execCommand('mceFocus',false,'id_comment');
}
</script>

{% endblock %}

Expand All @@ -41,11 +48,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|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.publish_time|timetonow}}</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span class="fad">标签:{% if arg.tag %}{{art.tag}}{% endif %}</span>
<span class="sep margintop" ></span>
<div class="ad1"> <h3>广告位</h3> </div>
Expand All @@ -62,13 +70,13 @@ <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|timetonow}}</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 %}
<span class="pull-right ico fad floor" id="comment_{{i.id}}"># {{forloop.counter}}</span>
<span class="pull-right ico ">
<a href="#"><img style="inline-block" src="/static/image/reply.png" align="absmiddle" border="0" alt="Reply"></a>
<a href="javascript:;" onclick="atuser('<a href=#comment_{{i.id}} >#{{forloop.counter}}</a> @<a class=mentioned_user href=/userpage/member/{{i.user}}>{{i.user}}</a>&nbsp;')"><img style="inline-block" src="/static/image/reply.png" align="absmiddle" border="0" alt="Reply"></a>
</span>

<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 @@ -11,7 +11,7 @@
'selector': 'textarea',
'theme': 'modern',
'plugins': ' textcolor save link image media preview codesample contextmenu table code lists fullscreen insertdatetime nonbreaking contextmenu directionality searchreplace wordcount visualblocks visualchars code fullscreen autolink lists charmap print hr anchor pagebreak textpattern',
'toolbar1': 'bold italic underline fontsizeselect forecolor alignleft alignright aligncenter alignjustify | indent outdent bullist numlist link image media hr codesample preview',
'toolbar1': 'bold italic underline fontsizeselect forecolor | alignleft alignright aligncenter alignjustify indent outdent bullist numlist | link image media hr codesample preview',
'contextmenu': 'formats | link image',
'menubar': false,
'statusbar': false,
Expand Down
Binary file modified db.sqlite3
Binary file not shown.
Binary file modified edconline/__pycache__/settings.cpython-36.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions edconline/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

'article',
'userpage',
'notification',
]

MIDDLEWARE = [
Expand Down
Binary file added notification/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added notification/__pycache__/admin.cpython-36.pyc
Binary file not shown.
Binary file added notification/__pycache__/models.cpython-36.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion notification/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@


class MsgAdmin(admin.ModelAdmin):
list_display=('id','user','mention_user','msg_time')
list_display=('id','comment_time','unread','comment',)
admin.site.register(Msg,MsgAdmin)
25 changes: 25 additions & 0 deletions notification/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 2.0.2 on 2018-03-02 06:49

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
('userpage', '0004_auto_20180228_1552'),
('article', '0016_comment_invalid'),
]

operations = [
migrations.CreateModel(
name='Msg',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('comment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='article.Comment')),
('mention_user', models.ManyToManyField(to='userpage.Profile')),
],
),
]
18 changes: 18 additions & 0 deletions notification/migrations/0002_msg_unread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.0.2 on 2018-03-02 07:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('notification', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='msg',
name='unread',
field=models.CharField(choices=[('Y', '是'), ('N', '否')], default='Y', max_length=8),
),
]
20 changes: 20 additions & 0 deletions notification/migrations/0003_msg_comment_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 2.0.2 on 2018-03-02 08:10

from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
('notification', '0002_msg_unread'),
]

operations = [
migrations.AddField(
model_name='msg',
name='comment_time',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
32 changes: 24 additions & 8 deletions notification/models.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
from django.db import models
from django.contrib.auth.models import User
from django.forms import ModelForm,Textarea
from userpage.models import *
from article.models import *
from userpage.models import Profile
from article.models import Comment
from django.db.models.signals import post_save
from django.dispatch import receiver
from bs4 import BeautifulSoup as bs

# Create your models here.

class Msg(models.Model):
id=models.AutoField(primary_key=True)
user = models.ForeignKey(Profile, on_delete=models.CASCADE)
mention_user = models.ManyToManyField(Profile, on_delete=models.CASCADE)
id=models.AutoField(primary_key=True)
mention_user = models.ManyToManyField(Profile)
comment = models.ForeignKey(Comment, on_delete=models.CASCADE)
msg_time = models.DateTimeField(auto_now_add=True,editable=False)
unread = models.CharField(choices=(('Y','是'),('N','否')),max_length=8,default='Y')
comment_time = models.DateTimeField(auto_now_add=True,editable=False)

def __str__(self):
return self.comments

@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 = list(set(mu))
if len(mu) > 0 and created:
msg = Msg.objects.create(comment=instance,unread='Y',comment_time=instance.comment_time)
for user in mu:
inst_u = User.objects.get(username=user)
inst_p = Profile.objects.get(user=inst_u)
inst_p.unread += 1
msg.mention_user.add(inst_p)
inst_p.save()
msg.save()


4 changes: 4 additions & 0 deletions static/bootstrap/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ span.floor {
display:none;
}

.member_comments {

padding:10px 20px 10px 20px;
border-bottom: 1px solid #e2e2e2
}



Expand Down
2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ <h1>{% if title %}{{title}}{% endif %} </h1>
</span> &nbsp;&nbsp;&nbsp;
<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}}
<a href="/userpage/member/{{user.user}}/">{{user.unread}}</a>
</span> &nbsp;&nbsp;&nbsp;
</p>
</div>
Expand Down
7 changes: 6 additions & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
{% load timetonow %}

{% block banner %}
<div style="height:30px">
<p></p>
</div>
{% endblock %}

<div class="banner" style="background:url(/static/upload/{{cover}}) no-repeat;background-position:center;background-size:cover;">
<div class="container">
<h1>{% if title %}{{title}}{% endif %} </h1>
</div>
</div>
{% endblock %}


{% block content %}

Expand Down
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.
18 changes: 18 additions & 0 deletions userpage/migrations/0005_auto_20180302_1610.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.0.2 on 2018-03-02 08:10

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('userpage', '0004_auto_20180228_1552'),
]

operations = [
migrations.AlterField(
model_name='profile',
name='unread',
field=models.IntegerField(default=0),
),
]
Binary file not shown.
6 changes: 4 additions & 2 deletions userpage/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.forms import ModelForm,Textarea,TextInput,ClearableFileInput,FileInput
from django.db.models.signals import post_save
from django.dispatch import receiver
#from notification.models import Msg

# Create your models here.

Expand All @@ -13,20 +14,21 @@ class Profile(models.Model):
#birth_date = models.DateField(null=True, blank=True)
avatar = models.ImageField(upload_to='static/avatar/', blank=True, null=True)
point = models.IntegerField()
unread = models.IntegerField()
unread = models.IntegerField(default=0)

def __str__(self):
return self.user.username

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

@receiver(post_save, sender=User)
def save_user_profile(sender, instance, **kwargs):
instance.profile.save()


class UserForm(ModelForm):
class Meta:
model = User
Expand Down
30 changes: 17 additions & 13 deletions userpage/templates/userpage/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<title> 物志 > {{request.user}} </title>
<script type="text/javascript">
$(function(){
$(".detail-tab").find(".profile-tab:first").show();
$("#tab-nav").find("li:first").addClass("active");
$("#tab-nav li").on("click",function(){
var index=$(this).index();
$(this).parent().next().find(".profile-tab").hide().eq(index).show();
$(this).addClass("active").siblings().removeClass("active");
})
$(".detail-tab").find(".profile-tab:first").show();
$("#tab-nav").find("li:first").addClass("active");
$("#tab-nav li").on("click",function(){
var index=$(this).index();
$(this).parent().next().find(".profile-tab").hide().eq(index).show();
$(this).addClass("active").siblings().removeClass("active");
})
})
</script>
{% if user_form.errors %}
Expand Down Expand Up @@ -75,14 +75,14 @@
<div class="card">
<ul class="nav nav-tabs" id="tab-nav">
<li role="presentation" >
<a href="javascript:;">文章列表<span class="badge">{{arts|length}}</span></a>
<a href="javascript:;">文章列表 &nbsp;<span class="badge">{{arts|length}}</span></a>
</li>
<li role="presentation" >
<a href="javascript:;">评论列表<span class="badge">{{comments|length}}</span></a>
<a href="javascript:;">评论列表 &nbsp;<span class="badge">{{comments|length}}</span></a>
</li>
{% ifequal member.id user.id %}
<li role="presentation" >
<a href="javascript:;">消息提醒</a>
<a href="javascript:;">消息提醒 &nbsp; {% ifnotequal unread 0 %}<span class="badge" style="background-color:#d73a49">{{unread}}</span>{% endifnotequal %}</a>
</li>
<li role="presentation" >
<a href="javascript:;">编辑资料</a>
Expand Down Expand Up @@ -117,8 +117,8 @@
<div class="profile-tab" >
<p></p>
{% for i in comments %}
<div class="row member_comments" style="padding:10px 20px 10px 20px;border-bottom: 1px solid #e2e2e2">
<p style="background-color: #eee">于 {{i.comment_time|timetonow}} 评论了 <a href="/userpage/member/{{i.article.author_id}}/">{{i.article.author_id}} </a>的文章【 <a href="/article/{{i.article.id}}/">{{i.article}}</a></p>
<div class="row member_comments">
<p style="background-color: #eee;padding:2px">于 {{i.comment_time|timetonow}} 评论了 <a href="/userpage/member/{{i.article.author_id}}/">{{i.article.author_id}} </a>的文章【 <a href="/article/{{i.article.id}}/">{{i.article}}</a></p>
<p><a href="/article/{{i.article.id}}/#comment_{{i.id}}">{{i.comment|safe|escape}}</a></p>
</div>

Expand All @@ -128,10 +128,14 @@
{% ifequal member.id user.id %}
<div class="profile-tab" >
{# 消息提醒 #}
{% for i in notice %}
<div class="row member_comments" style="padding-left:20px">

<p style="background-color: #eee;padding:2px"><a href="/userpage/member/{{i.comment.user}}/">{{i.comment.user}}</a><a href="/article/{{i.comment.article.id}}/">{{i.comment.article}}</a> 的评论中提到了您 <span class="pull-right">{{i.comment_time|timetonow}}</span></p>
<p><a href="/article/{{i.comment.article.id}}/#comment_{{i.comment.id}}">{{i.comment|safe|escape}}</a></p>
</div>
{% endfor %}
</div>


<div class="profile-tab" >
{# 编辑资料 #}
Expand Down
Loading

0 comments on commit b2b8be8

Please sign in to comment.