Skip to content

Commit

Permalink
Merge pull request liangliangyy#63 from liangliangyy/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
liangliangyy authored Dec 15, 2017
2 parents ec6fb3d + 16f2233 commit d3e0f9c
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 39 deletions.
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ windows电脑:
有详细的部署介绍.

为了安全起见,没有把`SECRET_KEY`上传到Github中而是在环境变量中配置的,如果你想要正常运行的话,需要修改`settings.py`中的`SECRET_KEY`为你自己的就可以了。
如:
`SECRET_KEY = 'n9ceqv38)#&mwuat@(mjb_p%em$e8$qyr#fw9ot!=ba6lijx-6'`
如:`SECRET_KEY = 'n9ceqv38)#&mwuat@(mjb_p%em$e8$qyr#fw9ot!=ba6lijx-6'`
若本地部署后发现静态文件无法加载.请将`settings.py`中的`DEBUG=False`修改为`DEBUG=True`即可.

## 运行
Expand All @@ -65,17 +64,17 @@ windows电脑:

### 创建数据库

终端下执行:
终端下执行:

./manage.py makemigrations
./manage.py migrate
./manage.py migrate
### 创建超级用户

终端下执行:
终端下执行:

./manage.py createsuperuser
### 创建测试数据
终端下执行:
终端下执行:

./manage.py create_testdata
### 收集静态文件
Expand All @@ -84,15 +83,26 @@ windows电脑:
./manage.py collectstatic --noinput
./manage.py compress --force
### 开始运行:
执行:
执行:
`./manage.py runserver`





浏览器打开: http://127.0.0.1:8000/ 就可以看到效果了。
浏览器打开: http://127.0.0.1:8000/ 就可以看到效果了。

## 问题相关

有任何问题欢迎提Issue,或者将问题描述发送至我邮箱 `liangliangyy#gmail.com`.我会尽快解答.推荐提交Issue方式.
## 捐赠
如果您觉得本项目对您有所帮助,欢迎您请我喝杯咖啡,您的支持是我最大的动力,您可以扫描下方二维码为我付款,谢谢。
### 支付宝:
<div align="center">
<img src="https://resource.lylinux.net/image/2017/12/16/IMG_0207.jpg" width="300" height="300" />
</div>

### 微信:
<div align="center">
<img src="https://resource.lylinux.net/image/2017/12/16/IMG_0206.jpg" width="300" height="300" />
</div>
3 changes: 3 additions & 0 deletions accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
from django.contrib.auth.models import AbstractUser, BaseUserManager
from django.core.urlresolvers import reverse
from django.contrib.sites.models import Site
from django.utils.timezone import now


# Create your models here.

class BlogUser(AbstractUser):
nickname = models.CharField('昵称', max_length=50, blank=True)
mugshot = models.ImageField('头像', upload_to='upload/mugshots', blank=True)
created_time = models.DateTimeField('创建时间', default=now)
last_mod_time = models.DateTimeField('修改时间', default=now)

# objects = BlogUserManager()

Expand Down
12 changes: 8 additions & 4 deletions blog/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ArticlelAdmin(admin.ModelAdmin):
list_display_links = ('id', 'title')
list_filter = (ArticleListFilter, 'status', 'type', 'category', 'tags')
filter_horizontal = ('tags',)
exclude = ('slug', 'created_time')
exclude = ('slug', 'created_time', 'last_mod_time')

def get_form(self, request, obj=None, **kwargs):
form = super(ArticlelAdmin, self).get_form(request, obj, **kwargs)
Expand All @@ -53,15 +53,19 @@ def save_model(self, request, obj, form, change):


class TagAdmin(admin.ModelAdmin):
exclude = ('slug',)
exclude = ('slug', 'last_mod_time', 'created_time')


class CategoryAdmin(admin.ModelAdmin):
exclude = ('slug',)
exclude = ('slug', 'last_mod_time', 'created_time')


class LinksAdmin(admin.ModelAdmin):
exclude = ('last_mod_time', 'created_time')


admin.site.register(Article, ArticlelAdmin)
# admin.site.register(BlogPage, ArticlelAdmin)
admin.site.register(Category, CategoryAdmin)
admin.site.register(Tag, TagAdmin)
admin.site.register(Links)
admin.site.register(Links, LinksAdmin)
15 changes: 9 additions & 6 deletions blog/management/commands/create_testdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,28 @@ class Command(BaseCommand):

