本文整理汇总了Python中naaya.core.zope2util.ofs_path函数的典型用法代码示例。如果您正苦于以下问题:Python ofs_path函数的具体用法?Python ofs_path怎么用?Python ofs_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ofs_path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_userinfo
def get_userinfo(self, ob):
""" returns a list of objects based on the ob type"""
site = self.getSite()
cat = site.getCatalogTool()
user = self.REQUEST.AUTHENTICATED_USER.getId()
filters = {"contributor": user}
if ob == "events":
filters["meta_type"] = "Naaya Event"
ob_list = cat.search(filters)
elif ob == "news":
filters["meta_type"] = "Naaya News"
ob_list = cat.search(filters)
elif ob == "topics":
ob_list = cat.search({"path": ofs_path(site.topics), "contributor": user})
elif ob == "resources":
ob_list = cat.search({"path": ofs_path(site.resources), "contributor": user})
elif ob == "forums":
forum_meta_types = ["Naaya Forum Topic", "Naaya Forum Message"]
ob_list = cat.search({"meta_type": forum_meta_types, "contributor": user})
elif ob == "contacts":
ob_list = cat.search({"meta_type": "Naaya Contact", "contributor": user})
sorted_list = site.utSortObjsListByAttr(ob_list, "releasedate")
userinfo = [
[item.title, item.absolute_url, item.releasedate.strftime("%d %b '%y")] for item in sorted_list[:50]
]
return json.dumps(userinfo)
示例2: _update
def _update(self, portal):
context = portal.restrictedTraverse('who-who/destinet-users')
cat = portal['portal_catalog']
acl_users = portal['acl_users']
users = acl_users.getUsers()
auth_tool = portal.getAuthenticationTool()
#manager = self.request.AUTHENTICATED_USER.getUserName()
# first, cleanup wrongly created users
wrong = [o for o in context.objectValues()
if o._owner[1] == 'tibiadmin']
self.log.info("Deleting %s wrong contacts" % len(wrong))
for obj in wrong:
cat.uncatalog_object(ofs_path(obj))
context.manage_delObjects([o.id for o in wrong])
self.log.info("Migration: start migration of contacts for old users")
EmailTool.divert_mail()
counter = 0
for user in users:
fullname = auth_tool.getUserFullNameByID(user.name)
contacts = cat.searchResults(path=ofs_path(context),
contributor=user.name)
if not contacts:
counter += 1
id = uniqueId(
slugify(user.name or 'contact', removelist=[]),
lambda x: context._getOb(x, None) is not None)
ob = _create_NyContact_object(context, id, user.name)
ob.approveThis(1, user.name) # 1, manager
ob.submitThis()
ob.set_localpropvalue('title', 'en', fullname)
ob.set_localpropvalue('description', 'en', "")
#ob.release_date = DateTime()
new_user = user.__of__(acl_users)
ob.changeOwnership(user=new_user)
ob.giveEditRights()
context.recatalogNyObject(ob)
#crashes with unicodedecodeerror:
#notify(NyContentObjectAddEvent(ob, user.name, {}))
#log post date
auth_tool.changeLastPost(user.name)
self.log.info("Migration: %s - added contact for user: %s",
counter, id)
EmailTool.divert_mail(False)
self.log.info("Migration: end migration")
return True
开发者ID:eaudeweb,项目名称:naaya.destinet.extra,代码行数:60,代码来源:update_recreate_naaya_contact_for_old_users.py
示例3: get_userinfo
def get_userinfo(self, ob):
""" returns a list of objects based on the ob type"""
site = self.getSite()
cat = site.getCatalogTool()
user = self.REQUEST.AUTHENTICATED_USER.getId()
filters = {'contributor': user}
if ob == 'events':
filters['meta_type'] = 'Naaya Event'
ob_list = cat.search(filters)
elif ob == 'news':
filters['meta_type'] = 'Naaya News'
ob_list = cat.search(filters)
elif ob == 'topics':
ob_list = cat.search({'path': ofs_path(site.topics),
'contributor': user})
elif ob == 'resources':
ob_list = cat.search({'path': ofs_path(site.resources),
'contributor': user})
elif ob == 'forums':
forum_meta_types = ['Naaya Forum Topic', 'Naaya Forum Message']
ob_list = cat.search({'meta_type': forum_meta_types,
'contributor': user})
elif ob == 'contacts':
ob_list = cat.search({'meta_type': 'Naaya Contact',
'contributor': user})
sorted_list = site.utSortObjsListByAttr(ob_list, 'releasedate')
userinfo = [[item.title, item.absolute_url,
item.releasedate.strftime('%d %b \'%y')]
for item in sorted_list[:50]]
return json.dumps(userinfo)
示例4: handle_edit_content
def handle_edit_content(event):
"""
Test whether this requires adding pointers and perform the action
"""
obj = event.context
site = obj.getSite()
if not getattr(site, 'destinet.publisher', False):
return None
q_both = _qualifies_for_both(obj)
q_topics = _qualifies_for_topics_only(obj)
if q_topics or q_both:
# clean-up all existing pointers, then re-add them
cat = site.getCatalogTool()
pointers = cat.search({'meta_type': 'Naaya Pointer',
'path': [ofs_path(site.countries),
ofs_path(site.topics),
ofs_path(getattr(site, 'resources')),
# kept for pointers prior to v 1.1
ofs_path(getattr(site, 'who-who'))],
'pointer': path_in_site(obj)})
for brain in pointers:
pointer = brain.getObject()
pointer.aq_parent._delObject(pointer.id)
if q_both:
place_pointers(obj)
else:
place_pointers(obj, exclude=['target-groups'])
示例5: _send_newsletter
def _send_newsletter(self, notif_type, when_start, when_end):
"""
We'll look in the ``Products.Naaya.NySite.getActionLogger`` for object
creation/modification log entries. Then we'll send notifications for
the period between `when_start` and `when_end` using the
`notif_type` template.
"""
notif_logger.info('Notifications newsletter on site %r, type %r, '
'from %s to %s',
ofs_path(self.getSite()), notif_type,
when_start, when_end)
objects_by_email = {}
langs_by_email = {}
subscriptions_by_email = {}
anonymous_users = {}
for log_type, ob in utils.get_modified_objects(self.getSite(),
when_start, when_end):
notif_logger.info('.. modified object: %r', ofs_path(ob))
for subscription in utils.fetch_subscriptions(ob, inherit=True):
if subscription.notif_type != notif_type:
continue
if not subscription.check_permission(ob):
continue
email = subscription.get_email(ob)
if email is None:
continue
content_types = getattr(subscription, 'content_types', [])
if content_types and ob.meta_type not in content_types:
continue
notif_logger.info('.. .. sending newsletter to %r', email)
objects_by_email.setdefault(email, []).append({
'ob': ob,
'type': log_type,
})
langs_by_email[email] = subscription.lang
subscriptions_by_email[email] = subscription
anonymous_users[email] = isinstance(subscription,
AnonymousSubscription)
messages_by_email = {}
for email in objects_by_email:
messages_by_email[email] = {
'objs': objects_by_email[email],
'_lang': langs_by_email[email],
'subscription': subscriptions_by_email[email],
'here': self,
'anonymous': anonymous_users[email]
}
template = self._get_template(notif_type)
self._send_notifications(messages_by_email, template)
示例6: generate_news
def generate_news(obj_list):
news = []
for obj in obj_list:
if obj.istranslated(lang):
#Description tag
if mesg_type == 'html':
desc_elem = E.description(sanitize_xml_data(
obj.getLocalProperty('description', lang))
)
else:
desc_elem = E.description(sanitize_xml_data(
self.utStripAllHtmlTags(
obj.getLocalProperty('description', lang)
)
))
#News tag
try:
news.append(E.news(desc_elem, {
'title': sanitize_xml_data(
obj.getLocalProperty('title', lang)),
'source': sanitize_xml_data(
obj.getLocalProperty('source', lang)),
'source_link': sanitize_xml_data(obj.source_link),
'file_link': sanitize_xml_data(obj.file_link),
'url': sanitize_xml_data(obj.absolute_url(0)),
'lang': sanitize_xml_data(lang),
'isrtl': sanitize_xml_data(
str(self.is_arabic(lang))),
}))
except:
logger.exception("Failed to add %r to xml", ofs_path(obj))
raise
return tuple(news)
示例7: test_add_entry
def test_add_entry(self):
glossary = helpers.make_glossary(self.portal)
bucket = helpers.add_folder(glossary, '1', "Bucket")
bucket.manage_addGlossaryElement('2', "Water")
water = bucket['2']
self.assertEqual(search(glossary, path=ofs_path(water)), [water])
self.assertEqual(search(glossary, English="Water"), [water])
示例8: userinfo
def userinfo(self):
""" Renders a view with everything the member posted """
site = self.getSite()
auth_tool = site.getAuthenticationTool()
user = self.REQUEST.AUTHENTICATED_USER.getId()
cat = site.getCatalogTool()
user_obj = auth_tool.getUser(user)
contact_obj = None
if user_obj:
user_info = {'first_name': user_obj.firstname,
'last_name': user_obj.lastname,
'email': user_obj.email}
# --- since destinet.registration: --- #
container = site['who-who']['destinet-users']
candidate_brains = cat.search({'path': ofs_path(container),
'contributor': user})
for candidate_br in candidate_brains:
try:
candidate = candidate_br.getObject()
except Exception, e:
continue
else:
owner_tuple = candidate.getOwnerTuple()
if owner_tuple and owner_tuple[1] == user:
contact_obj = candidate
break
示例9: test_thread
def test_thread(self):
from time import sleep
from threading import Semaphore
from naaya.core.zope2util import ofs_path, launch_job
import transaction
job_done = Semaphore(0)
def threaded_job(context):
context.hello = "world"
transaction.commit()
job_done.release()
folder = self.portal['info']
launch_job(threaded_job, folder, ofs_path(folder))
transaction.commit()
for c in range(100):
if job_done.acquire(blocking=False):
break
sleep(0.1)
else:
self.fail("Waited 10 seconds and the job did not finish yet")
transaction.abort()
self.assertEqual(folder.hello, "world")
示例10: notify_comment_instant
def notify_comment_instant(self, comment, parent, user_id):
"""
send instant notifications because a comment was added to
object `ob` by the user `user_id`
"""
if not self.config['enable_instant']:
return
# Don't send notifications if the object is unapproved, but store them
# into a queue to send them later when it becomes approved
if not parent.approved:
return
auth_tool = self.getSite().getAuthenticationTool()
subscribers_data = utils.get_subscribers_data(self, parent, **{
'comment': comment,
'parent': parent,
'person': auth_tool.name_from_userid(user_id),
})
if len(subscribers_data.keys()) > 0:
notif_logger.info('Comment instant notifications on %r',
ofs_path(parent))
template = self._get_template('instant')
self._send_notifications(subscribers_data, template)
示例11: get_countries
def get_countries(ob):
"""
Extracts coverage from ob, iterates countries and returns
nyfolders of them in `countries` location (creates them if missing)
"""
ret = []
site = ob.getSite()
cat = site.getCatalogTool()
filters = {'title': '', 'path': ofs_path(site.countries),
'meta_type': 'Naaya Folder'}
coverage = list(set(getattr(ob, 'coverage', u'').strip(',').split(',')))
for country_item in coverage:
country = country_item.strip()
if country:
country_folders = []
filters['title'] = country
bz = cat.search(filters)
for brain in bz:
if brain.title.strip().lower() == country.lower():
country_folders.append(brain.getObject())
ret.extend(country_folders)
if not country_folders:
logger.info("Country '%s' not found in destinet countries",
country)
return ret
示例12: allowed
def allowed(context, permission=None):
"""
Roles that have `permission` and why.
Returns {PERM_NAME: {'Role': (REASON, META), ..}, ..}
where `REASON` in ('assigned', 'inherited').
`META` can be None or dict supplying extra info, like `source` of
permission inheritance.
"""
out = {}
all_roles = context.valid_roles()
permissions = context.ac_inherited_permissions(1)
if permission:
permissions = [x for x in permissions if x[0] == permission]
for perm in permissions:
name, value = perm[:2]
maps = out[name] = {}
perm = Permission(name, value, context)
roles = perm.getRoles(default=[])
for role in roles:
maps[role] = ('assigned', None)
if isinstance(roles, list):
for role in set(all_roles) - set(roles):
from_parent = allowed(context.aq_parent, name)
parent_permission = from_parent[name].get(role)
if parent_permission:
reason, meta = parent_permission
if reason == 'assigned':
maps[role] = ('inherited',
{'source': ofs_path(context.aq_parent)})
elif reason == 'inherited':
maps[role] = parent_permission
return out
示例13: xliff_header
def xliff_header(self, folders, language):
""" return the xliff header """
results = []
r_append = results.append #alias for append function. For optimization purposes
# Generate the XLIFF file header
if folders == '/':
folders='all'
else:
folders = string.split(folders, '/')[-1]
r_append('<?xml version="1.0" encoding="UTF-8"?>')
r_append('<!DOCTYPE xliff SYSTEM "http://www.oasis-open.org/committees/xliff/documents/xliff.dtd">')
r_append(u'<!-- XLIFF Format Copyright \xa9 OASIS Open 2001-2003 -->')
r_append('<xliff version="1.0">')
r_append('<file')
r_append(' original="%s"' % ofs_path(self))
r_append(' product-name="NaayaGlossary"')
r_append(' product-version="1.1.x"')
r_append(' datatype="plaintext"')
r_append(' source-language="English"')
r_append(' target-language="%s"' % language)
r_append(' date="%s"' % DateTime().HTML4())
r_append('>')
r_append('<body>')
return results
示例14: _processExtFile
def _processExtFile(self, mid, ctype):
""" Apply media converters to self subobject with given id (mid) which
is stored outside Data.fs, with original content-type ctype.
"""
from OFS.ObjectManager import ObjectManager
media = ObjectManager._getOb(self, mid)
launch_job(media2flv, self.aq_parent, ofs_path(media))
示例15: uncatalog_comments
def uncatalog_comments(obj):
catalog = obj.getSite().getCatalogTool()
container = obj._get_comments_container()
if container is not None:
for comment in container.objectValues(NyComment.meta_type):
try:
catalog.uncatalog_object(ofs_path(comment))
except:
obj.getSite().log_current_error()