本文整理汇总了Python中assembl.models.Discussion.get方法的典型用法代码示例。如果您正苦于以下问题:Python Discussion.get方法的具体用法?Python Discussion.get怎么用?Python Discussion.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类assembl.models.Discussion
的用法示例。
在下文中一共展示了Discussion.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: discussion_as_graph
# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get [as 别名]
def discussion_as_graph(self, discussion_id):
from assembl.models import Discussion, AgentProfile
local_uri = self.local_uri()
discussion = Discussion.get(discussion_id)
d_storage_name = self.discussion_storage_name()
d_graph_iri = URIRef(self.discussion_graph_iri())
v = get_virtuoso(self.session, d_storage_name)
discussion_uri = URIRef(
Discussion.uri_generic(discussion_id, local_uri))
subjects = [s for (s,) in v.query(
"""SELECT DISTINCT ?s WHERE {
?s assembl:in_conversation %s }""" % (discussion_uri.n3()))]
subjects.append(discussion_uri)
participant_ids = list(discussion.get_participants(True))
profiles = {URIRef(AgentProfile.uri_generic(id, local_uri))
for id in participant_ids}
subjects.extend(profiles)
# add pseudo-accounts
subjects.extend((URIRef("%sAgentAccount/%d" % (local_uri, id))
for id in participant_ids))
# print len(subjects)
cg = ConjunctiveGraph(identifier=d_graph_iri)
self.add_subject_data(v, cg, subjects)
# add relationships of non-pseudo accounts
for ((account, p, profile), g) in v.triples((None, SIOC.account_of, None)):
if profile in profiles:
cg.add((account, SIOC.account_of, profile, g))
# Tempting: simplify with this.
# cg.add((profile, FOAF.account, account, g))
for (s, o, g) in v.query(
'''SELECT ?s ?o ?g WHERE {
GRAPH ?g {?s catalyst:expressesIdea ?o } .
?o assembl:in_conversation %s }''' % (discussion_uri.n3())):
cg.add((s, CATALYST.expressesIdea, o, g))
return cg
示例2: delete_discussion
# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get [as 别名]
def delete_discussion(session, discussion_id):
from assembl.models import Discussion, DiscussionBoundBase
# First, delete the discussion.
session.delete(Discussion.get(discussion_id))
session.flush()
# See if anything is left...
classes = DiscussionBoundBase._decl_class_registry.itervalues()
classes_by_table = {
cls.__dict__.get('__table__', None): cls for cls in classes}
# Only direct subclass of abstract
concrete_classes = set(filter(lambda cls:
issubclass(cls, DiscussionBoundBase) and (not isabstract(cls))
and isabstract(cls.mro()[1]),
classes_by_table.values()))
tables = DiscussionBoundBase.metadata.sorted_tables
tables.reverse()
for table in tables:
if table not in classes_by_table:
continue
cls = classes_by_table[table]
if cls not in concrete_classes:
continue
print 'deleting', cls.__name__
query = session.query(cls.id)
conds = cls.get_discussion_conditions(discussion_id)
assert conds
cond = and_(*conds)
v = JoinColumnsVisitor(cls, query, classes_by_table)
v.traverse(cond)
query = v.final_query().filter(cond)
if query.count():
print "*" * 20, "Not all deleted!"
session.query(cls).filter(
cls.id.in_(query.subquery())).delete(False)
示例3: get_ideas
# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get [as 别名]
def get_ideas(request):
discussion_id = request.matchdict['discussion_id']
discussion = Discussion.get(id=int(discussion_id))
if not discussion:
raise HTTPNotFound("Discussion with id '%s' not found." % discussion_id)
view_def = request.GET.get('view')
ids = request.GET.getall('ids')
return _get_ideas_real(discussion=discussion, view_def=view_def, ids=ids)
示例4: get_agents
# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get [as 别名]
def get_agents(request, discussion_only=False):
discussion_id = int(request.matchdict['discussion_id'])
discussion = Discussion.get(int(discussion_id))
if not discussion:
raise HTTPNotFound("Discussion with id '%s' not found." % discussion_id)
view_def = request.GET.get('view')
return _get_agents_real(
discussion, authenticated_userid(request), view_def)
示例5: get_ideas
# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get [as 别名]
def get_ideas(request):
user_id = authenticated_userid(request) or Everyone
discussion_id = int(request.matchdict["discussion_id"])
discussion = Discussion.get(int(discussion_id))
if not discussion:
raise HTTPNotFound("Discussion with id '%s' not found." % discussion_id)
view_def = request.GET.get("view")
ids = request.GET.getall("ids")
return _get_ideas_real(discussion=discussion, view_def=view_def, ids=ids, user_id=user_id)
示例6: add_local_role
# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get [as 别名]
def add_local_role(request):
# Do not use check_permissions, this is a special case
ctx = request.context
user_id = request.authenticated_userid
if not user_id:
raise HTTPUnauthorized()
discussion_id = ctx.get_discussion_id()
discussion = Discussion.get(discussion_id)
user_uri = User.uri_generic(user_id)
if discussion_id is None:
raise HTTPBadRequest()
permissions = get_permissions(user_id, discussion_id)
json = request.json_body
if "discussion" not in json:
json["discussion"] = Discussion.uri_generic(discussion_id)
requested_user = json.get('user', None)
if not requested_user:
json['user'] = requested_user = user_uri
elif requested_user != user_uri and P_ADMIN_DISC not in permissions:
raise HTTPUnauthorized()
if P_ADMIN_DISC not in permissions:
if P_SELF_REGISTER in permissions:
json['requested'] = False
json['role'] = R_PARTICIPANT
req_user = User.get_instance(requested_user)
if not discussion.check_authorized_email(req_user):
raise HTTPForbidden()
elif P_SELF_REGISTER_REQUEST in permissions:
json['requested'] = True
else:
raise HTTPUnauthorized()
try:
instances = ctx.create_object("LocalUserRole", json, user_id)
except HTTPClientError as e:
raise e
except Exception as e:
raise HTTPBadRequest(e)
if instances:
first = instances[0]
db = first.db
for instance in instances:
db.add(instance)
db.flush()
# Side effect: materialize subscriptions.
if not first.requested:
# relationship may not be initialized
user = first.user or User.get(first.user_id)
user.get_notification_subscriptions(discussion_id, True)
# Update the user's AgentStatusInDiscussion
user.update_agent_status_subscribe(discussion)
view = request.GET.get('view', None) or 'default'
permissions = get_permissions(
user_id, ctx.get_discussion_id())
return CreationResponse(first, user_id, permissions, view)
示例7: __acl__
# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get [as 别名]
def __acl__(self):
if getattr(self._instance, '__acl__', None):
return self._instance.__acl__
if getattr(self._instance, 'discussion', None):
return self._instance.discussion.__acl__
discussion_id = self.get_discussion_id()
if discussion_id:
from assembl.models import Discussion
return Discussion.get(discussion_id).__acl__
return self.__parent__.__acl__
示例8: get_extracts
# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get [as 别名]
def get_extracts(request):
discussion_id = int(request.matchdict['discussion_id'])
discussion = Discussion.get(int(discussion_id))
if not discussion:
raise HTTPNotFound(
"Discussion with id '%s' not found." % discussion_id)
view_def = request.GET.get('view')
ids = request.GET.getall('ids')
return _get_extracts_real(
discussion, view_def, ids, authenticated_userid(request))
示例9: get_syntheses
# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get [as 别名]
def get_syntheses(request):
discussion_id = int(request.matchdict['discussion_id'])
discussion = Discussion.get(int(discussion_id))
if not discussion:
raise HTTPNotFound("Discussion with id '%s' not found." % discussion_id)
user_id = authenticated_userid(request) or Everyone
permissions = get_permissions(user_id, discussion_id)
syntheses = discussion.get_all_syntheses()
view_def = request.GET.get('view') or 'default'
res = [synthesis.generic_json(view_def, user_id, permissions)
for synthesis in syntheses]
return [x for x in res if x is not None]
示例10: get_discussion_semantic_analysis
# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get [as 别名]
def get_discussion_semantic_analysis(
discussion_id, num_topics=200,
model_cls=gmodels.lsimodel.LsiModel, **model_kwargs):
discussion = Discussion.get(discussion_id)
lang = discussion.discussion_locales[0].split('_')[0]
dirname = join(nlp_data, lang)
dict_fname = join(dirname, DICTIONARY_FNAME)
# rebuild dico in all cases to ensure complete corpus
corpus = create_dictionaries(discussion_id)
dictionary = corpora.Dictionary.load(dict_fname)
post_ids = discussion.db.query(Content.id).filter_by(
discussion_id=discussion_id)
doc_count = post_ids.count()
if doc_count < 10:
return None, None
post_ids = [x for (x,) in post_ids]
subcorpus = corpus[post_ids]
tfidf_model = gmodels.TfidfModel(id2word=dictionary)
tfidf_fname = join(dirname, "tfidf_%d.model" % (discussion_id,))
model_fname = join(dirname, "model_%s_%d.model" % (
model_cls.__name__, discussion_id,))
gensim_model = model_cls(
id2word=dictionary, num_topics=num_topics, **model_kwargs)
if exists(tfidf_fname):
tfidf_model = tfidf_model.load(tfidf_fname)
# assumption: count implies identity.
# Wrong in corner cases: hidden, etc.
if tfidf_model.num_docs == doc_count:
if exists(model_fname):
gensim_model = gensim_model.load(model_fname)
same_kwargs = all((
getattr(gensim_model, k) == v
for (k, v) in model_kwargs.iteritems()))
same_kwargs = same_kwargs and getattr(
gensim_model, 'num_updates', doc_count) == doc_count
if same_kwargs and gensim_model.num_topics == num_topics:
return (subcorpus, tfidf_model, gensim_model)
elif exists(tfidf_fname):
unlink(tfidf_fname)
if exists(model_fname):
unlink(model_fname)
if tfidf_model.num_docs != doc_count:
tfidf_model.initialize(subcorpus)
tfidf_model.save(tfidf_fname)
tfidf_corpus = tfidf_model[subcorpus]
if getattr(gensim_model, 'update', None):
gensim_model.update(tfidf_corpus)
elif getattr(gensim_model, 'add_documents', None):
gensim_model.add_documents(tfidf_corpus)
gensim_model.save(model_fname)
return (subcorpus, tfidf_model, gensim_model)
示例11: maybe_contextual_route
# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get [as 别名]
def maybe_contextual_route(request, route_name, **args):
discussion_slug = request.matchdict.get('discussion_slug', None)
if discussion_slug is None:
discussion_id = request.matchdict.get('discussion_id', None)
if discussion_id is None:
return request.route_url(route_name, **args)
else:
discussion = Discussion.get(int(discussion_id))
return request.route_url(
'contextual_'+route_name,
discussion_slug=discussion.slug, **args)
else:
return request.route_url(
'contextual_'+route_name, discussion_slug=discussion_slug, **args)
示例12: add_multiple_users_csv
# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get [as 别名]
def add_multiple_users_csv(
request, csv_file, discussion_id, with_role,
send_password_change=False, message_subject=None,
text_message=None, html_message=None):
r = reader(csv_file)
localizer = request.localizer
for i, l in enumerate(r):
if not len(l):
# tolerate empty lines
continue
l = [x.decode('utf-8').strip() for x in l]
if send_password_change:
if len(l) != 2:
raise RuntimeError(localizer.translate(_(
"The CSV file must have two columns")))
(name, email) = l
password = base64.urlsafe_b64encode(urandom(8))
else:
if len(l) != 3:
raise RuntimeError(localizer.translate(_(
"The CSV file must have three columns")))
(name, email, password) = l
if not is_email(email):
if i == 0:
# Header
continue
raise RuntimeError(localizer.translate(_(
"Not an email: <%s> at line %d")) % (email, i))
if len(name) < 5:
raise RuntimeError(localizer.translate(_(
"Name too short: <%s> at line %d")) % (name, i))
if len(password) < 4:
raise RuntimeError(localizer.translate(_(
"Password too short: <%s> at line %d")) % (password, i))
(user, is_new) = add_user(
name, email, password, None, True, localrole=with_role,
discussion=discussion_id, change_old_password=False)
if is_new and send_password_change:
from assembl.views.auth.views import send_change_password_email
from assembl.models import Discussion
discussion = Discussion.get(discussion_id)
send_change_password_email(
request, user, email, subject=message_subject,
text_body=text_message, html_body=html_message,
discussion=discussion)
return i
示例13: participants_private_as_graph
# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get [as 别名]
def participants_private_as_graph(self, discussion_id):
from assembl.models import Discussion, AgentProfile
local_uri = self.local_uri()
discussion = Discussion.get(discussion_id)
d_storage_name = self.private_user_storage.name
d_graph_iri = self.private_user_storage.sections[0].graph_iri
cg = ConjunctiveGraph(identifier=d_graph_iri)
v = get_virtuoso(self.session, d_storage_name)
v_main = get_virtuoso(self.session, self.discussion_storage_name())
participant_ids = discussion.get_participants(True)
profiles={URIRef(AgentProfile.uri_generic(id, local_uri))
for id in participant_ids}
self.add_subject_data(v, cg, profiles)
accounts = [account for ((account, p, profile), g)
in v_main.triples((None, SIOC.account_of, None))
if profile in profiles]
self.add_subject_data(v, cg, accounts)
return cg
示例14: add_multiple_users_csv
# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get [as 别名]
def add_multiple_users_csv(
request, csv_file, discussion_id, with_role,
send_password_change=False, message_subject=None,
text_message=None, html_message=None, sender_name=None,
resend_if_not_logged_in=False):
r = reader(csv_file, skipinitialspace=True)
localizer = request.localizer
for i, row in enumerate(r):
if not len(row):
# tolerate empty lines
continue
row = [x.decode('utf-8').strip() for x in row]
if len(row) != 2:
raise RuntimeError(localizer.translate(_(
"The CSV file must have two columns")))
(name, email) = row
if not is_email(email):
if i == 0:
# Header
continue
raise RuntimeError(localizer.translate(_(
"Not an email: <%s> at line %d")) % (email, i))
if len(name) < 5:
raise RuntimeError(localizer.translate(_(
"Name too short: <%s> at line %d")) % (name, i))
(user, created_user, created_localrole) = add_user(
name, email, None, None, True, localrole=with_role,
discussion=discussion_id, change_old_password=False)
status_in_discussion = None
if send_password_change and not (created_user or created_localrole):
status_in_discussion = user.get_status_in_discussion(discussion_id)
if send_password_change and (
created_user or created_localrole or (
resend_if_not_logged_in and (
status_in_discussion is None or
not status_in_discussion.first_visit))):
from assembl.views.auth.views import send_change_password_email
from assembl.models import Discussion
discussion = Discussion.get(discussion_id)
send_change_password_email(
request, user, email, subject=message_subject,
text_body=text_message, html_body=html_message,
discussion=discussion, sender_name=sender_name, welcome=True)
return i
示例15: interesting_ideas
# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get [as 别名]
def interesting_ideas(request):
from .discussion import get_analytics_alerts
ctx = request.context
target = request.context._instance
user_id = authenticated_userid(request) or Everyone
discussion_id = ctx.get_discussion_id()
permissions = get_permissions(
user_id, discussion_id)
if P_READ not in permissions:
raise HTTPUnauthorized()
if user_id != target.id and P_ADMIN_DISC not in permissions:
raise HTTPUnauthorized()
discussion = Discussion.get(discussion_id)
if not discussion:
raise HTTPNotFound()
result = get_analytics_alerts(
discussion, target.id,
["interesting_to_me"], False)
result = loads(result)['responses'][0]['data'][0]['suggestions']
result = {x['targetID']: x['arguments']['score'] for x in result}
return result