def handle(self, *args, **options):
user = \
get_user_model().objects.get_or_create(email='test@test.com', username='testuser',
get_user_model().objects.get_or_create(email='test@test.com', username='测试用户',
password='test!q@w#eTYU')[0]

pcategory = Category.objects.get_or_create(name='pcategory', parent_category=None)[0]
pcategory = Category.objects.get_or_create(name='我是父类目', parent_category=None)[0]

category = Category.objects.get_or_create(name='category', parent_category=pcategory)[0]
category = Category.objects.get_or_create(name='子类目', parent_category=pcategory)[0]

category.save()

for i in range(1, 10):
basetag = Tag()
basetag.name = "标签"
basetag.save()
for i in range(1, 20):
article = Article.objects.get_or_create(category=category,
title='nice title ' + str(i),
body='nice content ' + str(i),
author=user
)[0]
tag = Tag()
tag.name = "nicetag" + str(i)
tag.name = "标签" + str(i)
tag.save()
article.tags.add(tag)
article.tags.add(basetag)
article.save()

from DjangoBlog.utils import cache
Expand Down
15 changes: 6 additions & 9 deletions blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
from django.contrib.sites.models import Site
from DjangoBlog.utils import cache_decorator, logger, cache
from django.utils.functional import cached_property
from django.utils.timezone import now


class BaseModel(models.Model):
slug = models.SlugField(default='no-slug', max_length=60, blank=True)
created_time = models.DateTimeField('创建时间', default=now)
last_mod_time = models.DateTimeField('修改时间', default=now)

def save(self, *args, **kwargs):
from DjangoBlog.blog_signals import article_save_signal
Expand All @@ -19,7 +22,7 @@ def save(self, *args, **kwargs):
super().save(*args, **kwargs)
# type = self.__class__.__name__
is_update_views = 'update_fields' in kwargs and len(kwargs['update_fields']) == 1 and kwargs['update_fields'][
0] == 'views'
0] == 'views'
article_save_signal.send(sender=self.__class__, is_update_views=is_update_views, id=self.id)

def get_full_url(self):
Expand Down Expand Up @@ -47,8 +50,6 @@ class Article(BaseModel):
)
title = models.CharField('标题', max_length=200, unique=True)
body = models.TextField('正文')
created_time = models.DateTimeField('创建时间', auto_now_add=True)
last_mod_time = models.DateTimeField('修改时间', auto_now=True)
pub_time = models.DateTimeField('发布时间', blank=True, null=True)
status = models.CharField('文章状态', max_length=1, choices=STATUS_CHOICES, default='p')
comment_status = models.CharField('评论状态', max_length=1, choices=COMMENT_STATUS, default='o')
Expand Down Expand Up @@ -124,8 +125,6 @@ def prev_article(self):
class Category(BaseModel):
"""文章分类"""
name = models.CharField('分类名', max_length=30, unique=True)
created_time = models.DateTimeField('创建时间', auto_now_add=True)
last_mod_time = models.DateTimeField('修改时间', auto_now=True)
parent_category = models.ForeignKey('self', verbose_name="父级分类", blank=True, null=True)

class Meta:
Expand Down Expand Up @@ -180,8 +179,6 @@ def parse(category):
class Tag(BaseModel):
"""文章标签"""
name = models.CharField('标签名', max_length=30, unique=True)
created_time = models.DateTimeField('创建时间', auto_now_add=True)
last_mod_time = models.DateTimeField('修改时间', auto_now=True)

def __str__(self):
return self.name
Expand All @@ -204,8 +201,8 @@ class Links(models.Model):
name = models.CharField('链接名称', max_length=30, unique=True)
link = models.URLField('链接地址')
sequence = models.IntegerField('排序', unique=True)
created_time = models.DateTimeField('创建时间', auto_now_add=True)
last_mod_time = models.DateTimeField('修改时间', auto_now=True)
created_time = models.DateTimeField('创建时间', default=now)
last_mod_time = models.DateTimeField('修改时间', default=now)

class Meta:
ordering = ['sequence']
Expand Down
12 changes: 8 additions & 4 deletions blog/templatetags/blog_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from django.core.urlresolvers import reverse
from blog.models import Article, Category, Tag, Links
from django.utils.encoding import force_text
from django.shortcuts import get_object_or_404
import hashlib
import urllib
from comments.models import Comment
Expand Down Expand Up @@ -178,12 +179,13 @@ def load_pagination_info(page_obj, page_type, tag_name):
previous_number = page_obj.previous_page_number()
previous_url = reverse('blog:index_page', kwargs={'page': previous_number})
if page_type == '分类标签归档':
tag = get_object_or_404(Tag, name=tag_name)
if page_obj.has_next():
next_number = page_obj.next_page_number()
next_url = reverse('blog:tag_detail_page', kwargs={'page': next_number, 'tag_name': tag_name})
next_url = reverse('blog:tag_detail_page', kwargs={'page': next_number, 'tag_name': tag.slug})
if page_obj.has_previous():
previous_number = page_obj.previous_page_number()
previous_url = reverse('blog:tag_detail_page', kwargs={'page': previous_number, 'tag_name': tag_name})
previous_url = reverse('blog:tag_detail_page', kwargs={'page': previous_number, 'tag_name': tag.slug})
if page_type == '作者文章归档':
if page_obj.has_next():
next_number = page_obj.next_page_number()
Expand All @@ -193,13 +195,15 @@ def load_pagination_info(page_obj, page_type, tag_name):
previous_url = reverse('blog:author_detail_page', kwargs={'page': previous_number, 'author_name': tag_name})

