From dc57759bf213c1c2b71e78f4c90b90b0020c000b Mon Sep 17 00:00:00 2001 From: "ben304zhe@gmail.com" Date: Tue, 28 Feb 2012 14:51:37 +0800 Subject: [PATCH 1/6] add sink function --- index.yaml | 430 +++++++++++++++++++++++++++-------------------------- topic.py | 24 ++- 2 files changed, 244 insertions(+), 210 deletions(-) diff --git a/index.yaml b/index.yaml index 5782366..cab4c0f 100644 --- a/index.yaml +++ b/index.yaml @@ -1,209 +1,221 @@ -indexes: - -# AUTOGENERATED - -# This index.yaml is automatically updated whenever the dev_appserver -# detects that a new type of query is run. If you want to manage the -# index.yaml file manually, remove the above marker line (the line -# saying "# AUTOGENERATED"). If you want to manage some indexes -# manually, move them above the marker line. The index.yaml file is -# automatically uploaded to the admin console when you next deploy -# your application using appcfg.py. - -- kind: Item - properties: - - name: column - - name: created - direction: desc - -- kind: Member - properties: - - name: email - - name: num - -- kind: Member - properties: - - name: username_lower - - name: num - -- kind: MemberBookmark - properties: - - name: member_num - - name: created - direction: desc - -- kind: Node - properties: - - name: __key__ - direction: desc - -- kind: Node - properties: - - name: category - - name: name - -- kind: Node - properties: - - name: category - - name: topics - direction: desc - -- kind: Node - properties: - - name: name - - name: num - -- kind: Node - properties: - - name: parent_node_name - - name: name - -- kind: Node - properties: - - name: section_num - - name: created - -- kind: Node - properties: - - name: section_num - - name: last_modified - direction: desc - -- kind: Node - properties: - - name: section_num - - name: topics - direction: desc - -- kind: NodeBookmark - properties: - - name: member - - name: created - direction: desc - -- kind: Note - properties: - - name: member - - name: created - direction: desc - -- kind: Note - properties: - - name: member - - name: last_modified - direction: desc - -- kind: Notification - properties: - - name: for_member_num - - name: created - direction: desc - -- kind: Notification - properties: - - name: for_member_num - - name: num - direction: desc - -- kind: Page - properties: - - name: minisite - - name: weight - -- kind: PasswordResetToken - properties: - - name: email - - name: timestamp - -- kind: PlaceMessage - properties: - - name: place - - name: created - direction: desc - -- kind: Reply - properties: - - name: __key__ - direction: desc - -- kind: Reply - properties: - - name: member_num - - name: created - direction: desc - -- kind: Reply - properties: - - name: member_num - - name: topic_num - - name: created - -- kind: Reply - properties: - - name: member_num - - name: topic_num - - name: created - direction: desc - -- kind: Reply - properties: - - name: topic_num - - name: created - -- kind: Reply - properties: - - name: topic_num - - name: created - direction: desc - -- kind: Topic - properties: - - name: __key__ - direction: desc - -- kind: Topic - properties: - - name: member - - name: created - -- kind: Topic - properties: - - name: member_num - - name: created - direction: desc - -- kind: Topic - properties: - - name: member_num - - name: node_name - - name: created - direction: desc - -- kind: Topic - properties: - - name: node - - name: created - -- kind: Topic - properties: - - name: node - - name: created - direction: desc - -- kind: Topic - properties: - - name: node_name - - name: created - direction: desc - -- kind: Topic - properties: - - name: node_num - - name: last_touched - direction: desc - -- kind: TopicBookmark - properties: - - name: member - - name: created - direction: desc +indexes: + +# AUTOGENERATED + +# This index.yaml is automatically updated whenever the dev_appserver +# detects that a new type of query is run. If you want to manage the +# index.yaml file manually, remove the above marker line (the line +# saying "# AUTOGENERATED"). If you want to manage some indexes +# manually, move them above the marker line. The index.yaml file is +# automatically uploaded to the admin console when you next deploy +# your application using appcfg.py. + +- kind: Item + properties: + - name: column + - name: created + direction: desc + +- kind: Member + properties: + - name: email + - name: num + +- kind: Member + properties: + - name: username_lower + - name: num + +- kind: MemberBookmark + properties: + - name: member_num + - name: created + direction: desc + +- kind: Node + properties: + - name: __key__ + direction: desc + +- kind: Node + properties: + - name: category + - name: name + +- kind: Node + properties: + - name: category + - name: topics + direction: desc + +- kind: Node + properties: + - name: name + - name: num + +- kind: Node + properties: + - name: parent_node_name + - name: name + +- kind: Node + properties: + - name: section_num + - name: created + +- kind: Node + properties: + - name: section_num + - name: last_modified + direction: desc + +- kind: Node + properties: + - name: section_num + - name: topics + direction: desc + +- kind: NodeBookmark + properties: + - name: member + - name: created + direction: desc + +- kind: Note + properties: + - name: member + - name: created + direction: desc + +- kind: Note + properties: + - name: member + - name: last_modified + direction: desc + +- kind: Notification + properties: + - name: for_member_num + - name: created + direction: desc + +- kind: Notification + properties: + - name: for_member_num + - name: num + direction: desc + +- kind: Page + properties: + - name: minisite + - name: weight + +- kind: PasswordResetToken + properties: + - name: email + - name: timestamp + +- kind: PlaceMessage + properties: + - name: place + - name: created + direction: desc + +- kind: Reply + properties: + - name: __key__ + direction: desc + +- kind: Reply + properties: + - name: member_num + - name: created + direction: desc + +- kind: Reply + properties: + - name: member_num + - name: topic_num + - name: created + +- kind: Reply + properties: + - name: member_num + - name: topic_num + - name: created + direction: desc + +- kind: Reply + properties: + - name: topic_num + - name: created + +- kind: Reply + properties: + - name: topic_num + - name: created + direction: desc + +- kind: Topic + properties: + - name: __key__ + direction: desc + +- kind: Topic + properties: + - name: don_totop + - name: last_touched + direction: desc + +- kind: Topic + properties: + - name: member + - name: created + +- kind: Topic + properties: + - name: member_num + - name: created + direction: desc + +- kind: Topic + properties: + - name: member_num + - name: node_name + - name: created + direction: desc + +- kind: Topic + properties: + - name: node + - name: created + +- kind: Topic + properties: + - name: node + - name: created + direction: desc + +- kind: Topic + properties: + - name: node_name + - name: created + direction: desc + +- kind: Topic + properties: + - name: node_num + - name: last_touched + direction: desc + +- kind: Topic + properties: + - name: sink + - name: last_touched + direction: desc + +- kind: TopicBookmark + properties: + - name: member + - name: created + direction: desc diff --git a/topic.py b/topic.py index ff1848d..8f8df9a 100644 --- a/topic.py +++ b/topic.py @@ -410,6 +410,7 @@ def get(self, topic_num): memcache.set('Topic_' + str(topic_num), topic, 86400) can_edit = False can_move = False + can_sink = False if topic: if topic.content: template_values['page_description'] = topic.content[:60] + ' - ' + topic.member.username @@ -421,6 +422,7 @@ def get(self, topic_num): can_edit = True can_move = True if topic.member_num == member.num: + can_sink = True now = datetime.datetime.now() if (now - topic.created).seconds < 300: can_edit = True @@ -443,6 +445,7 @@ def get(self, topic_num): template_values['topic'] = topic template_values['can_edit'] = can_edit template_values['can_move'] = can_move + template_values['can_sink'] = can_sink if (topic): node = False section = False @@ -1082,7 +1085,25 @@ def get(self, topic_num): memcache.delete('home_rendered') memcache.delete('home_rendered_mobile') self.redirect('/') - + +class TopicSinkHandler(webapp.RequestHandler): + def get(self, topic_num): + site = GetSite() + member = CheckAuth(self) + if member: + q = db.GqlQuery("SELECT * FROM Topic WHERE num = :1", int(topic_num)) + if q.count() == 1: + topic = q[0] + if member.num == topic.member_num: + topic.sink = 1 if topic.sink == 0 else 0 + topic.put() + memcache.delete('Topic_' + str(topic.num)) + #useless + memcache.delete('q_latest_16') + memcache.delete('home_rendered') + memcache.delete('home_rendered_mobile') + self.redirect('/t/' + str(topic_num)) + class TopicPlainTextHandler(webapp.RequestHandler): def get(self, topic_num): @@ -1235,6 +1256,7 @@ def main(): ('/t/([0-9]+).txt', TopicPlainTextHandler), ('/edit/topic/([0-9]+)', TopicEditHandler), ('/delete/topic/([0-9]+)', TopicDeleteHandler), + ('/sink/topic/([0-9]+)', TopicSinkHandler), ('/index/topic/([0-9]+)', TopicIndexHandler), ('/edit/reply/([0-9]+)', ReplyEditHandler), ('/hit/topic/(.*)', TopicHitHandler), From a95a9bb72a798f81481bc2b314bd680acbc78ae3 Mon Sep 17 00:00:00 2001 From: "ben304zhe@gmail.com" Date: Tue, 28 Feb 2012 14:58:32 +0800 Subject: [PATCH 2/6] add sink function --- tpl/desktop/topic.html | 2 +- v2ex/babel/__init__.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tpl/desktop/topic.html b/tpl/desktop/topic.html index 8fd92a3..2751216 100644 --- a/tpl/desktop/topic.html +++ b/tpl/desktop/topic.html @@ -43,7 +43,7 @@ {{ site.title }} {{ l10n.chevron }} {{ node.title|escape }}

