diff --git a/article/__pycache__/admin.cpython-36.pyc b/article/__pycache__/admin.cpython-36.pyc index 998a701..b10ac21 100644 Binary files a/article/__pycache__/admin.cpython-36.pyc and b/article/__pycache__/admin.cpython-36.pyc differ diff --git a/article/__pycache__/models.cpython-36.pyc b/article/__pycache__/models.cpython-36.pyc index 6bc0210..35a5cb0 100644 Binary files a/article/__pycache__/models.cpython-36.pyc and b/article/__pycache__/models.cpython-36.pyc differ diff --git a/article/__pycache__/urls.cpython-36.pyc b/article/__pycache__/urls.cpython-36.pyc index 19f5bf5..febf41e 100644 Binary files a/article/__pycache__/urls.cpython-36.pyc and b/article/__pycache__/urls.cpython-36.pyc differ diff --git a/article/__pycache__/views.cpython-36.pyc b/article/__pycache__/views.cpython-36.pyc index 35ace1c..5a54e08 100644 Binary files a/article/__pycache__/views.cpython-36.pyc and b/article/__pycache__/views.cpython-36.pyc differ diff --git a/article/admin.py b/article/admin.py index 2a0ea84..c939909 100644 --- a/article/admin.py +++ b/article/admin.py @@ -4,6 +4,7 @@ # Register your models here. class ArticleAdmin(admin.ModelAdmin): list_display = ('id','section','title','author','author_id','publish_time','visible') + #search_fields = ('section__name',) admin.site.register(Article,ArticleAdmin) @@ -13,5 +14,5 @@ class SectionAdmin(admin.ModelAdmin): class CommentAdmin(admin.ModelAdmin): - list_display=('id','article','user','mail','ip','comment_time','comment') + list_display=('id','article','user','ip','comment_time','comment') admin.site.register(Comment,CommentAdmin) diff --git a/article/migrations/0010_auto_20180226_1738.py b/article/migrations/0010_auto_20180226_1738.py new file mode 100644 index 0000000..0f9d933 --- /dev/null +++ b/article/migrations/0010_auto_20180226_1738.py @@ -0,0 +1,20 @@ +# Generated by Django 2.0.2 on 2018-02-26 09:38 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('article', '0009_auto_20180225_2027'), + ] + + operations = [ + migrations.AlterField( + model_name='comment', + name='user', + field=models.ForeignKey(default=0, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/article/migrations/0011_remove_comment_mail.py b/article/migrations/0011_remove_comment_mail.py new file mode 100644 index 0000000..018dcf2 --- /dev/null +++ b/article/migrations/0011_remove_comment_mail.py @@ -0,0 +1,17 @@ +# Generated by Django 2.0.2 on 2018-02-26 10:07 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('article', '0010_auto_20180226_1738'), + ] + + operations = [ + migrations.RemoveField( + model_name='comment', + name='mail', + ), + ] diff --git a/article/migrations/0012_auto_20180226_1935.py b/article/migrations/0012_auto_20180226_1935.py new file mode 100644 index 0000000..3546576 --- /dev/null +++ b/article/migrations/0012_auto_20180226_1935.py @@ -0,0 +1,19 @@ +# Generated by Django 2.0.2 on 2018-02-26 11:35 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('article', '0011_remove_comment_mail'), + ] + + operations = [ + migrations.AlterField( + model_name='comment', + name='user', + field=models.ForeignKey(default=0, on_delete=django.db.models.deletion.CASCADE, to='userpage.Profile'), + ), + ] diff --git a/article/migrations/0013_auto_20180226_1938.py b/article/migrations/0013_auto_20180226_1938.py new file mode 100644 index 0000000..041fb75 --- /dev/null +++ b/article/migrations/0013_auto_20180226_1938.py @@ -0,0 +1,19 @@ +# Generated by Django 2.0.2 on 2018-02-26 11:38 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('article', '0012_auto_20180226_1935'), + ] + + operations = [ + migrations.AlterField( + model_name='article', + name='author_id', + field=models.ForeignKey(default=0, on_delete=django.db.models.deletion.CASCADE, to='userpage.Profile'), + ), + ] diff --git a/article/migrations/__pycache__/0010_auto_20180226_1738.cpython-36.pyc b/article/migrations/__pycache__/0010_auto_20180226_1738.cpython-36.pyc new file mode 100644 index 0000000..aa5bb9e Binary files /dev/null and b/article/migrations/__pycache__/0010_auto_20180226_1738.cpython-36.pyc differ diff --git a/article/migrations/__pycache__/0011_remove_comment_mail.cpython-36.pyc b/article/migrations/__pycache__/0011_remove_comment_mail.cpython-36.pyc new file mode 100644 index 0000000..9ad6412 Binary files /dev/null and b/article/migrations/__pycache__/0011_remove_comment_mail.cpython-36.pyc differ diff --git a/article/migrations/__pycache__/0012_auto_20180226_1935.cpython-36.pyc b/article/migrations/__pycache__/0012_auto_20180226_1935.cpython-36.pyc new file mode 100644 index 0000000..900c59a Binary files /dev/null and b/article/migrations/__pycache__/0012_auto_20180226_1935.cpython-36.pyc differ diff --git a/article/migrations/__pycache__/0013_auto_20180226_1938.cpython-36.pyc b/article/migrations/__pycache__/0013_auto_20180226_1938.cpython-36.pyc new file mode 100644 index 0000000..a51d8e6 Binary files /dev/null and b/article/migrations/__pycache__/0013_auto_20180226_1938.cpython-36.pyc differ diff --git a/article/models.py b/article/models.py index 9597c68..14b022e 100644 --- a/article/models.py +++ b/article/models.py @@ -3,6 +3,7 @@ from tinymce.models import HTMLField from django.contrib.auth.models import User from django.forms import ModelForm,Textarea +from userpage.models import * #from django.conf import settings #from tagging.fields import TagField #from tagging.models import Tag @@ -23,7 +24,7 @@ class Meta: class Article(models.Model): id=models.AutoField(primary_key=True) section=models.ForeignKey(Section,on_delete=models.CASCADE,default=0) - author_id = models.ForeignKey(User,on_delete=models.CASCADE,default=0) + author_id = models.ForeignKey(Profile,on_delete=models.CASCADE,default=0) author = models.CharField(max_length=128,default='') #author_id = models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE) publish_time = models.DateTimeField(auto_now_add=True) @@ -58,8 +59,7 @@ class Meta: class Comment(models.Model): id = models.AutoField(primary_key=True) article = models.ForeignKey(Article,on_delete=models.CASCADE,default=0) - user = models.CharField(max_length=128) - mail = models.CharField(max_length=1024) + user = models.ForeignKey(Profile,on_delete=models.CASCADE,default=0) comment_time = models.DateTimeField(auto_now_add=True) comment = HTMLField() ip = models.GenericIPAddressField() @@ -74,3 +74,10 @@ class Meta: db_table ="comment" ordering = ['-comment_time'] +class CommentForm(ModelForm): + class Meta: + model = Comment + fields = ('article','user','comment') + widgets = { + 'comment':Textarea(), + } diff --git a/article/templates/article/detail.html b/article/templates/article/detail.html new file mode 100644 index 0000000..d016227 --- /dev/null +++ b/article/templates/article/detail.html @@ -0,0 +1,56 @@ +{% extends "base.html" %} + +{% block header %} +{{art.title}} - 物志 + +{% endblock %} + + +{% block banner %} + +{% endblock %} + + +{% block content %} +
+ 作者: {{art.author}} +           + 发表于:{{art.publish_time}} + + + {{art.detail|safe}} +
+ +
+ + {% for i in comments %} +
+
+

