diff --git a/article/__pycache__/models.cpython-36.pyc b/article/__pycache__/models.cpython-36.pyc index dd15828..8791d41 100644 Binary files a/article/__pycache__/models.cpython-36.pyc and b/article/__pycache__/models.cpython-36.pyc differ diff --git a/article/migrations/0015_article_comment_count.py b/article/migrations/0015_article_comment_count.py new file mode 100644 index 0000000..5b3ed46 --- /dev/null +++ b/article/migrations/0015_article_comment_count.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.2 on 2018-03-01 03:50 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('article', '0014_auto_20180228_1552'), + ] + + operations = [ + migrations.AddField( + model_name='article', + name='comment_count', + field=models.IntegerField(default=0), + ), + ] diff --git a/article/migrations/0016_comment_invalid.py b/article/migrations/0016_comment_invalid.py new file mode 100644 index 0000000..d7e5115 --- /dev/null +++ b/article/migrations/0016_comment_invalid.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.2 on 2018-03-01 06:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('article', '0015_article_comment_count'), + ] + + operations = [ + migrations.AddField( + model_name='comment', + name='invalid', + field=models.CharField(choices=[('Y', '是'), ('N', '否')], default='N', max_length=64), + ), + ] diff --git a/article/migrations/__pycache__/0015_article_comment_count.cpython-36.pyc b/article/migrations/__pycache__/0015_article_comment_count.cpython-36.pyc new file mode 100644 index 0000000..77c2ba5 Binary files /dev/null and b/article/migrations/__pycache__/0015_article_comment_count.cpython-36.pyc differ diff --git a/article/migrations/__pycache__/0016_comment_invalid.cpython-36.pyc b/article/migrations/__pycache__/0016_comment_invalid.cpython-36.pyc new file mode 100644 index 0000000..420bdf4 Binary files /dev/null and b/article/migrations/__pycache__/0016_comment_invalid.cpython-36.pyc differ diff --git a/article/models.py b/article/models.py index ed98dbb..95acb89 100644 --- a/article/models.py +++ b/article/models.py @@ -4,6 +4,8 @@ from django.contrib.auth.models import User from django.forms import * from userpage.models import * +from django.db.models.signals import post_save +from django.dispatch import receiver #from django.conf import settings #from tagging.fields import TagField #from tagging.models import Tag @@ -35,7 +37,8 @@ class Article(models.Model): tag = models.CharField(max_length=128, blank=True, null=True) visible = models.CharField(choices=(('Y','是'),('N','否')),max_length=64,default='N') readtime = models.IntegerField(default=0) - #comment_count = models.IntegerField(default=0) + comment_count = models.IntegerField(default=0) + #update_time = models.DateTimeField(auto_now=True,blank=True,null=True) #def set_tags(self, tags): # Tag.objects.update_tags(self, tags) @@ -48,6 +51,7 @@ class Meta: db_table ="article" ordering = ['-publish_time'] + class ArticleForm(ModelForm): class Meta: model = Article @@ -76,6 +80,7 @@ class Comment(models.Model): user = models.ForeignKey(Profile,on_delete=models.CASCADE,default=0) comment_time = models.DateTimeField(auto_now_add=True,editable=False) comment = HTMLField() + invalid = models.CharField(choices=(('Y','是'),('N','否')),max_length=64,default='N') ip = models.GenericIPAddressField(blank=True,null=True,default='0.0.0.0') clickcount = models.IntegerField(default=0) refer = models.CharField(max_length=5096,default='none') @@ -91,7 +96,15 @@ class Meta: class CommentForm(ModelForm): class Meta: model = Comment - fields = ('article','user','comment','ip') + fields = ('article','user','comment','ip','invalid') widgets = { 'comment':TinyMCE(attrs={'cols':'100%','rows':10}), } + + +@receiver(post_save, sender=Comment) +def comment_count(sender, created, instance, **kwargs): + if created: + art = Article.objects.get(pk=instance.article.id) + art.comment_count += 1 + art.save() diff --git a/article/templates/article/detail.html b/article/templates/article/detail.html index 74e50f3..890bbfb 100644 --- a/article/templates/article/detail.html +++ b/article/templates/article/detail.html @@ -54,16 +54,16 @@

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

评论