{{ topic.title|escape }}

- {% if site.use_topic_types %}{% if topic.type %}{{ topic.type }}  {% endif %}{% endif %}By {{ topic.created_by }}{% if topic.source %} via {{ topic.source }}{% endif %} at {{ topic.created|timesince }} ago, {{ topic.hits }} hits{% ifequal member.level 0 %}   DELETE TIDY{% endifequal %}{% if can_move %} MOVE{% endif %}{% if can_edit %} EDIT{% endif %} + {% if site.use_topic_types %}{% if topic.type %}{{ topic.type }}  {% endif %}{% endif %}By {{ topic.created_by }}{% if topic.source %} via {{ topic.source }}{% endif %} at {{ topic.created|timesince }} ago, {{ topic.hits }} hits{% ifequal member.level 0 %}   DELETE TIDY{% endifequal %}{% if can_move %} MOVE{% endif %}{% if can_edit %} EDIT{% endif %}{% if can_sink %} {% if topic.sink %}UNSINK{% else %}SINK{% endif %}{% endif %} {% if topic.has_content %}
{{ topic.content_rendered }}
diff --git a/v2ex/babel/__init__.py b/v2ex/babel/__init__.py index 9d5512c..346eb4a 100644 --- a/v2ex/babel/__init__.py +++ b/v2ex/babel/__init__.py @@ -179,6 +179,7 @@ class Topic(db.Model): created = db.DateTimeProperty(auto_now_add=True) last_modified = db.DateTimeProperty(auto_now=True) last_touched = db.DateTimeProperty() + sink = db.IntegerProperty(default=0) class Reply(db.Model): num = db.IntegerProperty(indexed=True) From 1d99f88331b771edf265666d13eb2afa22de0247 Mon Sep 17 00:00:00 2001 From: "ben304zhe@gmail.com" Date: Tue, 28 Feb 2012 15:02:50 +0800 Subject: [PATCH 3/6] add sink function --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 8bbec9a..1d17418 100644 --- a/main.py +++ b/main.py @@ -127,7 +127,7 @@ def get(self): if (latest): template_values['latest'] = latest else: - q2 = db.GqlQuery("SELECT * FROM Topic ORDER BY last_touched DESC LIMIT 16") + q2 = db.GqlQuery("SELECT * FROM Topic WHERE sink = 0 ORDER BY last_touched DESC LIMIT 16") topics = [] for topic in q2: if topic.node_name not in ignored: @@ -146,7 +146,7 @@ def get(self): if (latest): template_values['latest'] = latest else: - q2 = db.GqlQuery("SELECT * FROM Topic ORDER BY last_touched DESC LIMIT 16") + q2 = db.GqlQuery("SELECT * FROM Topic WHERE sink = 0 ORDER BY last_touched DESC LIMIT 16") topics = [] for topic in q2: if topic.node_name not in ignored: From 34d7ceef89fa9c6b94736230756271cbdbcbc136 Mon Sep 17 00:00:00 2001 From: "ben304zhe@gmail.com" Date: Tue, 28 Feb 2012 15:06:19 +0800 Subject: [PATCH 4/6] add sink function --- app.yaml.example | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app.yaml.example b/app.yaml.example index a774b98..bf8da9b 100755 --- a/app.yaml.example +++ b/app.yaml.example @@ -58,6 +58,9 @@ handlers: - url: /delete/.* script: topic.py + +- url: /sink/.* + script: topic.py - url: /hit/.* script: topic.py From 0e640b3b2720c4f974decf7187e1c4aacfb7ff2f Mon Sep 17 00:00:00 2001 From: "ben304zhe@gmail.com" Date: Tue, 28 Feb 2012 17:27:35 +0800 Subject: [PATCH 5/6] add sink function to /recent --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 1d17418..2864683 100644 --- a/main.py +++ b/main.py @@ -279,7 +279,7 @@ def get(self): if (latest): template_values['latest'] = latest else: - q2 = db.GqlQuery("SELECT * FROM Topic ORDER BY last_touched DESC LIMIT 16,50") + q2 = db.GqlQuery("SELECT * FROM Topic WHERE sink = 0 ORDER BY last_touched DESC LIMIT 16,50") topics = [] IGNORED_RECENT = ['flamewar', 'pointless', 'in', 'autistic', 'chamber', 'flood', 'diary'] for topic in q2: From bc6d3906f7fcd345934172c0005310d96f803329 Mon Sep 17 00:00:00 2001 From: ben304 Date: Mon, 9 Apr 2012 11:58:49 +0800 Subject: [PATCH 6/6] Update v2ex/templatetags/filters.py --- v2ex/templatetags/filters.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/v2ex/templatetags/filters.py b/v2ex/templatetags/filters.py index 6e534d9..3bf2592 100644 --- a/v2ex/templatetags/filters.py +++ b/v2ex/templatetags/filters.py @@ -50,10 +50,7 @@ def autolink(text, trim_url_limit=None, nofollow=False): match = punctuation_re.match(word) if match: lead, middle, trail = match.groups() - if middle.startswith('www.') or ('@' not in middle and not middle.startswith('http://') and \ - len(middle) > 0 and middle[0] in string.letters + string.digits and \ - (middle.endswith('.org') or middle.endswith('.net') or middle.endswith('.com'))): - middle = '%s' % (middle, nofollow_attr, trim_url(middle)) + #Let guys without 'http://' go if middle.startswith('http://') or middle.startswith('https://'): middle = '%s' % (middle, nofollow_attr, trim_url(middle)) if '@' in middle and not middle.startswith('www.') and not ':' in middle \