Permalink
Browse files

single post page, 长文章单独显示页面

  • Loading branch information...
1 parent 7a70439 commit 28c12c7c320da182e93499812a48f01e9295e149 @laiwei committed Apr 11, 2012
View
4 past/model/data.py
@@ -568,6 +568,4 @@ def get_origin_uri(self):
return self.data.get("id", "") or self.data.get("link", "")
def get_summary(self):
- #summary的排版有问题,暂时先换回content
- #return self.data.get("summary", "")
- return self.get_content()
+ return self.data.get("summary", "")[:140]
View
4 past/model/status.py
@@ -34,6 +34,7 @@ def __init__(self, id, user_id, origin_id,
self.origin_user_id = UserAlias.get_by_user_and_type(self.user_id, self.site).alias
_raw_data_obj = self.get_data()
##对于140字以内的消息,summary和text相同;对于wordpress等长文,summary只是摘要,text为全文
+ ##summary当作属性来,可以缓存在mc中,text太大了,作为一个method
self.summary = _raw_data_obj and _raw_data_obj.get_summary()
if self.site == config.OPENID_TYPE_DICT[config.OPENID_TWITTER]:
self.create_time += datetime.timedelta(seconds=8*3600)
@@ -72,14 +73,15 @@ def __hash__(self):
d.update(s.encode("utf8"))
return int(d.hexdigest(),16)
- def _generate_bare_text(self, offset=150):
+ def _generate_bare_text(self, offset=140):
bare_text = self.summary[:offset]
bare_text = clear_html_element(bare_text).replace(u"", "").replace(u"", "").replace("amp;","")
bare_text = re.sub("\s", "", bare_text)
bare_text = re.sub("http://t.cn/[a-zA-Z0-9]+", "", bare_text)
bare_text = re.sub("http://t.co/[a-zA-Z0-9]+", "", bare_text)
bare_text = re.sub("http://url.cn/[a-zA-Z0-9]+", "", bare_text)
bare_text = re.sub("http://goo.gl/[a-zA-Z0-9]+", "", bare_text)
+ bare_text = re.sub("http://dou.bz/[a-zA-Z0-9]+", "", bare_text)
return bare_text
##TODO:这个clear_cache需要拆分
View
2 past/templates/bind_wordpress.html
@@ -6,7 +6,7 @@
<div id="sidebar"></div>
<div id="rightbar">
{{blocks.rightbar_intros_block(intros)}}
- <div class="sep10"></div>
+
{{blocks.rightbar_feedback_block()}}
</div>
View
27 past/templates/blocks.html
@@ -65,7 +65,7 @@
{% endfor %}
</div>
</div>
- <div class="sep20"></div>
+ <div class="sep3"></div>
{% endif %}
{% endwith %}
{% endif %}
@@ -74,6 +74,7 @@
{% macro rightbar_tags_block(tags_list) -%}
+{%if tags_list%}
<div class="box">
<div class="cell">
<span class="bigger">个人关键字</span>
@@ -89,20 +90,25 @@
<span>个人关键字是thepast根据你的timeline自动提取的,如果你觉得不错,请推荐给你的朋友^^</span>
</div>
</div>
+<div class="sep10"></div>
+{%endif%}
{%- endmacro %}
{% macro rightbar_intros_block(intros) -%}
-<div class="box">
- <div class="cell">
- <span class="bigger">个人介绍</span>
- </div>
+ {%if intros%}
+ <div class="box">
+ <div class="cell">
+ <span class="bigger">个人介绍</span>
+ </div>
- {% for intro in intros%}
- <div class="inner">
- {{intro|nl2br|safe}}
+ {% for intro in intros%}
+ <div class="inner">
+ {{intro|nl2br|safe}}
+ </div>
+ {% endfor%}
</div>
- {% endfor%}
-</div>
+ <div class="sep10"></div>
+ {%endif%}
{%- endmacro %}
@@ -121,4 +127,5 @@
</div>
</div>
+<div class="sep10"></div>
{%- endmacro %}
View
2 past/templates/home.html
@@ -2,6 +2,8 @@
{% block content_block %}
<!-- 个人杂志计划简介 -->
+ <div class="sep3"></div>
+ {{ blocks.notification_block() }}
<div id="news">
<h2>个人杂志计划<sup><a target="_blank" href="https://github.com/laiwei/thepast">[开源]</a></sup></h2>
<p>1.实时聚合你在“豆瓣”、“新浪微博”、“腾讯微博”、“Twitter”等平台的 Timeline,支持同步历史记录、消息去重。</p>
View
1 past/templates/past.html
@@ -7,7 +7,6 @@
<div id="sidebar"></div>
<div id="rightbar">
{{blocks.rightbar_intros_block(intros)}}
- <div class="sep10"></div>
{{blocks.rightbar_feedback_block()}}
</div>
View
31 past/templates/post.html
@@ -0,0 +1,31 @@
+{% extends "layout.html" %}
+
+{% import "blocks.html" as blocks %}
+
+{% block content_block %}
+ <div id="sidebar"></div>
+ <div id="rightbar">
+ {{blocks.rightbar_intros_block(intros)}}
+
+ {{blocks.rightbar_feedback_block()}}
+ </div>
+
+ <div id="middlebar">
+ <!--提醒-->
+ {{ blocks.notification_block() }}
+
+ <div class="box">
+ <div class="inner"><a href="/i">首页</a> &gt; 文章</div>
+ </div>
+ <div class="sep10"></div>
+ <!--single post-->
+ <div class="box">
+ <div class="cell">
+ {{status.title}}
+ <div class="sep3"></div>
+ <span class="fade">{{status.create_time.strftime("%Y-%m-%d %H:%M:%S")}}</span>
+ </div>
+ <div class="inner">{{status.text|safe}}</div>
+ </div>
+ </div>
+{% endblock %}
View
5 past/templates/status.html
@@ -159,11 +159,12 @@
{% macro wordpress_status(s, pdf=False) -%}
{% set origin_uri = s.get_origin_uri() %}
- <a href="{{origin_uri[1]}}" class="bigger">{{s.title}}</a><br/>
+ <a href="{{origin_uri[1]}}">{{s.title}}</a><br/>
{%if pdf%}
{{s.text|wrap_long_line}}
{%else%}
- {{s.summary|safe}}
+ {{s.summary}}
+ <a href="/post/{{s.id}}">&nbsp;read more</a>
{%endif%}
{%if pdf%}
View
1 past/templates/timeline.html
@@ -25,7 +25,6 @@
<div class="sep10"></div>
{{blocks.rightbar_intros_block(intros)}}
- <div class="sep10"></div>
{{blocks.rightbar_feedback_block()}}
<div class="sep10"></div>
View
2 past/view/settings.py
@@ -16,7 +16,7 @@
from .utils import require_login
@app.route("/settings", methods=["GET", "POST"])
-@require_login("/settings")
+@require_login()
def settings():
##XXX:
intros = [g.user.get_thirdparty_profile(x).get("intro") for x in config.OPENID_TYPE_DICT.values()]
View
4 past/view/utils.py
@@ -3,13 +3,13 @@
from functools import wraps
from flask import g, flash, redirect
-def require_login(redir=None):
+def require_login():
def _(f):
@wraps(f)
def __(*a, **kw):
if not g.user:
flash(u"为了保护用户的隐私,请先登录后再查看^^", "tip")
- return redirect("/home?redir=%s" %redir)
+ return redirect("/home")
return f(*a, **kw)
return __
return _
View
19 past/view/views.py
@@ -64,7 +64,7 @@ def index():
return redirect(url_for("home"))
@app.route("/i")
-@require_login("/i")
+@require_login()
def timeline():
ids = Status.get_ids(user_id=g.user.id, start=g.start, limit=g.count, cate=g.cate)
status_list = Status.gets(ids)
@@ -86,7 +86,7 @@ def home():
users=users, config=config)
@app.route("/past")
-@require_login("/past")
+@require_login()
def past():
intros = [g.user.get_thirdparty_profile(x).get("intro") for x in config.OPENID_TYPE_DICT.values()]
intros = filter(None, intros)
@@ -109,6 +109,19 @@ def past():
return render_template("past.html", **locals())
+@app.route("/post/<id>")
+@require_login()
+def post(id):
+ intros = [g.user.get_thirdparty_profile(x).get("intro") for x in config.OPENID_TYPE_DICT.values()]
+ intros = filter(None, intros)
+
+ status = Status.get(id)
+ if not status:
+ flash(u"访问的文章不存在^^","error")
+
+ return render_template("post.html", **locals())
+
+
#TODO:xxx
@app.route("/user")
def user_explore():
@@ -284,7 +297,7 @@ def sync(cates):
return json_encode({'ok':'true'})
@app.route("/pdf")
-@require_login("/pdf")
+@require_login()
def mypdf():
if not g.user:
return redirect(url_for("pdf", uid=config.MY_USER_ID))

0 comments on commit 28c12c7

Please sign in to comment.