diff --git a/.gitignore b/.gitignore
index c21fc33..9735536 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,4 @@ atlassian-ide-plugin.xml
.env
*.log
*.sqlite3
+.ropeproject/
diff --git a/readme.rst b/readme.rst
index e2a22f8..3d2fae3 100644
--- a/readme.rst
+++ b/readme.rst
@@ -31,6 +31,13 @@ the5fire的技术博客源码
-------------------------------
后台修改为xadmin(0.5v)
+2016-07-02
+-------------------------------
+* Post增加is_md字段,增加对markdown格式的支持
+* 拆分settings.py文件为develop.py,product.py让配置更清晰
+* 通过DJANGOSELFBLOG_PROFILE来加载对应的配置develop/product
+* 修复创建Post时不填英文标题导致的文章无法访问的bug
+
哪些技术
------------------------------
diff --git a/requirements.txt b/requirements.txt
index 7aacf5b..39b5f3e 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -12,3 +12,4 @@ python-memcached==1.53
django-debug-toolbar==0.10.2
django-xadmin==0.5.0
django-ipware
+markdown
diff --git a/selfblog/blog/adminx.py b/selfblog/blog/adminx.py
index dc25657..4748503 100644
--- a/selfblog/blog/adminx.py
+++ b/selfblog/blog/adminx.py
@@ -1,4 +1,5 @@
-#coding:utf-8
+# coding:utf-8
+import markdown
import xadmin
from django.core import urlresolvers
@@ -35,7 +36,10 @@ def save_models(self):
obj.author = self.request.user
if not obj.summary:
obj.summary = obj.content
- if not obj.is_old:
+
+ if obj.is_md:
+ obj.content_html = markdown.markdown(obj.content, extensions=['codehilite'])
+ elif not obj.is_old:
obj.content_html = restructuredtext(obj.content)
else:
obj.content_html = obj.content.replace('\r\n', '
')
diff --git a/selfblog/blog/models.py b/selfblog/blog/models.py
index 4c62be8..cd4aaaa 100644
--- a/selfblog/blog/models.py
+++ b/selfblog/blog/models.py
@@ -1,11 +1,13 @@
# coding:utf-8
from datetime import datetime
-from django.db import models
from django.contrib.auth.models import User
+from django.db import models
+from django.db.models import signals
+from django.dispatch import receiver
from django.utils.functional import cached_property
-from selfblog import settings
+from django.conf import settings
from utils.cache import cache_decorator
STATUS = {
@@ -55,7 +57,7 @@ class Post(models.Model):
is_top = models.BooleanField(default=False, verbose_name=u'置顶')
summary = models.TextField(verbose_name=u'摘要')
- content = models.TextField(verbose_name=u'文章正文rst格式')
+ content = models.TextField(verbose_name=u'文章正文rst/md格式')
content_html = models.TextField(verbose_name=u'文章正文html')
view_times = models.IntegerField(default=1)
@@ -63,6 +65,7 @@ class Post(models.Model):
tags = models.CharField(max_length=100, null=True, blank=True, verbose_name=u'标签', help_text=u'用英文逗号分割')
status = models.IntegerField(default=0, choices=STATUS.items(), verbose_name=u'状态')
+ is_md = models.BooleanField(default=False, verbose_name=u'是否为Markdown格式')
is_old = models.BooleanField(default=False, verbose_name=u'是否为旧数据')
pub_time = models.DateTimeField(default=datetime.now, verbose_name=u'发布时间')
@@ -122,6 +125,14 @@ class Meta:
verbose_name_plural = verbose_name = u"文章"
+@receiver(signals.post_save, sender=Post)
+def check_or_update_post_alias(sender, instance=None, **kwargs):
+ # 如果alias未设置则使用id
+ if not instance.alias:
+ instance.alias = instance.id
+ instance.save()
+
+
class Page(models.Model):
author = models.ForeignKey(User, verbose_name=u'作者')
title = models.CharField(max_length=100, verbose_name=u'标题')
diff --git a/selfblog/blog/templates/base.html b/selfblog/blog/templates/base.html
index 9e3ae04..b066fa4 100644
--- a/selfblog/blog/templates/base.html
+++ b/selfblog/blog/templates/base.html
@@ -100,5 +100,6 @@