{{i.user.username}}

+
+
+

+ {{i.comment|safe}} +  {{i.publish_time}} + +   #{{forloop.counter}} + +
+
+ + {% endfor %} +
+ +
+
+ {% csrf_token %} + {{ comment_form.as_p }} + +
+ +
+{% endblock %} diff --git a/article/urls.py b/article/urls.py index 110bc25..27b4498 100644 --- a/article/urls.py +++ b/article/urls.py @@ -3,6 +3,6 @@ from . import views urlpatterns = [ - path('', views.homepage), + #path('', views.homepage), path('/', views.detail, name='detail'), ] diff --git a/article/views.py b/article/views.py index ba2ab2d..5f5bef9 100644 --- a/article/views.py +++ b/article/views.py @@ -2,6 +2,8 @@ from django.http import HttpResponse,HttpResponseRedirect from django.template import RequestContext,Template,Context,loader,defaultfilters from django.shortcuts import render_to_response +from django.contrib import messages +from .models import * # Create your views here. @@ -10,7 +12,22 @@ def homepage(request): def detail(request, article_id): - return HttpResponse("You're looking at article %s." % article_id) + art = Article.objects.get(pk=article_id) + comments = Comment.objects.filter(article_id=article_id).order_by('comment_time') + + if request.method == 'POST': + comment_form = CommentForm(request.POST,instance=None) + if comment_form.is_valid(): + comment_form.save() + return redirect('.') + else: + messages.error(request, 'Please correct the error below.') + else: + comment_form = CommentForm(instance=None) + + return render(request,'article/detail.html',{'art':art,'comments':comments,'comment_form':comment_form}) + #return HttpResponse("You're looking at article %s." % article_id) + def vote(request, article_id): return HttpResponse("You're voting on article %s." % article_id) diff --git a/db.sqlite3 b/db.sqlite3 index 1cc89df..0877efc 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/edconline/__pycache__/views.cpython-36.pyc b/edconline/__pycache__/views.cpython-36.pyc index 085f72c..48fc4d2 100644 Binary files a/edconline/__pycache__/views.cpython-36.pyc and b/edconline/__pycache__/views.cpython-36.pyc differ diff --git a/edconline/views.py b/edconline/views.py index 7fce85f..3db0376 100644 --- a/edconline/views.py +++ b/edconline/views.py @@ -1,5 +1,6 @@ from django.shortcuts import render from django.http import HttpResponse,HttpResponseRedirect +from django.db.models import Q from django.template import RequestContext,Template,Context,loader,defaultfilters from django.shortcuts import render_to_response from article.models import * @@ -14,6 +15,10 @@ def user_login(request): } def homepage(request): + query = request.GET.items() + data = {} + for i in query: + data[i[0]]=i[1] if request.user.is_authenticated :# and request.user.has_perm('cmdb.permit')): username = request.user.username @@ -23,7 +28,12 @@ def homepage(request): imgs = os.listdir('static/upload/') cover = random.sample(imgs,1)[0] - arts = Article.objects.all() + if 'catalog' in data: + qset = (Q(section__name=data['catalog'])) + arts = Article.objects.filter(qset).order_by('-publish_time') + else: + arts = Article.objects.all().order_by('-publish_time') + secs = Section.objects.all() return render(request,'index.html',{'cover':cover,'username':username,'arts':arts,'secs':secs}) diff --git a/static/avatar/seaside.jpg b/static/avatar/seaside.jpg new file mode 100644 index 0000000..e17d0c3 Binary files /dev/null and b/static/avatar/seaside.jpg differ diff --git a/static/avatar/seaside_pXW0mZb.jpg b/static/avatar/seaside_pXW0mZb.jpg new file mode 100644 index 0000000..e17d0c3 Binary files /dev/null and b/static/avatar/seaside_pXW0mZb.jpg differ diff --git a/static/bootstrap/css/style.css b/static/bootstrap/css/style.css index 372a49b..bd0110e 100755 --- a/static/bootstrap/css/style.css +++ b/static/bootstrap/css/style.css @@ -5,6 +5,26 @@ html,body { height: 100%; } +img{ + width: auto; + height: auto; + max-width: 100%; + max-height: 100%; + overflow:hidden; + display: block; +} + +img.avatar-img { + display:inline-block; + width:16px; + height:18px; + padding-bottom:2px; +} + +.margintop { + margin-top:10px; +} + .banner { top:0; width:100%; diff --git a/templates/.index.html.swp b/templates/.index.html.swp deleted file mode 100644 index a561004..0000000 Binary files a/templates/.index.html.swp and /dev/null differ diff --git a/templates/base.html b/templates/base.html index 6e2b140..1789a70 100644 --- a/templates/base.html +++ b/templates/base.html @@ -3,16 +3,16 @@ - {% if title %}{{title}} - {% endif %}物志 + {% block header %} - + {% if title %}{{title}} - {% endif %}物志 {% endblock %} @@ -93,19 +93,18 @@

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

diff --git a/templates/index.html b/templates/index.html index 835cef5..24dbf36 100644 --- a/templates/index.html +++ b/templates/index.html @@ -40,7 +40,7 @@

{{i.title}}

分类

{% for i in secs %} -

{{i.name}}

+

{{i.name}}

{% endfor %} diff --git a/userpage/__pycache__/models.cpython-36.pyc b/userpage/__pycache__/models.cpython-36.pyc index 96b8bca..5ac925a 100644 Binary files a/userpage/__pycache__/models.cpython-36.pyc and b/userpage/__pycache__/models.cpython-36.pyc differ diff --git a/userpage/migrations/0003_auto_20180226_1938.py b/userpage/migrations/0003_auto_20180226_1938.py new file mode 100644 index 0000000..93226ce --- /dev/null +++ b/userpage/migrations/0003_auto_20180226_1938.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.2 on 2018-02-26 11:38 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('userpage', '0002_auto_20180224_1712'), + ] + + operations = [ + migrations.AlterField( + model_name='profile', + name='avatar', + field=models.ImageField(blank=True, null=True, upload_to='static/avatar/'), + ), + ] diff --git a/userpage/migrations/__pycache__/0003_auto_20180226_1938.cpython-36.pyc b/userpage/migrations/__pycache__/0003_auto_20180226_1938.cpython-36.pyc new file mode 100644 index 0000000..4a5d704 Binary files /dev/null and b/userpage/migrations/__pycache__/0003_auto_20180226_1938.cpython-36.pyc differ diff --git a/userpage/models.py b/userpage/models.py index cec05f4..3986b24 100644 --- a/userpage/models.py +++ b/userpage/models.py @@ -11,7 +11,10 @@ class Profile(models.Model): #bio = models.TextField(max_length=500, blank=True) location = models.CharField(max_length=30, blank=True) #birth_date = models.DateField(null=True, blank=True) - avatar = models.ImageField(upload_to='avatar/', blank=True, null=True) + avatar = models.ImageField(upload_to='static/avatar/', blank=True, null=True) + + def __str__(self): + return self.user.username @receiver(post_save, sender=User) def create_user_profile(sender, instance, created, **kwargs):