Navigation Menu

Skip to content

Commit

Permalink
add latest comments and fix some bug
Browse files Browse the repository at this point in the history
  • Loading branch information
laoqiu committed Apr 21, 2011
1 parent b6ddb28 commit 2e17053
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 16 deletions.
11 changes: 10 additions & 1 deletion pypress/__init__.py
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions 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"
Expand All @@ -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
Expand All @@ -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'
7 changes: 7 additions & 0 deletions pypress/helpers.py
Expand Up @@ -11,6 +11,7 @@
import urlparse
import functools
import hashlib
import socket, struct

from datetime import datetime

Expand Down Expand Up @@ -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))

12 changes: 12 additions & 0 deletions pypress/templates/blog/_comment.html
@@ -0,0 +1,12 @@
<div id="comment" class="sidebox">
<h3>{{ _("Latest Comments") }}</h3>
<div class="inner">
{% if latest_comments %}
<ul>
{% for comment in latest_comments %}
<li><strong>{{ comment.author.nickname }}:</strong> <a href="{{ comment.url }}">{{ comment.comment }}</a></li>
{% endfor %}
</ul>
{% endif %}
</div>
</div>
1 change: 1 addition & 0 deletions pypress/templates/blog/about.html
Expand Up @@ -26,6 +26,7 @@ <h3>待开发:</h3>
</ul>
<h3>日志:</h3>
<ul>
<li>1.1.0 2010-04-21 (添加“最新评论”,修复非mysql引擎下的错误)</li>
<li>1.1.0 2010-04-12 (修复一些bug)</li>
<li>1.1.0 2010-03-12 (twitter API支持)</li>
<li>1.0.0 2010-03-09 (核心功能实现)</li>
Expand Down
1 change: 1 addition & 0 deletions pypress/templates/blog/archive.html
Expand Up @@ -19,6 +19,7 @@ <h2 class="title">{{ _("Archive") }}</h2>
{% include "blog/_postnow.html" %}
{% include "blog/_search.html" %}
{% include "blog/_tags.html" %}
{% include "blog/_comment.html" %}
{% include "blog/_archive.html" %}
{% include "blog/_links.html" %}
</div>
Expand Down
2 changes: 1 addition & 1 deletion pypress/templates/blog/comment.html
@@ -1 +1 @@
Your comments javascript here...
Your comment javascript code...
5 changes: 4 additions & 1 deletion pypress/templates/blog/list.html
Expand Up @@ -12,7 +12,9 @@ <h2 class="post-title"><a href="{{ post.url }}">{{ post.title }}</a></h2>
<div class="post-byline">
By <a href="{{ url_for('frontend.people', username=post.author.username) }}">{{ post.author.nickname }}</a>. <abbr title="{{ post.created_date|format_date('full') }}" class="time">{{ post.created_date|timesince }}</abbr>
</div>
{% if post.tags %}<div class="post-tags">{% for tag,url in post.linked_taglist %}<a href="{{ url }}">{{ tag }}</a>{{ loop.last and '...' or ', ' }}{% endfor %}</div>{% endif %}
{% if post.tags %}<div class="post-tags">{% for tag,url in
post.linked_taglist %}<a href="{{ url }}">{{ tag }}</a>{{ ', ' if not
loop.last }}{% endfor %}</div>{% endif %}
<div class="post-summary">
{{ post.summary|endtags|code_highlight|safe }}
</div>
Expand All @@ -35,6 +37,7 @@ <h2 class="post-title"><a href="{{ post.url }}">{{ post.title }}</a></h2>
{% include "blog/_postnow.html" %}
{% include "blog/_search.html" %}
{% include "blog/_tags.html" %}
{% include "blog/_comment.html" %}
{% include "blog/_archive.html" %}
{% include "blog/_links.html" %}
</div>
Expand Down
1 change: 1 addition & 0 deletions pypress/templates/blog/tags.html
Expand Up @@ -19,6 +19,7 @@ <h2 class="title">{{ _("Tags") }}</h2>
{% include "blog/_postnow.html" %}
{% include "blog/_search.html" %}
{% include "blog/_tags.html" %}
{% include "blog/_comment.html" %}
{% include "blog/_archive.html" %}
{% include "blog/_links.html" %}
</div>
Expand Down
4 changes: 3 additions & 1 deletion pypress/templates/blog/view.html
Expand Up @@ -11,7 +11,8 @@ <h2 class="post-title">{{ post.title }}</h2>
<div class="post-byline">
By <a href="{{ url_for('frontend.people', username=post.author.username) }}">{{ post.author.nickname }}</a>. <abbr title="{{ post.created_date|format_date('full') }}" class="time">{{ post.created_date|timesince }}</abbr>
</div>
{% if post.tags %}<div class="post-tags">{% for tag,url in post.linked_taglist %}<a href="{{ url }}">{{ tag }}</a>{{ loop.last and '...' or ', ' }}{% endfor %}</div>{% endif %}
{% if post.tags %}<div class="post-tags">{% for tag,url in
post.linked_taglist %}<a href="{{ url }}">{{ tag }}</a>{{ ', ' if not loop.last }}{% endfor %}</div>{% endif %}
<div class="post-content">
{{ post.content|code_highlight|gistcode|safe }}
</div>
Expand Down Expand Up @@ -83,6 +84,7 @@ <h3>{{ _('Comments') }}</h3>
{% include "blog/_postnow.html" %}
{% include "blog/_search.html" %}
{% include "blog/_tags.html" %}
{% include "blog/_comment.html" %}
{% include "blog/_archive.html" %}
{% include "blog/_links.html" %}
</div>
Expand Down
5 changes: 4 additions & 1 deletion pypress/themes/default/static/style.css
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pypress/themes/default/templates/layout.html
Expand Up @@ -65,6 +65,7 @@ <h1>Team blog</h1>
{% include "blog/_search.html" %}
{% include "blog/_tags.html" %}
{% include "blog/_archive.html" %}
{% include "blog/_comment.html" %}
{% include "blog/_links.html" %}
</div>
{%- endblock %}
Expand Down
4 changes: 4 additions & 0 deletions pypress/views/frontend.py
Expand Up @@ -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")

Expand Down
4 changes: 2 additions & 2 deletions pypress/views/post.py
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 2e17053

Please sign in to comment.