Skip to content

Commit

Permalink
article detail page
Browse files Browse the repository at this point in the history
  • Loading branch information
gothack329 committed Feb 26, 2018
1 parent 58b263d commit d16073d
Show file tree
Hide file tree
Showing 30 changed files with 230 additions and 24 deletions.
Binary file modified article/__pycache__/admin.cpython-36.pyc
Binary file not shown.
Binary file modified article/__pycache__/models.cpython-36.pyc
Binary file not shown.
Binary file modified article/__pycache__/urls.cpython-36.pyc
Binary file not shown.
Binary file modified article/__pycache__/views.cpython-36.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion article/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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)
20 changes: 20 additions & 0 deletions article/migrations/0010_auto_20180226_1738.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
17 changes: 17 additions & 0 deletions article/migrations/0011_remove_comment_mail.py
Original file line number Diff line number Diff line change
@@ -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',
),
]
19 changes: 19 additions & 0 deletions article/migrations/0012_auto_20180226_1935.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
19 changes: 19 additions & 0 deletions article/migrations/0013_auto_20180226_1938.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
13 changes: 10 additions & 3 deletions article/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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(),
}
56 changes: 56 additions & 0 deletions article/templates/article/detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{% extends "base.html" %}

{% block header %}
<title>{{art.title}} - 物志</title>

{% endblock %}


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


{% block content %}
<div class="card margintop">
<span class="fad">作者:<a href="#"><img src="/static/{{art.author_id.avatar}}" class="avatar-img">&nbsp;{{art.author}}</a> </span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span class="fad">发表于:{{art.publish_time}}</span>
<span class="sep margintop"></span>
<span class="ad1"> </span>
{{art.detail|safe}}
</div>

<div class="card">
<span class="sep"></span>
{% for i in comments %}
<div class="comment row">
<div class="comment-avatar" style="margin-top:20px;background:url(/static/{{i.user.avatar}}) no-repeat;background-position:center;background-size:cover;">
<p>{{i.user.username}}</p>
</div>
<div class="comment-info">
<p></p>
{{i.comment|safe}}
<span class="glyphicon glyphicon-time fad"> </span>&nbsp;<span class="fad">{{i.publish_time}}</span>
<span class="pull-right">
<a href="#"><span class="glyphicon glyphicon-reply fad"></span></a> &nbsp; <span class="fad">#{{forloop.counter}}</span>
</span>
</div>
</div>
<span class="sep"></span>
{% endfor %}
</div>

<div class="card">
<form method="post">
{% csrf_token %}
{{ comment_form.as_p }}
<button class="btn btn-default pull-right" type="submit">发表</button>
</form>

</div>
{% endblock %}
2 changes: 1 addition & 1 deletion article/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
from . import views

urlpatterns = [
path('', views.homepage),
#path('', views.homepage),
path('<int:article_id>/', views.detail, name='detail'),
]
19 changes: 18 additions & 1 deletion article/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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)
Binary file modified db.sqlite3
Binary file not shown.
Binary file modified edconline/__pycache__/views.cpython-36.pyc
Binary file not shown.
12 changes: 11 additions & 1 deletion edconline/views.py
Original file line number Diff line number Diff line change
@@ -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 *
Expand All @@ -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
Expand All @@ -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})

Expand Down
Binary file added static/avatar/seaside.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/avatar/seaside_pXW0mZb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions static/bootstrap/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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%;
Expand Down
Binary file removed templates/.index.html.swp
Binary file not shown.
29 changes: 14 additions & 15 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

<html>
<head>
<title>{% if title %}{{title}} - {% endif %}物志</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="EDC online">
<meta name="author" content="物志">
<link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="/static/bootstrap/css/style.css" rel="stylesheet">
<link href='http://cdn.webfont.youziku.com/webfonts/nomal/114602/46453/5a919786f629d911e0099415.css' rel='stylesheet' type='text/css' />
{% block header %}
<link href="/static/bootstrap/css/style.css" rel="stylesheet">
<title>{% if title %}{{title}} - {% endif %}物志</title>
{% endblock %}
</head>
<body>
Expand Down Expand Up @@ -93,19 +93,18 @@ <h1>{% if title %}{{title}}{% endif %} </h1>
</div>

<div class="sidebar col-md-4">
{% block sidebar %}
<div class="card">
<p>用户模块</p>
<p>这里是右侧边栏</p>
<p>这里是右侧边栏</p>
</div>
<div class="card">
<p>广告</p>
<p>这里是右侧边栏</p>
<p>这里是右侧边栏</p>
</div>
{% endblock %}

{% block sidebar %}

<div class="card">
<h4>分类</h4>
<span class="sep"></span>
{% for i in secs %}
<p><a href="/?catalog={{i.name}}">{{i.name}}</a></p>
<span class="sep"></span>
{% endfor %}
</div>

{% endblock %}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h2>{{i.title}}</h2>
<h4>分类</h4>
<span class="sep"></span>
{% for i in secs %}
<p><a href="">{{i.name}}</a></p>
<p><a href="/?catalog={{i.name}}">{{i.name}}</a></p>
<span class="sep"></span>
{% endfor %}
</div>
Expand Down
Binary file modified userpage/__pycache__/models.cpython-36.pyc
Binary file not shown.
18 changes: 18 additions & 0 deletions userpage/migrations/0003_auto_20180226_1938.py
Original file line number Diff line number Diff line change
@@ -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/'),
),
]
Binary file not shown.
5 changes: 4 additions & 1 deletion userpage/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit d16073d

Please sign in to comment.