本文整理汇总了Python中assembl.models.Post.get方法的典型用法代码示例。如果您正苦于以下问题:Python Post.get方法的具体用法?Python Post.get怎么用?Python Post.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类assembl.models.Post
的用法示例。
在下文中一共展示了Post.get方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_mutation_add_extract_comment
# 需要导入模块: from assembl.models import Post [as 别名]
# 或者: from assembl.models.Post import get [as 别名]
def test_mutation_add_extract_comment(admin_user, graphql_request, idea_in_thread_phase, top_post_in_thread_phase, extract_post_1_to_subidea_1_1):
from graphene.relay import Node
raw_id = int(Node.from_global_id(top_post_in_thread_phase)[1])
from assembl.models import Post
post = Post.get(raw_id)
post.extracts.append(extract_post_1_to_subidea_1_1)
post.db.flush()
extract_id = extract_post_1_to_subidea_1_1.graphene_id()
idea_id = idea_in_thread_phase
res = schema.execute(u"""
mutation createPost {
createPost(
ideaId:"%s",
extractId:"%s",
subject:"Manger des choux à la crème",
body:"Je recommande de manger des choux à la crème, c'est très bon, et ça permet de maintenir l'industrie de la patisserie française."
) {
post {
... on Post {
parentExtractId
}
}
}
}
""" % (idea_id, extract_id), context_value=graphql_request)
assert res.data['createPost']['post']['parentExtractId'] == extract_id
示例2: get_posts
# 需要导入模块: from assembl.models import Post [as 别名]
# 或者: from assembl.models.Post import get [as 别名]
def get_posts(request):
"""
Query interface on posts
Filters have two forms:
only_*, is for filters that cannot be reversed (ex: only_synthesis)
is_*, is for filters that can be reversed (ex:is_unread=true returns only unread
order can be chronological, reverse_chronological
message, is_unread=false returns only read messages)
"""
localizer = request.localizer
discussion_id = int(request.matchdict['discussion_id'])
discussion = Discussion.get(int(discussion_id))
if not discussion:
raise HTTPNotFound(localizer.translate(
_("No discussion found with id=%s")) % discussion_id)
discussion.import_from_sources()
user_id = authenticated_userid(request) or Everyone
permissions = get_permissions(user_id, discussion_id)
DEFAULT_PAGE_SIZE = 25
page_size = DEFAULT_PAGE_SIZE
filter_names = [
filter_name for filter_name \
in request.GET.getone('filters').split(',') \
if filter_name
] if request.GET.get('filters') else []
try:
page = int(request.GET.getone('page'))
except (ValueError, KeyError):
page = 1
text_search = request.GET.get('text_search', None)
order = request.GET.get('order')
if order == None:
order = 'chronological'
assert order in ('chronological', 'reverse_chronological', 'score')
if order == 'score':
assert text_search is not None
if page < 1:
page = 1
root_post_id = request.GET.getall('root_post_id')
if root_post_id:
root_post_id = get_database_id("Post", root_post_id[0])
family_post_id = request.GET.getall('family_post_id')
if family_post_id:
family_post_id = get_database_id("Post", family_post_id[0])
root_idea_id = request.GET.getall('root_idea_id')
if root_idea_id:
root_idea_id = get_database_id("Idea", root_idea_id[0])
ids = request.GET.getall('ids[]')
if ids:
ids = [get_database_id("Post", id) for id in ids]
view_def = request.GET.get('view') or 'default'
only_synthesis = request.GET.get('only_synthesis')
post_author_id = request.GET.get('post_author')
if post_author_id:
post_author_id = get_database_id("AgentProfile", post_author_id)
assert AgentProfile.get(post_author_id), "Unable to find agent profile with id " + post_author_id
post_replies_to = request.GET.get('post_replies_to')
if post_replies_to:
post_replies_to = get_database_id("AgentProfile", post_replies_to)
assert AgentProfile.get(post_replies_to), "Unable to find agent profile with id " + post_replies_to
posted_after_date = request.GET.get('posted_after_date')
posted_before_date = request.GET.get('posted_before_date')
PostClass = SynthesisPost if only_synthesis == "true" else Post
ideaContentLinkQuery = discussion.db.query(
PostClass.id, PostClass.idea_content_links_above_post)
if order == 'score':
posts = discussion.db.query(PostClass, Content.body_text_index.score_name)
else:
posts = discussion.db.query(PostClass)
posts = posts.filter(
PostClass.discussion_id == discussion_id,
)
ideaContentLinkQuery = ideaContentLinkQuery.filter(
PostClass.discussion_id == discussion_id)
##no_of_posts_to_discussion = posts.count()
post_data = []
only_orphan = request.GET.get('only_orphan')
if only_orphan == "true":
if root_idea_id:
raise HTTPBadRequest(localizer.translate(
#.........这里部分代码省略.........
示例3: get_posts
# 需要导入模块: from assembl.models import Post [as 别名]
# 或者: from assembl.models.Post import get [as 别名]
def get_posts(request):
"""
Query interface on posts
Filters have two forms:
only_*, is for filters that cannot be reversed (ex: only_synthesis, only_orphan)
is_*, is for filters that can be reversed (ex:is_unread=true returns only unread message, is_unread=false returns only read messages)
order: can be chronological, reverse_chronological, popularity
root_post_id: all posts below the one specified.
family_post_id: all posts below the one specified, and all its ancestors.
post_reply_to: replies to a given post
root_idea_id: all posts associated with the given idea
ids: explicit message ids.
posted_after_date, posted_before_date: date selection (ISO format)
post_author: filter by author
classifier: filter on message_classifier, or absence thereof (classifier=null). Can be negated with "!"
"""
localizer = request.localizer
discussion_id = int(request.matchdict['discussion_id'])
discussion = Discussion.get(int(discussion_id))
if not discussion:
raise HTTPNotFound(localizer.translate(
_("No discussion found with id=%s")) % discussion_id)
discussion.import_from_sources()
user_id = request.authenticated_userid or Everyone
permissions = get_permissions(user_id, discussion_id)
DEFAULT_PAGE_SIZE = 25
page_size = DEFAULT_PAGE_SIZE
filter_names = [
filter_name for filter_name
in request.GET.getone('filters').split(',')
if filter_name
] if request.GET.get('filters') else []
try:
page = int(request.GET.getone('page'))
except (ValueError, KeyError):
page = 1
text_search = request.GET.get('text_search', None)
order = request.GET.get('order')
if order is None:
order = 'chronological'
assert order in ('chronological', 'reverse_chronological', 'score', 'popularity')
if order == 'score':
assert text_search is not None
if page < 1:
page = 1
root_post_id = request.GET.getall('root_post_id')
if root_post_id:
root_post_id = get_database_id("Post", root_post_id[0])
family_post_id = request.GET.getall('family_post_id')
if family_post_id:
family_post_id = get_database_id("Post", family_post_id[0])
root_idea_id = request.GET.getall('root_idea_id')
if root_idea_id:
root_idea_id = get_database_id("Idea", root_idea_id[0])
ids = request.GET.getall('ids[]')
if ids:
ids = [get_database_id("Post", id) for id in ids]
view_def = request.GET.get('view') or 'default'
only_synthesis = request.GET.get('only_synthesis')
post_author_id = request.GET.get('post_author')
if post_author_id:
post_author_id = get_database_id("AgentProfile", post_author_id)
assert AgentProfile.get(post_author_id), "Unable to find agent profile with id " + post_author_id
post_replies_to = request.GET.get('post_replies_to')
if post_replies_to:
post_replies_to = get_database_id("AgentProfile", post_replies_to)
assert AgentProfile.get(post_replies_to), "Unable to find agent profile with id " + post_replies_to
posted_after_date = request.GET.get('posted_after_date')
posted_before_date = request.GET.get('posted_before_date')
message_classifiers = request.GET.getall('classifier')
PostClass = SynthesisPost if only_synthesis == "true" else Post
if order == 'score':
posts = discussion.db.query(PostClass, Content.body_text_index.score_name)
else:
posts = discussion.db.query(PostClass)
posts = posts.filter(
PostClass.discussion_id == discussion_id,
).filter(PostClass.type != 'proposition_post')
##no_of_posts_to_discussion = posts.count()
post_data = []
#.........这里部分代码省略.........
示例4: get_posts
# 需要导入模块: from assembl.models import Post [as 别名]
# 或者: from assembl.models.Post import get [as 别名]
def get_posts(request):
"""
Query interface on posts
Filters have two forms:
only_*, is for filters that cannot be reversed (ex: only_synthesis)
is_*, is for filters that can be reversed (ex:is_unread=true returns only unread
order can be chronological, reverse_chronological
message, is_unread=false returns only read messages)
"""
localizer = get_localizer(request)
discussion_id = int(request.matchdict["discussion_id"])
discussion = Discussion.get(id=int(discussion_id))
if not discussion:
raise HTTPNotFound(localizer.translate(_("No discussion found with id=%s")) % discussion_id)
discussion.import_from_sources()
user_id = authenticated_userid(request)
DEFAULT_PAGE_SIZE = 25
page_size = DEFAULT_PAGE_SIZE
filter_names = (
[filter_name for filter_name in request.GET.getone("filters").split(",") if filter_name]
if request.GET.get("filters")
else []
)
try:
page = int(request.GET.getone("page"))
except (ValueError, KeyError):
page = 1
order = request.GET.get("order")
if order == None:
order = "chronological"
assert order in ("chronological", "reverse_chronological")
if page < 1:
page = 1
root_post_id = request.GET.getall("root_post_id")
if root_post_id:
root_post_id = get_database_id("Post", root_post_id[0])
root_idea_id = request.GET.getall("root_idea_id")
if root_idea_id:
root_idea_id = get_database_id("Idea", root_idea_id[0])
ids = request.GET.getall("ids")
if ids:
ids = [get_database_id("Post", id) for id in ids]
view_def = request.GET.get("view")
only_synthesis = request.GET.get("only_synthesis")
if only_synthesis == "true":
posts = Post.db.query(SynthesisPost)
else:
posts = Post.db.query(Post)
posts = posts.filter(Post.discussion_id == discussion_id)
##no_of_posts_to_discussion = posts.count()
post_data = []
only_orphan = request.GET.get("only_orphan")
if only_orphan == "true":
if root_idea_id:
raise HTTPBadRequest(localizer.translate(_("Getting orphan posts of a specific idea isn't supported.")))
posts = posts.filter(
Post.id.in_(
text(Idea._get_orphan_posts_statement(), bindparams=[bindparam("discussion_id", discussion_id)])
)
)
elif only_orphan == "false":
raise HTTPBadRequest(localizer.translate(_("Getting non-orphan posts isn't supported.")))
if root_idea_id:
posts = posts.filter(
Post.id.in_(
text(
Idea._get_related_posts_statement(),
bindparams=[bindparam("root_idea_id", root_idea_id), bindparam("discussion_id", discussion_id)],
)
)
)
if root_post_id:
root_post = Post.get(id=root_post_id)
posts = posts.filter(
(Post.ancestry.like(root_post.ancestry + cast(root_post.id, String) + ",%")) | (Post.id == root_post.id)
)
else:
root_post = None
if ids:
posts = posts.filter(Post.id.in_(ids))
#.........这里部分代码省略.........
示例5: get_posts
# 需要导入模块: from assembl.models import Post [as 别名]
# 或者: from assembl.models.Post import get [as 别名]
def get_posts(request):
discussion_id = int(request.matchdict['discussion_id'])
discussion = Discussion.get(id=int(discussion_id))
if not discussion:
raise HTTPNotFound(_("No discussion found with id=%s" % discussion_id))
discussion.import_from_sources()
user_id = authenticated_userid(request)
DEFAULT_PAGE_SIZE = 25
page_size = DEFAULT_PAGE_SIZE
filter_names = [
filter_name for filter_name \
in request.GET.getone('filters').split(',') \
if filter_name
] if request.GET.get('filters') else []
try:
page = int(request.GET.getone('page'))
except (ValueError, KeyError):
page = 1
if page < 1:
page = 1
root_post_id = request.GET.getall('root_post_id')
if root_post_id:
root_post_id = get_database_id("Post", root_post_id[0])
root_idea_id = request.GET.getall('root_idea_id')
if root_idea_id:
root_idea_id = get_database_id("Idea", root_idea_id[0])
ids = request.GET.getall('ids')
if ids:
ids = [get_database_id("Post", id) for id in ids]
view_def = request.GET.get('view')
#Rename "inbox" to "unread", the number of unread messages for the current user.
no_of_messages_viewed_by_user = Post.db.query(ViewPost).join(
Post,
Content,
Source
).filter(
Source.discussion_id == discussion_id,
Content.source_id == Source.id,
ViewPost.actor_id == user_id,
).count() if user_id else 0
posts = Post.db.query(Post).join(
Content,
Source,
).filter(
Source.discussion_id == discussion_id,
Content.source_id == Source.id,
)
no_of_posts_to_discussion = posts.count()
post_data = []
if root_idea_id:
if root_idea_id == Idea.ORPHAN_POSTS_IDEA_ID:
ideas_query = Post.db.query(Post) \
.filter(Post.id.in_(text(Idea._get_orphan_posts_statement(),
bindparams=[bindparam('discussion_id', discussion_id)]
)))
else:
ideas_query = Post.db.query(Post) \
.filter(Post.id.in_(text(Idea._get_related_posts_statement(),
bindparams=[bindparam('root_idea_id', root_idea_id)]
)))
posts = ideas_query.join(Content,
Source,
)
elif root_post_id:
root_post = Post.get(id=root_post_id)
posts = posts.filter(
(Post.ancestry.like(
root_post.ancestry + cast(root_post.id, String) + ',%'
))
|
(Post.id==root_post.id)
)
#Benoitg: For now, this completely garbles threading without intelligent
#handling of pagination. Disabling
#posts = posts.limit(page_size).offset(data['startIndex']-1)
elif ids:
posts = posts.filter(Post.id.in_(ids))
if user_id:
posts = posts.outerjoin(ViewPost,
and_(ViewPost.actor_id==user_id, ViewPost.post_id==Post.id)
)
posts = posts.add_entity(ViewPost)
posts = posts.options(contains_eager(Post.content, Content.source))
#.........这里部分代码省略.........
示例6: get_data
# 需要导入模块: from assembl.models import Post [as 别名]
# 或者: from assembl.models.Post import get [as 别名]
def get_data(content):
"""Return uid, dict of fields we want to index,
return None if we don't index."""
from assembl.models import Idea, Post, SynthesisPost, AgentProfile, LangString, Extract, Question
if type(content) == Idea: # only index Idea, not Thematic or Question
data = {}
for attr in ('creation_date', 'id', 'discussion_id'):
data[attr] = getattr(content, attr)
populate_from_langstring_prop(content, data, 'title')
populate_from_langstring_prop(content, data, 'synthesis_title')
populate_from_langstring_prop(content, data, 'description')
announcement = content.get_applicable_announcement()
if announcement:
populate_from_langstring_prop(announcement, data, 'title', 'announcement_title')
populate_from_langstring_prop(announcement, data, 'body', 'announcement_body')
phase = content.get_associated_phase()
if phase:
data['phase_id'] = phase.id
data['phase_identifier'] = phase.identifier
data['message_view_override'] = content.message_view_override
return get_uid(content), data
elif isinstance(content, AgentProfile):
data = {}
for attr in ('creation_date', 'id', 'name'):
data[attr] = getattr(content, attr, None)
# AgentProfile doesn't have creation_date, User does.
# get all discussions that the user is in via AgentStatusInDiscussion
data['discussion_id'] = set([s.discussion_id
for s in content.agent_status_in_discussion])
# get discussion_id for all posts of this agent
data['discussion_id'] = list(
data['discussion_id'].union(
[post.discussion_id for post in content.posts_created]
)
)
return get_uid(content), data
elif isinstance(content, Post):
data = {}
data['_parent'] = 'user:{}'.format(content.creator_id)
if content.parent_id is not None:
data['parent_creator_id'] = content.parent.creator_id
for attr in ('discussion_id', 'creation_date', 'id', 'parent_id',
'creator_id', 'sentiment_counts'):
data[attr] = getattr(content, attr)
data['creator_display_name'] = AgentProfile.get(content.creator_id).display_name()
data['sentiment_tags'] = [key for key in data['sentiment_counts']
if data['sentiment_counts'][key] > 0]
like = data['sentiment_counts']['like']
disagree = data['sentiment_counts']['disagree']
dont_understand = data['sentiment_counts']['dont_understand']
more_info = data['sentiment_counts']['more_info']
all_sentiments = [like, disagree, dont_understand, more_info]
data['sentiment_counts']['total'] = sum(all_sentiments)
data['sentiment_counts']['popularity'] = like - disagree
data['sentiment_counts']['consensus'] = max(all_sentiments) / ((sum(all_sentiments) / len(all_sentiments)) or 1)
data['sentiment_counts']['controversy'] = max(like, disagree, 1) / min(like or 1, disagree or 1)
data['type'] = content.type # this is the subtype (assembl_post, email...)
# data['publishes_synthesis_id'] = getattr(
# content, 'publishes_synthesis_id', None)
phase = content.get_created_phase()
if phase:
data['phase_id'] = phase.id
data['phase_identifier'] = phase.identifier
if isinstance(content, SynthesisPost):
populate_from_langstring_prop(content.publishes_synthesis,
data, 'subject')
populate_from_langstring_prop(content.publishes_synthesis,
data, 'introduction')
populate_from_langstring_prop(content.publishes_synthesis,
data, 'conclusion')
long_titles = [idea.synthesis_title for idea in content.publishes_synthesis.ideas
if idea.synthesis_title]
long_titles_c = defaultdict(list)
for ls in long_titles:
for e in ls.entries:
if e.value:
long_titles_c[strip_country(e.base_locale)].append(e.value)
ls = LangString()
for locale, values in long_titles_c.iteritems():
ls.add_value(' '.join(values), locale)
populate_from_langstring(ls, data, 'ideas')
else:
idea_id = get_idea_id_for_post(content)
if not idea_id:
return None, None
data['idea_id'] = idea_id
related_idea = Idea.get(idea_id[0])
data['message_view_override'] = related_idea.message_view_override
if isinstance(related_idea, Question):
related_idea = related_idea.parents[0]
#.........这里部分代码省略.........
示例7: get_posts
# 需要导入模块: from assembl.models import Post [as 别名]
# 或者: from assembl.models.Post import get [as 别名]
def get_posts(request):
"""
Query interface on posts
Filters have two forms:
only_*, is for filters that cannot be reversed (ex: only_synthesis)
is_*, is for filters that can be reversed (ex:is_unread=true returns only unread
order can be chronological, reverse_chronological
message, is_unread=false returns only read messages)
"""
localizer = request.localizer
discussion_id = int(request.matchdict['discussion_id'])
discussion = Discussion.get(int(discussion_id))
if not discussion:
raise HTTPNotFound(localizer.translate(
_("No discussion found with id=%s")) % discussion_id)
discussion.import_from_sources()
user_id = authenticated_userid(request)
permissions = get_permissions(user_id, discussion_id)
DEFAULT_PAGE_SIZE = 25
page_size = DEFAULT_PAGE_SIZE
filter_names = [
filter_name for filter_name \
in request.GET.getone('filters').split(',') \
if filter_name
] if request.GET.get('filters') else []
try:
page = int(request.GET.getone('page'))
except (ValueError, KeyError):
page = 1
order = request.GET.get('order')
if order == None:
order = 'chronological'
assert order in ('chronological', 'reverse_chronological')
if page < 1:
page = 1
root_post_id = request.GET.getall('root_post_id')
if root_post_id:
root_post_id = get_database_id("Post", root_post_id[0])
root_idea_id = request.GET.getall('root_idea_id')
if root_idea_id:
root_idea_id = get_database_id("Idea", root_idea_id[0])
ids = request.GET.getall('ids[]')
if ids:
ids = [get_database_id("Post", id) for id in ids]
view_def = request.GET.get('view') or 'default'
only_synthesis = request.GET.get('only_synthesis')
PostClass = SynthesisPost if only_synthesis == "true" else Post
posts = Post.db.query(PostClass)
posts = posts.filter(
PostClass.discussion_id == discussion_id,
)
##no_of_posts_to_discussion = posts.count()
post_data = []
only_orphan = request.GET.get('only_orphan')
if only_orphan == "true":
if root_idea_id:
raise HTTPBadRequest(localizer.translate(
_("Getting orphan posts of a specific idea isn't supported.")))
orphans = text(Idea._get_orphan_posts_statement(),
bindparams=[bindparam('discussion_id', discussion_id)]
).columns(column('post_id')).alias('orphans')
posts = posts.join(orphans, PostClass.id==orphans.c.post_id)
elif only_orphan == "false":
raise HTTPBadRequest(localizer.translate(
_("Getting non-orphan posts isn't supported.")))
if root_idea_id:
related = text(Idea._get_related_posts_statement(),
bindparams=[bindparam('root_idea_id', root_idea_id),
bindparam('discussion_id', discussion_id)]
).columns(column('post_id')).alias('related')
#Virtuoso bug: This should work...
#posts = posts.join(related, PostClass.id==related.c.post_id)
posts = posts.filter(PostClass.id.in_(related))
if root_post_id:
root_post = Post.get(root_post_id)
posts = posts.filter(
(Post.ancestry.like(
root_post.ancestry + cast(root_post.id, String) + ',%'
))
|
(PostClass.id==root_post.id)
)
#.........这里部分代码省略.........