- + {% for i in comments %} -
+
-
+
 {{i.comment_time}}    - {% ifequal request.user.id art.author_id.id %} + {% ifequal request.user.id i.user.id %} 作者 {% endifequal %} # {{forloop.counter}} @@ -72,10 +72,15 @@

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

+ {% ifequal i.invalid 'Y' %} +

“此评论违规”

+ {% else %} {{i.comment|safe|escape}} + {% endifequal %} +
- + {% endfor %}
diff --git a/article/templatetags/__init__.py b/article/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/article/templatetags/__pycache__/__init__.cpython-36.pyc b/article/templatetags/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000..e6e3080 Binary files /dev/null and b/article/templatetags/__pycache__/__init__.cpython-36.pyc differ diff --git a/article/templatetags/__pycache__/upto.cpython-36.pyc b/article/templatetags/__pycache__/upto.cpython-36.pyc new file mode 100644 index 0000000..e2e5b1e Binary files /dev/null and b/article/templatetags/__pycache__/upto.cpython-36.pyc differ diff --git a/article/templatetags/upto.py b/article/templatetags/upto.py new file mode 100644 index 0000000..c8d5b18 --- /dev/null +++ b/article/templatetags/upto.py @@ -0,0 +1,10 @@ +from django import template +from django.template.defaultfilters import stringfilter + +register = template.Library() + +@register.filter +@stringfilter +def upto(value, delimiter=None): + return value.split(delimiter)[0] +upto.is_safe = True \ No newline at end of file diff --git a/db.sqlite3 b/db.sqlite3 index 6ad43d3..16a8c56 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/static/bootstrap/css/style.css b/static/bootstrap/css/style.css index fa337c3..ff4cb2f 100755 --- a/static/bootstrap/css/style.css +++ b/static/bootstrap/css/style.css @@ -128,6 +128,10 @@ div.container-fluid { padding-bottom:30px; } +.card .comment { + border-top:1px solid #e2e2e2; +} + .card .comment div { display: inline-block; margin:10px; @@ -194,9 +198,13 @@ span.floor { margin:auto; } +.invalid { + background-color: #eee; +} - - +.profile-tab { + display:none; +} diff --git a/templates/index.html b/templates/index.html index f6f2f7d..38b7929 100644 --- a/templates/index.html +++ b/templates/index.html @@ -27,6 +27,8 @@

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

     {{i.section}}     +  {{i.readtime}} +      {{i.tag}} 阅读全文 diff --git a/userpage/__pycache__/models.cpython-36.pyc b/userpage/__pycache__/models.cpython-36.pyc index 02de966..9b1e159 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 2b42b88..f9547bc 100644 Binary files a/userpage/__pycache__/views.cpython-36.pyc and b/userpage/__pycache__/views.cpython-36.pyc differ diff --git a/userpage/models.py b/userpage/models.py index b28ddfb..7f0bd69 100644 --- a/userpage/models.py +++ b/userpage/models.py @@ -30,11 +30,12 @@ def save_user_profile(sender, instance, **kwargs): class UserForm(ModelForm): class Meta: model = User - fields = ('first_name', 'last_name', 'email') + fields = ('username','first_name', 'last_name', 'email') widgets = { - 'email':TextInput(attrs={'class':'form-control','placeholder':"E-mail"}), - 'first_name':TextInput(attrs={'class':'form-control','placeholder':"First Name"}), - 'last_name':TextInput(attrs={'class':'form-control','placeholder':"Last Name"}), + 'username':TextInput(attrs={'class':'form-control','placeholder':"Username"}), + 'email':TextInput(attrs={'class':'form-control','placeholder':"E-mail"}), + 'first_name':TextInput(attrs={'class':'form-control','placeholder':"First Name"}), + 'last_name':TextInput(attrs={'class':'form-control','placeholder':"Last Name"}), } class ProfileForm(ModelForm): diff --git a/userpage/templates/userpage/profile.html b/userpage/templates/userpage/profile.html index 83aee1c..5691900 100644 --- a/userpage/templates/userpage/profile.html +++ b/userpage/templates/userpage/profile.html @@ -1,7 +1,17 @@ {% extends "base.html"%} - +{% load upto %} {% block header %} [ {{request.user}} ]用户详情 - 物志 + {% endblock %} {% block banner %} @@ -41,43 +51,76 @@
-