diff --git a/article/__pycache__/models.cpython-36.pyc b/article/__pycache__/models.cpython-36.pyc index 7ed3163..433674b 100644 Binary files a/article/__pycache__/models.cpython-36.pyc and b/article/__pycache__/models.cpython-36.pyc differ diff --git a/article/models.py b/article/models.py index c001a75..ad3db8c 100644 --- a/article/models.py +++ b/article/models.py @@ -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 diff --git a/article/templates/article/detail.html b/article/templates/article/detail.html index 79166a4..0d0002a 100644 --- a/article/templates/article/detail.html +++ b/article/templates/article/detail.html @@ -12,7 +12,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, @@ -20,6 +20,13 @@ ); + {% endblock %} @@ -41,11 +48,12 @@

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

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

+ 发表于:{{art.publish_time|timetonow}}        标签:{% if arg.tag %}{{art.tag}}{% endif %}

广告位

@@ -62,13 +70,13 @@

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

-  {{i.comment_time|timetonow}}前    +  {{i.comment_time|timetonow}}    {% ifequal request.user.id i.user.id %} 作者 {% endifequal %} # {{forloop.counter}} - Reply + Reply

diff --git a/article/templates/article/publish.html b/article/templates/article/publish.html index b74ae3c..67fb5d9 100644 --- a/article/templates/article/publish.html +++ b/article/templates/article/publish.html @@ -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, diff --git a/db.sqlite3 b/db.sqlite3 index 13c3287..d6fba15 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/edconline/__pycache__/settings.cpython-36.pyc b/edconline/__pycache__/settings.cpython-36.pyc index 649fe15..3001fda 100644 Binary files a/edconline/__pycache__/settings.cpython-36.pyc and b/edconline/__pycache__/settings.cpython-36.pyc differ diff --git a/edconline/settings.py b/edconline/settings.py index 4e0d62b..f9884d7 100644 --- a/edconline/settings.py +++ b/edconline/settings.py @@ -46,6 +46,7 @@ 'article', 'userpage', + 'notification', ] MIDDLEWARE = [ diff --git a/notification/__pycache__/__init__.cpython-36.pyc b/notification/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000..c6366c3 Binary files /dev/null and b/notification/__pycache__/__init__.cpython-36.pyc differ diff --git a/notification/__pycache__/admin.cpython-36.pyc b/notification/__pycache__/admin.cpython-36.pyc new file mode 100644 index 0000000..422f1bc Binary files /dev/null and b/notification/__pycache__/admin.cpython-36.pyc differ diff --git a/notification/__pycache__/models.cpython-36.pyc b/notification/__pycache__/models.cpython-36.pyc new file mode 100644 index 0000000..4155ec5 Binary files /dev/null and b/notification/__pycache__/models.cpython-36.pyc differ diff --git a/notification/admin.py b/notification/admin.py index 4e61edb..95fd24f 100644 --- a/notification/admin.py +++ b/notification/admin.py @@ -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) diff --git a/notification/migrations/0001_initial.py b/notification/migrations/0001_initial.py new file mode 100644 index 0000000..e7a7155 --- /dev/null +++ b/notification/migrations/0001_initial.py @@ -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')), + ], + ), + ] diff --git a/notification/migrations/0002_msg_unread.py b/notification/migrations/0002_msg_unread.py new file mode 100644 index 0000000..49f4d4a --- /dev/null +++ b/notification/migrations/0002_msg_unread.py @@ -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), + ), + ] diff --git a/notification/migrations/0003_msg_comment_time.py b/notification/migrations/0003_msg_comment_time.py new file mode 100644 index 0000000..ec5768a --- /dev/null +++ b/notification/migrations/0003_msg_comment_time.py @@ -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, + ), + ] diff --git a/notification/migrations/__pycache__/0001_initial.cpython-36.pyc b/notification/migrations/__pycache__/0001_initial.cpython-36.pyc new file mode 100644 index 0000000..e9d1d49 Binary files /dev/null and b/notification/migrations/__pycache__/0001_initial.cpython-36.pyc differ diff --git a/notification/migrations/__pycache__/0002_msg_unread.cpython-36.pyc b/notification/migrations/__pycache__/0002_msg_unread.cpython-36.pyc new file mode 100644 index 0000000..440facb Binary files /dev/null and b/notification/migrations/__pycache__/0002_msg_unread.cpython-36.pyc differ diff --git a/notification/migrations/__pycache__/0003_msg_comment_time.cpython-36.pyc b/notification/migrations/__pycache__/0003_msg_comment_time.cpython-36.pyc new file mode 100644 index 0000000..96d1761 Binary files /dev/null and b/notification/migrations/__pycache__/0003_msg_comment_time.cpython-36.pyc differ diff --git a/notification/migrations/__pycache__/__init__.cpython-36.pyc b/notification/migrations/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000..0ba14a9 Binary files /dev/null and b/notification/migrations/__pycache__/__init__.cpython-36.pyc differ diff --git a/notification/models.py b/notification/models.py index 2e2b061..6fe42a2 100644 --- a/notification/models.py +++ b/notification/models.py @@ -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() + diff --git a/static/bootstrap/css/style.css b/static/bootstrap/css/style.css index 8408566..eb13f9f 100755 --- a/static/bootstrap/css/style.css +++ b/static/bootstrap/css/style.css @@ -204,7 +204,11 @@ span.floor { display:none; } +.member_comments { + padding:10px 20px 10px 20px; + border-bottom: 1px solid #e2e2e2 +} diff --git a/templates/base.html b/templates/base.html index 1ac51c7..cdfca29 100644 --- a/templates/base.html +++ b/templates/base.html @@ -84,7 +84,7 @@