if page_type == '分类目录归档':
category = get_object_or_404(Category, name=tag_name)
if page_obj.has_next():
next_number = page_obj.next_page_number()
next_url = reverse('blog:category_detail_page', kwargs={'page': next_number, 'category_name': tag_name})
next_url = reverse('blog:category_detail_page',
kwargs={'page': next_number, 'category_name': category.slug})
if page_obj.has_previous():
previous_number = page_obj.previous_page_number()
previous_url = reverse('blog:category_detail_page',
kwargs={'page': previous_number, 'category_name': tag_name})
kwargs={'page': previous_number, 'category_name': category.slug})

return {
'previous_url': previous_url,
Expand Down
6 changes: 3 additions & 3 deletions blog/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ def test_validate_article(self):
self.assertIsNotNone(s)

p = Paginator(Tag.objects.all(), 2)
s = load_pagination_info(p.page(1), '分类标签归档', 'tagname')
s = load_pagination_info(p.page(1), '分类标签归档', tag.slug)
self.assertIsNotNone(s)

p = Paginator(BlogUser.objects.all(), 2)
s = load_pagination_info(p.page(1), '作者文章归档', 'username')
s = load_pagination_info(p.page(1), '作者文章归档', 'liangliangyy')
self.assertIsNotNone(s)

p = Paginator(Category.objects.all(), 2)
s = load_pagination_info(p.page(1), '分类目录归档', 'categoryname')
s = load_pagination_info(p.page(1), '分类目录归档', category.slug)
self.assertIsNotNone(s)

f = BlogSearchForm()
Expand Down
4 changes: 2 additions & 2 deletions blog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
url(r'^author/(?P<author_name>\w+)/(?P<page>\d+).html$', views.AuthorDetailView.as_view(),
name='author_detail_page'),

url(r'^tag/(?P<tag_name>.+).html$', views.TagDetailView.as_view(), name='tag_detail'),
url(r'^tag/(?P<tag_name>.+)/(?P<page>\d+).html$', views.TagDetailView.as_view(), name='tag_detail_page'),
url(r'^tag/(?P<tag_name>[\w-]+).html$', views.TagDetailView.as_view(), name='tag_detail'),
url(r'^tag/(?P<tag_name>[\w-]+)/(?P<page>\d+).html$', views.TagDetailView.as_view(), name='tag_detail_page'),

url(r'^upload', views.fileupload, name='upload'),
url(r'^refresh', views.refresh_memcache, name='refresh')
Expand Down
5 changes: 3 additions & 2 deletions comments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
from django.conf import settings
from blog.models import Article
from DjangoBlog.utils import logger
from django.utils.timezone import now


# Create your models here.

class Comment(models.Model):
body = models.TextField('正文', max_length=300)
created_time = models.DateTimeField('创建时间', auto_now_add=True)
last_mod_time = models.DateTimeField('修改时间', auto_now=True)
created_time = models.DateTimeField('创建时间', default=now)
last_mod_time = models.DateTimeField('修改时间', default=now)
author = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name='作者', on_delete=models.CASCADE)
article = models.ForeignKey(Article, verbose_name='文章', on_delete=models.CASCADE)
parent_comment = models.ForeignKey('self', verbose_name="上级评论", blank=True, null=True)
Expand Down
3 changes: 3 additions & 0 deletions oauth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Create your models here.
from django.conf import settings
from django.utils.timezone import now


class OAuthUser(models.Model):
Expand All @@ -13,6 +14,8 @@ class OAuthUser(models.Model):
type = models.CharField(blank=False, null=False, max_length=50)
email = models.CharField(max_length=50, null=True, blank=True)
matedata = models.CharField(max_length=2000, null=True, blank=True)
created_time = models.DateTimeField('创建时间', default=now)
last_mod_time = models.DateTimeField('修改时间', default=now)

def __str__(self):
return self.nikename
Expand Down
4 changes: 3 additions & 1 deletion templates/share_layout/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
Powered by
<a href="https://www.djangoproject.com/" rel="nofollow" target="blank">Django</a>
&nbsp;|&nbsp;
<a href="https://github.com/liangliangyy/DjangoBlog" rel="nofollow" target="blank"> LiangLiangyy</a>
<a href="https://github.com/liangliangyy/DjangoBlog" rel="nofollow" target="blank">LiangLiangyy</a>
|
<a href="https://www.lylinux.net" target="blank">Lylinux</a>
|
本页面加载耗时:<!!LOAD_TIMES!!>s
</div>
Expand Down

0 comments on commit d3e0f9c

Please sign in to comment.