本文整理汇总了Python中substanced.util.get_oid函数的典型用法代码示例。如果您正苦于以下问题:Python get_oid函数的具体用法?Python get_oid怎么用?Python get_oid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_oid函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _add_modal
def _add_modal(self, explanations, process, soup, tag, context, request):
context_oid = get_oid(context)
dace_ui_api = get_current_registry().getUtility(IDaceUIAPI,
'dace_ui_api')
explanationitemaction = None
explanationitem_actions = process.get_actions('explanationitem')
if explanationitem_actions:
explanationitemaction = explanationitem_actions[0]
if explanationitemaction:
values = {'url': request.resource_url(context, '@@explanationjson',
query={'op': 'getform',
'itemid': tag['data-item']}),
'item': explanations[tag['data-item']],
}
body = renderers.render(self.explanation_template, values, request)
explanation_item_soup = BeautifulSoup(body)
actionurl_update = dace_ui_api.updateaction_viewurl(
request=request,
action_uid=str(get_oid(explanationitemaction)),
context_uid=str(context_oid))
values = {'url': actionurl_update,
'item': explanations[tag['data-item']],
}
modal_body = renderers.render(self.modal_template, values, request)
explanation_item_modal_soup = BeautifulSoup(modal_body)
soup.body.append(explanation_item_modal_soup.body)
tag.append(explanation_item_soup.body)
tag.body.unwrap()
示例2: serialize_roles
def serialize_roles(roles, root=None):
result = []
principal_root = getSite()
if principal_root is None:
return []
if root is None:
root = principal_root
root_oid = str(get_oid(root, ''))
principal_root_oid = str(get_oid(principal_root, ''))
for role in roles:
if isinstance(role, tuple):
obj_oid = str(get_oid(role[1], ''))
result.append((role[0]+'_'+obj_oid).lower())
superiors = getattr(DACE_ROLES.get(role[0], _marker),
'all_superiors', [])
result.extend([(r.name+'_'+obj_oid).lower()
for r in superiors])
else:
result.append(role.lower()+'_'+root_oid)
superiors = getattr(DACE_ROLES.get(role, _marker),
'all_superiors', [])
result.extend([(r.name+'_'+root_oid).lower() for r in
superiors])
for superior in superiors:
if superior.name == 'Admin':
result.append('admin_'+principal_root_oid)
break
return list(set(result))
示例3: serialize
def serialize(self, field, cstruct, **kw):
if cstruct in (null, None):
cstruct = ()
is_multiple = getattr(self, 'multiple', False)
if is_multiple and not isinstance(cstruct, (list, tuple, set)):
cstruct = [cstruct]
if cstruct and is_multiple and \
not isinstance(list(cstruct)[0], string_types):
try:
cstruct = [str(get_oid(value)) for value in cstruct]
except Exception:
pass
elif isinstance(cstruct, string_types):
try:
cstruct = str(get_oid(cstruct))
except Exception:
pass
readonly = kw.get('readonly', self.readonly)
values = kw.get('values', self.values)
kw['values'] = _normalize_choices(values)
template = readonly and self.readonly_template or self.template
tmpl_values = self.get_template_values(field, cstruct, kw)
return field.renderer(template, **tmpl_values)
示例4: start
def start(self, context, request, appstruct, **kw):
appstruct.pop('_csrf_token_')
user = request.user
appstruct['user'] = 'Anonymous'
if user:
appstruct['user'] = get_oid(user)
now = datetime.datetime.now(tz=pytz.timezone('Europe/Paris'))
appstruct['date'] = now.isoformat()
site = get_site_folder(True, request)
appstruct['site'] = get_oid(site)
alert('arango', [], ["lac."+appstruct['id']], appstruct)
#alert slack
appstruct['date'] = to_localized_time(
now, translate=True)
text = 'Aimez-vous la nouvelle version: {new_version}\n '
if appstruct['new_version'] == 'False':
text += 'Pourquoi non: {explanation}\n '
text += 'Aimeriez-vous une application mobile: {mobile_application}\n \n User: {user}\n Email: {email}\n Date: {date}'
text = text.format(**appstruct)
alert('slack', [], ['questionnaire'], {'text': text})
if user and not getattr(user, 'email', ''):
user.email = appstruct.get('email', '')
return {}
示例5: clean_reviews
def clean_reviews(root, registry):
import json
from substanced.util import get_oid
from dace.util import find_catalog
wapis = [s for s in root.site_folders if s.title == 'Sortir Wapi']
lilles = [s for s in root.site_folders if s.title == 'Sortir Lille']
wapi_site = wapis[0]
wapi_site_oid = get_oid(wapi_site)
lille_site = lilles[0]
lille_site_oid = get_oid(lille_site)
with open('critiques.json') as data_file:
entities = json.load(data_file)
entities_with_ids = [entity for entity in entities
if entity.get('source_data', {}).get('id', None)]
ids = {str(entity['source_data']['id'] + '_' + entity['source_data']['source_id']): entity
for entity in entities_with_ids}
lac_catalog = find_catalog('lac')
object_id_index = lac_catalog['object_id']
reviews = object_id_index.any(list(ids.keys())).execute()
len_entities = str(len(reviews))
for index, review in enumerate(reviews):
reviwe_site = getattr(review, 'source_data', {}).get('site', None)
if reviwe_site != 'wapi':
review.access_control = PersistentList(
[wapi_site_oid, lille_site_oid])
review.reindex()
log.info("Wapi-Lille: "+str(index) + "/" + len_entities)
else:
log.info("Wapi: "+str(index) + "/" + len_entities)
log.info('Clean review evolved.')
示例6: get_roles
def get_roles(user=None, obj=None,
root=None, ignore_groups=False):
if user is None:
user = get_current()
if isinstance(user, Anonymous):
return [RoleAnonymous.name]
if root is None:
root = getSite()
if obj is None:
obj = root
opts = {u'source_id': get_oid(user),
u'target_id': get_oid(obj)}
opts[u'reftype'] = 'Role'
roles = [r.relation_id for r in find_relations(obj, opts).all()]
principals = find_service('principals')
sd_admin = principals['users']['admin']
if sd_admin is user and 'Admin' not in roles:
roles.append('Admin')
groups = []
if not ignore_groups:
groups.extend(getattr(user, 'user_groups', []))
for group in groups:
roles.extend(get_roles(group, obj, root))
return list(set(roles))
示例7: update
def update(self):
result = {}
duplicates = get_duplicates(self.context)
diff_bodies = {}
context_view = self.content(
args={'object': self.context},
template=self.context.templates.get('diff', None))['body']
for duplicate in duplicates:
duplicate_view = self.content(
args={'object': duplicate},
template=duplicate.templates.get('diff', None))['body']
soupt, textdiff = html_diff_wrapper.render_html_diff(
context_view, duplicate_view)
diff_bodies[duplicate] = (textdiff, get_oid(duplicate))
values = {'context': self.context,
'oid': get_oid(self.context),
'context_view': context_view,
'contents': diff_bodies,
'view': self}
body = self.content(args=values, template=self.template)['body']
item = self.adapt_item(body, self.viewid)
result['coordinates'] = {self.coordinates: [item]}
return result
示例8: get_access_keys
def get_access_keys(user, root=None, to_exclude=[]):
if isinstance(user, Anonymous):
return ['anonymous']
principals = find_service('principals')
sd_admin = principals['users']['admin']
pricipal_root = getSite()
if root is None:
root = pricipal_root
root_oid = get_oid(root)
principal_root_oid = get_oid(pricipal_root)
if sd_admin is user:
return list(set([('admin'+'_'+str(root_oid)).lower(),
('admin'+'_'+str(principal_root_oid)).lower()]))
groups = list(getattr(user, 'user_groups', []))
groups.append(user)
relations = []
for group in groups:
opts = {u'source_id': get_oid(group)}
opts[u'reftype'] = 'Role'
relations.extend(list(find_relations(group, opts).all()))
result = [(t.relation_id+'_'+str(t.target_id)).lower() \
for t in relations if t.target_id not in to_exclude]
for relation in relations:
if relation.relation_id == 'Admin':
result.append(('admin'+'_'+str(principal_root_oid)).lower())
break
return list(set(result))
示例9: bind
def bind(self):
bindings = {}
user = get_current(self.request)
dace_catalog = find_catalog('dace')
novaideo_catalog = find_catalog('novaideo')
object_authors_index = novaideo_catalog['object_authors']
container_index = dace_catalog['container_oid']
query = container_index.eq(get_oid(self.context))
objects = find_entities(
interfaces=[IAmendment],
user=user,
add_query=query)
query = query & object_authors_index.any([get_oid(user)])
my_objs = find_entities(
interfaces=[IAmendment],
user=user,
add_query=query)
len_result = len(objects)
len_my = len(my_objs)
len_others = len_result - len_my
bindings['user'] = user
bindings['len_result'] = len_result
bindings['len_my'] = len_my
bindings['len_others'] = len_others
setattr(self, '_bindings', bindings)
示例10: _get_query
def _get_query(self, user):
dace_catalog = find_catalog('dace')
novaideo_catalog = find_catalog('novaideo')
object_authors_index = novaideo_catalog['object_authors']
container_index = dace_catalog['container_oid']
return container_index.eq(get_oid(self.context)) & \
object_authors_index.notany([get_oid(user)])
示例11: content_added_or_removed
def content_added_or_removed(event):
""" Generates ContentAdded and ContentRemoved audit events """
if IObjectWillBeRemoved.providedBy(event):
event_name = 'ContentRemoved'
elif IObjectAdded.providedBy(event):
event_name = 'ContentAdded'
else:
return False # for testing
userinfo = get_userinfo()
eventscribe = AuditScribe(event.object)
parent = event.parent
# this is an event related to the *container*, not to the object.
folder_oid = get_oid(parent, None)
object_oid = get_oid(event.object, None)
folder_path = resource_path(parent)
object_name = event.name
moving = bool(event.moving)
loading = bool(event.loading)
content_type = str(event.registry.content.typeof(event.object))
eventscribe.add(
event_name,
folder_oid,
object_oid=object_oid,
folder_oid=folder_oid,
folder_path=folder_path,
object_name=object_name,
content_type=content_type,
userinfo=userinfo,
moving=moving,
loading=loading,
)
示例12: reviwes_access_control_evolve
def reviwes_access_control_evolve(root, registry):
from lac.views.filter import find_entities
from lac.content.interface import IBaseReview
from substanced.util import get_oid
reviews = find_entities(interfaces=[IBaseReview])
len_entities = str(len(reviews))
wapis = [s for s in root.site_folders if s.title == 'Sortir Wapi']
lilles = [s for s in root.site_folders if s.title == 'Sortir Lille']
wapi_site = wapis[0]
wapi_site_oid = get_oid(wapi_site)
lille_site = lilles[0]
lille_site_oid = get_oid(lille_site)
for index, review in enumerate(reviews):
reviwe_site = getattr(review, 'source_data', {}).get('site', None)
reviwe_siteid = getattr(review, 'source_data', {}).get('source_id', None)
if reviwe_site == 'wapi':
review.source_site = wapi_site_oid
review.access_control = PersistentList([wapi_site_oid])
log.info("Wapi: "+str(index) + "/" + len_entities)
elif reviwe_siteid == 'sortir':
review.source_site = lille_site_oid
review.access_control = PersistentList([lille_site_oid])
#log.info("Lille: "+str(index) + "/" + len_entities)
else:
source_site = review.source_site if review.source_site else 'all'
review.access_control = PersistentList([source_site])
#log.info("CrerationCulturelle: "+str(index) + "/" + len_entities)
review.reindex()
log.info('Review access_control evolved.')
示例13: calculate_votes
def calculate_votes(self, votes):
"""Return the result of ballot"""
result = {}
for subject in self.report.subjects:
try:
subject_id = get_oid(subject)
except Exception:
subject_id = subject
result[subject_id] = 0
for vote in votes:
subject = get_obj(vote.value)
if subject is None:
subject = vote.value
try:
subject_id = get_oid(vote.value)
except Exception:
subject_id = vote.value
if subject in self.report.subjects:
result[subject_id] += 1
return result
示例14: test_disconnect_relation
def test_disconnect_relation(self):
before = len(get_relations_container(self.app))
source, target, relation = self._create_relation()
self.assertEqual(len(get_relations_container(source)), before + 1)
results = find_relations(source, {'target_id': get_oid(target)})
before = len(get_relations_container(self.app))
disconnect(relation)
self.assertEqual(len(get_relations_container(source)), before - 1)
results = find_relations(source, {'target_id': get_oid(target)})
self.assertEqual(len(list(results)), 0)
示例15: test_remove_target
def test_remove_target(self):
before = len(get_relations_container(self.app))
source, target, relation = self._create_relation()
self.assertEqual(len(get_relations_container(source)), before + 1)
results = find_relations(source, {'target_id': get_oid(target)})
self.assertEqual(len(list(results)), 1)
before = len(get_relations_container(self.app))
del target.__parent__[target.__name__]
self.assertEqual(len(get_relations_container(source)), before - 1)
results = find_relations(source, {'target_id': get_oid(target)})
self.assertEqual(len(list(results)), 0)