{% if title %}{{title}}{% endif %}

    未读提醒 - 0{{user.msg}} + {{user.unread}}    

diff --git a/templates/index.html b/templates/index.html index a70a854..f37882e 100644 --- a/templates/index.html +++ b/templates/index.html @@ -2,12 +2,17 @@ {% load timetonow %} {% block banner %} +
+

+
+{% endblock %} + -{% endblock %} + {% block content %} diff --git a/userpage/__pycache__/models.cpython-36.pyc b/userpage/__pycache__/models.cpython-36.pyc index 9aa0cc4..f5503da 100644 Binary files a/userpage/__pycache__/models.cpython-36.pyc and b/userpage/__pycache__/models.cpython-36.pyc differ diff --git a/userpage/__pycache__/views.cpython-36.pyc b/userpage/__pycache__/views.cpython-36.pyc index 68f5bd5..c9d7c82 100644 Binary files a/userpage/__pycache__/views.cpython-36.pyc and b/userpage/__pycache__/views.cpython-36.pyc differ diff --git a/userpage/migrations/0005_auto_20180302_1610.py b/userpage/migrations/0005_auto_20180302_1610.py new file mode 100644 index 0000000..404da5e --- /dev/null +++ b/userpage/migrations/0005_auto_20180302_1610.py @@ -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), + ), + ] diff --git a/userpage/migrations/__pycache__/0005_auto_20180302_1610.cpython-36.pyc b/userpage/migrations/__pycache__/0005_auto_20180302_1610.cpython-36.pyc new file mode 100644 index 0000000..f562d68 Binary files /dev/null and b/userpage/migrations/__pycache__/0005_auto_20180302_1610.cpython-36.pyc differ diff --git a/userpage/models.py b/userpage/models.py index 277a7da..3404a42 100644 --- a/userpage/models.py +++ b/userpage/models.py @@ -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. @@ -13,7 +14,7 @@ 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 @@ -21,12 +22,13 @@ def __str__(self): @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 diff --git a/userpage/templates/userpage/profile.html b/userpage/templates/userpage/profile.html index fe4d162..64ef98a 100644 --- a/userpage/templates/userpage/profile.html +++ b/userpage/templates/userpage/profile.html @@ -4,13 +4,13 @@ 物志 > {{request.user}} {% if user_form.errors %} @@ -75,14 +75,14 @@