def _send_newsletter(self, notif_type, when_start, when_end): """ Send notifications for the period between `when_start` and `when_end` using the `notif_type` template """ objects_by_user = {} langs_by_user = {} for ob in self._list_modified_objects(when_start, when_end): ob_path = relative_object_path(ob, self._get_site()) for subscription in self.list_subscriptions(notif_type=notif_type): if not is_subpath(ob_path, subscription.location): continue if not self._has_view_permission(subscription.user_id, ob): continue msgs_for_user = objects_by_user.setdefault(subscription.user_id, []) msgs_for_user.append({'ob': ob}) langs_by_user[subscription.user_id] = subscription.lang messages_by_user = {} for user_id in objects_by_user: messages_by_user[user_id] = { 'objs': objects_by_user[user_id], '_lang': langs_by_user[user_id], } template = self._get_template(notif_type) self._send_notifications(messages_by_user, template)
def admin_add_subscription(self, user_id, location, notif_type, lang, REQUEST): """ """ if location == '__root': location = '' ob = self.getSite().unrestrictedTraverse(location) location = relative_object_path(ob, self.getSite()) try: self.add_subscription(user_id, location, notif_type, lang) except ValueError, msg: self.setSessionErrors(msg)
def add_roles_from_ob(ob): try: ob_roles = ob.acl_satellite.getAllLocalRoles() except AttributeError: return # looks like we found a broken object for group_id, group_roles in ob_roles.iteritems(): all_group_roles = groups_roles_map.setdefault(group_id, []) for role in group_roles: location = { 'ob': ob, 'path': relative_object_path(ob, site), 'is_site': ob == site, } all_group_roles.append( (role, location) )
def notify_instant(self, ob, user_id, ob_edited=False): """ send instant notifications because object `ob` was changed by the user `user_id` """ if not self.config['enable_instant']: return ob_path = relative_object_path(ob, self._get_site()) messages_by_user = {} for subscription in self.list_subscriptions(notif_type='instant'): if not is_subpath(ob_path, subscription.location): continue if not self._has_view_permission(subscription.user_id, ob): continue messages_by_user[subscription.user_id] = { 'ob': ob, 'ob_edited': ob_edited, 'person': user_id, '_lang': subscription.lang, } template = self._get_template('instant') self._send_notifications(messages_by_user, template)
for file_path, file_data in zip_files: if '/' in file_path: file_container_path, file_name = file_path.rsplit('/', 1) else: file_container_path, file_name = '', file_path assert file_container_path in folder_map try: file_container = folder_map[file_container_path] file_ob_id = add_file(file_container, file_name, file_data) file_ob = file_container[file_ob_id] except Exception, e: errors.append((u"Error while creating file ${file_path}: ${error}", {'file_path': file_path, 'error': force_to_unicode(str(e))})) else: p = relative_object_path(file_ob, container) created_file_paths.add(p) if errors: if REQUEST is not None: transaction.abort() self.setSessionErrorsTrans(errors) return self.index_html(REQUEST) else: return errors else: notify(ZipImportEvent(container, sorted(created_file_paths))) if REQUEST is not None:
def get_location(self): return utils.relative_object_path(self.aq_parent, self.getSite())