Esempio n. 1
0
    def test_iterate_over_tree_caching_first_level_addition(self):
        """Ensure that returned results are correctly cached"""
        results = utils.iterate_over_tree(self.container)
        self.assertEqual(5, len(results))

        new_category = self._create_category(u"003", u"Third")
        self.container._add_element(new_category)

        results = utils.iterate_over_tree(self.container)
        self.assertEqual(6, len(results))

        expected = [u"001", u"001.1", u"001.2", u"002", u"002.1", u"003"]
        self.assertEqual(expected, sorted([e.identifier for e in results]))
Esempio n. 2
0
    def test_iterate_over_tree_caching_edition(self):
        """Ensure that returned results are correctly cached"""
        results = utils.iterate_over_tree(self.container)
        self.assertEqual(5, len(results))

        category = [
            e for e in self.container.values() if e.identifier == u"002"
        ][0]
        category.identifier = u"002-updated"
        self.container._update_element(category)

        results = utils.iterate_over_tree(self.container)
        self.assertEqual(5, len(results))

        expected = [u"001", u"001.1", u"001.2", u"002-updated", u"002.1"]
        self.assertEqual(expected, sorted([e.identifier for e in results]))
Esempio n. 3
0
    def test_iterate_over_tree_basic(self):
        """Ensure that returned results are correct"""
        results = utils.iterate_over_tree(self.container)
        self.assertEqual(5, len(results))

        expected = [u"001", u"001.1", u"001.2", u"002", u"002.1"]
        self.assertEqual(expected, sorted([e.identifier for e in results]))
Esempio n. 4
0
def classification_tree_title_mapping_vocabulary_factory(context):
    query = {"portal_type": "ClassificationContainer", "context": api.portal.get()}
    containers = api.content.find(**query)
    results = []
    for container in containers:
        results.extend(
            [
                (e.title, e.UID())
                for e in utils.iterate_over_tree(container.getObject())
            ]
        )
    results = sorted(results, key=itemgetter(1))
    return iterable_to_vocabulary(results)
Esempio n. 5
0
def full_classification_tree_vocabulary_factory(context):
    query = {"portal_type": "ClassificationContainer"}
    containers = context.portal_catalog.unrestrictedSearchResults(**query)
    results = []
    for container in containers:
        results.extend(
            [
                (e.UID(), e.Title(), e.enabled)
                for e in utils.iterate_over_tree(container._unrestrictedGetObject())
            ]
        )
    results = sorted(results, key=itemgetter(1))
    return category_iterable_to_vocabulary(results)
Esempio n. 6
0
 def search(self, query):
     self.query = query
     raw_results = utils.iterate_over_tree(self.context)
     filtered_data = self._order(self._filter(raw_results))
     start, end = self._limits
     return len(raw_results), len(filtered_data), filtered_data[start:end]
Esempio n. 7
0
 def items_to_delete(self):
     return len(utils.iterate_over_tree(self.context))
Esempio n. 8
0
def clean_examples(self, doit='1'):
    """ Clean created examples """
    if not check_zope_admin():
        return "You must be a zope manager to run this script"
    if doit == '1':
        doit = True
    else:
        doit = False
    out = []
    portal = api.portal.getSite()
    if doit:
        portal.portal_properties.site_properties.enable_link_integrity_checks = False
    registry = getUtility(IRegistry)

    # Delete om
    brains = find(unrestricted=True, portal_type='dmsoutgoingmail')
    for brain in brains:
        log_list(out, "Deleting om '%s'" % brain.getPath())
        if doit:
            api.content.delete(obj=brain._unrestrictedGetObject(), check_linkintegrity=False)
    if doit:
        registry['collective.dms.mailcontent.browser.settings.IDmsMailConfig.outgoingmail_number'] = 1
    # Create test om
    params = {'title': u'Courrier test pour création de modèles (ne pas effacer)',
              'internal_reference_no': internalReferenceOutgoingMailDefaultValue(DummyView(portal, portal.REQUEST)),
              'mail_date': date.today(),
              'mail_type': 'type1',
              }
    if doit:
        sub_create(portal['outgoing-mail'], 'dmsoutgoingmail', datetime.now(), 'test_creation_modele', **params)

    # Delete im
    brains = find(unrestricted=True, portal_type=['dmsincomingmail', 'dmsincoming_email'])
    for brain in brains:
        log_list(out, "Deleting im '%s'" % brain.getPath())
        if doit:
            api.content.delete(obj=brain._unrestrictedGetObject(), check_linkintegrity=False)
    if doit:
        registry['collective.dms.mailcontent.browser.settings.IDmsMailConfig.incomingmail_number'] = 1
    # Delete own personnel
    pf = portal['contacts']['personnel-folder']
    brains = find(unrestricted=True, context=pf, portal_type='person')
    for brain in brains:
        log_list(out, "Deleting person '%s'" % brain.getPath())
        if doit:
            api.content.delete(obj=brain._unrestrictedGetObject(), check_linkintegrity=False)
    # Deactivate own organizations
    ownorg = portal['contacts']['plonegroup-organization']
    brains = find(unrestricted=True, context=ownorg, portal_type='organization',
                  id=['plonegroup-organization', 'college-communal'])
    kept_orgs = [brain.UID for brain in brains]
    log_list(out, "Activating only 'college-communal'")
    if doit:
        set_registry_organizations([ownorg['college-communal'].UID()])
    # Delete organization and template folders
    tmpl_folder = portal['templates']['om']
    brains = find(unrestricted=True, context=ownorg, portal_type='organization', sort_on='path',
                  sort_order='descending')
    for brain in brains:
        uid = brain.UID
        if uid in kept_orgs:
            continue
        log_list(out, "Deleting organization '%s'" % brain.getPath())
        if doit:
            api.content.delete(obj=brain._unrestrictedGetObject(), check_linkintegrity=False)
        if uid in tmpl_folder:
            log_list(out, "Deleting template folder '%s'" % '/'.join(tmpl_folder[uid].getPhysicalPath()))
            if doit:
                api.content.delete(obj=tmpl_folder[uid])
    # Delete contacts
    brains = find(unrestricted=True, context=portal['contacts'], portal_type='contact_list')
    for brain in brains:
        log_list(out, "Deleting contact list '%s'" % brain.getPath())
        if doit:
            api.content.delete(obj=brain._unrestrictedGetObject(), check_linkintegrity=False)
    brains = find(unrestricted=True, context=portal['contacts'], portal_type='person',
                  id=['jeancourant', 'sergerobinet', 'bernardlermitte'])
    for brain in brains:
        log_list(out, "Deleting person '%s'" % brain.getPath())
        if doit:
            api.content.delete(obj=brain._unrestrictedGetObject(), check_linkintegrity=False)
    brains = find(unrestricted=True, context=portal['contacts'], portal_type='organization', id=['electrabel', 'swde'])
    for brain in brains:
        log_list(out, "Deleting organization '%s'" % brain.getPath())
        if doit:
            api.content.delete(obj=brain._unrestrictedGetObject(), check_linkintegrity=False)
    # Delete users
    for userid in ['encodeur', 'dirg', 'chef', 'agent', 'agent1', 'lecteur']:
        user = api.user.get(userid=userid)
        for brain in find(unrestricted=True, Creator=userid, sort_on='path', sort_order='descending'):
            log_list(out, "Deleting object '%s' created by '%s'" % (brain.getPath(), userid))
            if doit:
                api.content.delete(obj=brain._unrestrictedGetObject(), check_linkintegrity=False)
        for group in api.group.get_groups(user=user):
            if group.id == 'AuthenticatedUsers':
                continue
            log_list(out, "Removing user '%s' from group '%s'" % (userid, group.getProperty('title')))
            if doit:
                api.group.remove_user(group=group, user=user)
        log_list(out, "Deleting user '%s'" % userid)
        if doit:
            api.user.delete(user=user)
    # Delete groups
    functions = [dic['fct_id'] for dic in get_registry_functions()]
    groups = api.group.get_groups()
    for group in groups:
        if '_' not in group.id or group.id in ['createurs_dossier', 'dir_general', 'lecteurs_globaux_ce',
                                               'lecteurs_globaux_cs']:
            continue
        parts = group.id.split('_')
        if len(parts) == 1:
            continue
        org_uid = parts[0]
        function = '_'.join(parts[1:])
        if org_uid in kept_orgs or function not in functions:
            continue
        log_list(out, "Deleting group '%s'" % group.getProperty('title'))
        if doit:
            api.group.delete(group=group)
    # Delete folders
    for brain in find(unrestricted=True, portal_type=('ClassificationFolder', 'ClassificationSubfolder'),
                      sort_on='path', sort_order='descending'):
        log_list(out, "Deleting classification folder '%s'" % brain.getPath())
        if doit:
            api.content.delete(obj=brain._unrestrictedGetObject())
    # Delete categories
    caching.invalidate_cache("collective.classification.tree.utils.iterate_over_tree", portal['tree'].UID())
    res = iterate_over_tree(portal['tree'])
    for category in reversed(res):
        log_list(out, "Deleting category '%s - %s'" % (safe_encode(category.identifier), safe_encode(category.title)))
        if doit:
            api.content.delete(obj=category)
    if doit:
        caching.invalidate_cache("collective.classification.tree.utils.iterate_over_tree", portal['tree'].UID())
        portal.portal_properties.site_properties.enable_link_integrity_checks = True
    return '\n'.join(out)