diff --git a/pypress/__init__.py b/pypress/__init__.py
index f330a9d..92519d8 100644
--- a/pypress/__init__.py
+++ b/pypress/__init__.py
@@ -22,7 +22,7 @@
from flaskext.uploads import configure_uploads
from pypress import views, helpers
-from pypress.models import User, Post, Tag, Link
+from pypress.models import User, Post, Tag, Link, Comment
from pypress.extensions import db, mail, cache, photos
from pypress.helpers import render_template
@@ -136,6 +136,15 @@ def archives():
return dict(archives=archives)
+ @app.context_processor
+ def latest_comments():
+ latest_comments = cache.get("latest_comments")
+ if latest_comments is None:
+ latest_comments = Comment.query.order_by(Comment.created_date.desc()) \
+ .limit(5).all()
+ cache.set("latest_comments", latest_comments)
+ return dict(latest_comments=latest_comments)
+
@app.context_processor
def config():
return dict(config=app.config)
diff --git a/pypress/config.cfg b/pypress/config.cfg
index df574b3..fb0ea3f 100644
--- a/pypress/config.cfg
+++ b/pypress/config.cfg
@@ -1,10 +1,10 @@
-DEBUG = False
-SECRET_KEY = 'key'
+DEBUG = True
+SECRET_KEY = 'secret test'
-SQLALCHEMY_DATABASE_URI = 'mysql://username:password@localhost/pypress?charset=utf8'
+SQLALCHEMY_DATABASE_URI = 'sqlite:///test.db'
SQLALCHEMY_ECHO = False
-UPLOADS_DEFAULT_DEST = '/path/to/pypress/pypress/static/'
+UPLOADS_DEFAULT_DEST = '/path/to/pypress/static/'
UPLOADS_DEFAULT_URL = '/static'
CACHE_TYPE = "simple"
@@ -16,19 +16,19 @@ USE_LOCAL_COMMENT = True # if false, to include comment.html
ACCEPT_LANGUAGES = ['en', 'zh']
-BABEL_DEFAULT_LOCALE = 'en'
+BABEL_DEFAULT_LOCALE = 'zh'
BABEL_DEFAULT_TIMEZONE = 'Asia/Shanghai'
# http://twitter.com/oauth_clients/new
-TWITTER_KEY = 'key'
-TWITTER_SECRET = 'twiiter_secret'
+TWITTER_KEY = ''
+TWITTER_SECRET = ''
PER_PAGE = 20
DEBUG_LOG = 'logs/debug.log'
ERROR_LOG = 'logs/error.log'
-ADMINS = ('username@gmail.com',)
+ADMINS = ('yourname@domain.com',)
MAIL_SERVER = 'smtp.gmail.com'
MAIL_PORT = 465
@@ -37,4 +37,4 @@ MAIL_USE_SSL = True
MAIL_DEBUG = DEBUG
MAIL_USERNAME = 'username'
MAIL_PASSWORD = 'password'
-DEFAULT_MAIL_SENDER = 'username@gmail.com'
+DEFAULT_MAIL_SENDER = 'yourname@domain.com'
diff --git a/pypress/helpers.py b/pypress/helpers.py
index 5c8506f..37b3d8b 100644
--- a/pypress/helpers.py
+++ b/pypress/helpers.py
@@ -11,6 +11,7 @@
import urlparse
import functools
import hashlib
+import socket, struct
from datetime import datetime
@@ -265,3 +266,9 @@ def code2html(code, lang):
formatter = HtmlFormatter()
return highlight(code, lexer, formatter)
+def ip2long(ip):
+ return struct.unpack("!I",socket.inet_aton(ip))[0]
+
+def long2ip(num):
+ return socket.inet_ntoa(struct.pack("!I",num))
+
diff --git a/pypress/templates/blog/_comment.html b/pypress/templates/blog/_comment.html
new file mode 100644
index 0000000..e03c130
--- /dev/null
+++ b/pypress/templates/blog/_comment.html
@@ -0,0 +1,12 @@
+
diff --git a/pypress/templates/blog/about.html b/pypress/templates/blog/about.html
index fe8dd1e..a71d743 100644
--- a/pypress/templates/blog/about.html
+++ b/pypress/templates/blog/about.html
@@ -26,6 +26,7 @@ 待开发:
日志:
+ - 1.1.0 2010-04-21 (添加“最新评论”,修复非mysql引擎下的错误)
- 1.1.0 2010-04-12 (修复一些bug)
- 1.1.0 2010-03-12 (twitter API支持)
- 1.0.0 2010-03-09 (核心功能实现)
diff --git a/pypress/templates/blog/archive.html b/pypress/templates/blog/archive.html
index 33ccc57..dffa7ff 100644
--- a/pypress/templates/blog/archive.html
+++ b/pypress/templates/blog/archive.html
@@ -19,6 +19,7 @@ {{ _("Archive") }}
{% include "blog/_postnow.html" %}
{% include "blog/_search.html" %}
{% include "blog/_tags.html" %}
+ {% include "blog/_comment.html" %}
{% include "blog/_archive.html" %}
{% include "blog/_links.html" %}
diff --git a/pypress/templates/blog/comment.html b/pypress/templates/blog/comment.html
index 6f7a236..b290f39 100644
--- a/pypress/templates/blog/comment.html
+++ b/pypress/templates/blog/comment.html
@@ -1 +1 @@
-Your comments javascript here...
+Your comment javascript code...
diff --git a/pypress/templates/blog/list.html b/pypress/templates/blog/list.html
index ea98a2f..827dd43 100644
--- a/pypress/templates/blog/list.html
+++ b/pypress/templates/blog/list.html
@@ -12,7 +12,9 @@
By
{{ post.author.nickname }}.
{{ post.created_date|timesince }}
- {% if post.tags %}{% for tag,url in post.linked_taglist %}
{{ tag }}{{ loop.last and '...' or ', ' }}{% endfor %}
{% endif %}
+ {% if post.tags %}{% for tag,url in
+ post.linked_taglist %}
{{ tag }}{{ ', ' if not
+ loop.last }}{% endfor %}
{% endif %}
{{ post.summary|endtags|code_highlight|safe }}
@@ -35,6 +37,7 @@
{% include "blog/_postnow.html" %}
{% include "blog/_search.html" %}
{% include "blog/_tags.html" %}
+ {% include "blog/_comment.html" %}
{% include "blog/_archive.html" %}
{% include "blog/_links.html" %}
diff --git a/pypress/templates/blog/tags.html b/pypress/templates/blog/tags.html
index 391225f..f98049c 100644
--- a/pypress/templates/blog/tags.html
+++ b/pypress/templates/blog/tags.html
@@ -19,6 +19,7 @@ {{ _("Tags") }}
{% include "blog/_postnow.html" %}
{% include "blog/_search.html" %}
{% include "blog/_tags.html" %}
+ {% include "blog/_comment.html" %}
{% include "blog/_archive.html" %}
{% include "blog/_links.html" %}
diff --git a/pypress/templates/blog/view.html b/pypress/templates/blog/view.html
index 7a97ae5..3b31976 100644
--- a/pypress/templates/blog/view.html
+++ b/pypress/templates/blog/view.html
@@ -11,7 +11,8 @@ {{ post.title }}
By
{{ post.author.nickname }}.
{{ post.created_date|timesince }}
- {% if post.tags %}{% for tag,url in post.linked_taglist %}
{{ tag }}{{ loop.last and '...' or ', ' }}{% endfor %}
{% endif %}
+ {% if post.tags %}{% for tag,url in
+ post.linked_taglist %}
{{ tag }}{{ ', ' if not loop.last }}{% endfor %}
{% endif %}
{{ post.content|code_highlight|gistcode|safe }}
@@ -83,6 +84,7 @@ {{ _('Comments') }}
{% include "blog/_postnow.html" %}
{% include "blog/_search.html" %}
{% include "blog/_tags.html" %}
+ {% include "blog/_comment.html" %}
{% include "blog/_archive.html" %}
{% include "blog/_links.html" %}
diff --git a/pypress/themes/default/static/style.css b/pypress/themes/default/static/style.css
index 248d4e2..ed49941 100644
--- a/pypress/themes/default/static/style.css
+++ b/pypress/themes/default/static/style.css
@@ -358,7 +358,10 @@ textarea.text:focus {
border-bottom: 1px solid #eee;
color: #999;
}
-.sidebox a {
+.sidebox strong {
+ color: #333;
+}
+.sidebox small a {
color: #333;
}
.sidebox .more {
diff --git a/pypress/themes/default/templates/layout.html b/pypress/themes/default/templates/layout.html
index db1d966..653f6a8 100644
--- a/pypress/themes/default/templates/layout.html
+++ b/pypress/themes/default/templates/layout.html
@@ -65,6 +65,7 @@ Team blog
{% include "blog/_search.html" %}
{% include "blog/_tags.html" %}
{% include "blog/_archive.html" %}
+ {% include "blog/_comment.html" %}
{% include "blog/_links.html" %}
{%- endblock %}
diff --git a/pypress/views/frontend.py b/pypress/views/frontend.py
index 54ffe2d..2f42645 100644
--- a/pypress/views/frontend.py
+++ b/pypress/views/frontend.py
@@ -128,6 +128,10 @@ def people(username, page=1):
if status:
flash(_("Twitter posting is success"), "success")
+
+ return redirect(url_for('frontend.people',
+ username=username,
+ page=page))
else:
flash(_("Twitter posting is failed"), "error")
diff --git a/pypress/views/post.py b/pypress/views/post.py
index 0797df7..34f0231 100644
--- a/pypress/views/post.py
+++ b/pypress/views/post.py
@@ -17,7 +17,7 @@
from flaskext.babel import gettext as _
from pypress import signals
-from pypress.helpers import render_template, cached
+from pypress.helpers import render_template, cached, ip2long
from pypress.permissions import auth
from pypress.extensions import db
@@ -123,7 +123,7 @@ def add_comment(post_id, parent_id=None):
comment = Comment(post=post,
parent=parent,
- ip=db.func.inet_aton(request.environ['REMOTE_ADDR']))
+ ip=ip2long(request.environ['REMOTE_ADDR']))
form.populate_obj(comment)
if g.user: