Skip to content

Instantly share code, notes, and snippets.

@allenluce-zz
Created July 28, 2012 00:31
Show Gist options
  • Save allenluce-zz/3191199 to your computer and use it in GitHub Desktop.
Save allenluce-zz/3191199 to your computer and use it in GitHub Desktop.
Commit 07b0e595
commit 07b0e595d0c35bea2476a499161785cdc1204864
Author: Alex May <[email protected]>
Date: Wed Mar 28 14:54:01 2012 -0700
use context's topics, not contents
diff --git a/src/opencore/opencore/models/contentfeeds.py b/src/opencore/opencore/models/contentfeeds.py
index 51de399..4a71ee3 100644
--- a/src/opencore/opencore/models/contentfeeds.py
+++ b/src/opencore/opencore/models/contentfeeds.py
@@ -139,6 +139,7 @@ def _getInfo(profile, content, ifaces=None):
likes = len(getattr(content, 'likes', []))
if hasattr(content, 'get'):
comment_count = len(content.get('comments', ()))
+ topics = ()
else:
context_name = context.title
context_url = model_path(context)
@@ -147,6 +148,7 @@ def _getInfo(profile, content, ifaces=None):
likes = len(getattr(context, 'likes', []))
if hasattr(context, 'get'):
comment_count = len(context.get('comments', ()))
+ topics = list(get_topics(context))
tagger = find_tags(content)
if tagger is not None:
@@ -180,7 +182,7 @@ def _getInfo(profile, content, ifaces=None):
principals_allowed_by_permission(content, 'view'),
'comment_count': comment_count,
'tags': tags, #XXX
- 'topics': list(get_topics(content)), # sets aren't JSON serializable
+ 'topics': topics,
'author': profile.title,
'author_location': get_content_location(profile),
'author_location_display': getattr(profile, 'location', None),
diff --git a/src/openhcd/openhcd/evolve/zodb/__init__.py b/src/openhcd/openhcd/evolve/zodb/__init__.py
index c5943ae..87a61bf 100644
--- a/src/openhcd/openhcd/evolve/zodb/__init__.py
+++ b/src/openhcd/openhcd/evolve/zodb/__init__.py
@@ -1,2 +1,2 @@
-VERSION = 52
+VERSION = 53
NAME = 'openhcd'
diff --git a/src/openhcd/openhcd/evolve/zodb/evolve53.py b/src/openhcd/openhcd/evolve/zodb/evolve53.py
new file mode 100644
index 0000000..e308d89
--- /dev/null
+++ b/src/openhcd/openhcd/evolve/zodb/evolve53.py
@@ -0,0 +1,27 @@
+""" Reprocess events to use topics from context, not content """
+
+from repoze.bfg.traversal import find_model
+
+from opencore.views.utils import find_site
+
+from openhcd.views.utils import get_topics
+
+def evolve(context): #pragma NO COVERAGE
+ site = find_site(context)
+
+ types = ['Comment', 'CommentReply', 'Story', 'Answer']
+ ops = ['added']
+ events = list(site.events)
+ filtered_events = [e[2] for e in events if e[2]['content_type'] in types and e[2]['operation'] in ops]
+
+ for event in filtered_events:
+ context = None
+ try:
+ context = find_model(site, event.get('context_url'))
+ except:
+ pass
+ if not context:
+ next
+
+ event['topics'] = list(get_topics(context))
+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment