-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d748dc7
commit b2b8be8
Showing
29 changed files
with
204 additions
and
51 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ | |
|
||
'article', | ||
'userpage', | ||
'notification', | ||
] | ||
|
||
MIDDLEWARE = [ | ||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+693 Bytes
notification/migrations/__pycache__/0003_msg_comment_time.cpython-36.pyc
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+585 Bytes
userpage/migrations/__pycache__/0005_auto_20180302_1610.cpython-36.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.