How to use the zope.interface.alsoProvides function in Zope

To help you get started, we’ve selected a few Zope examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github socialplanning / opencore / nui / project / tests.py View on Github external
def contents_content(tc):
        tc.loginAsPortalOwner()
        proj = tc.portal.projects.p2
        proj.invokeFactory('Document', 'new1', title='new title')
        proj.invokeFactory('Image', 'img1', title='new image')
        proj.restrictedTraverse('project-home').invokeFactory('FileAttachment', 'fa1', title='new file')
        proj.new1.invokeFactory('FileAttachment', 'fa2', title='new1 file')
        proj.invokeFactory('Folder', 'lists', title='Listen Stub')
        lists = proj.lists
        lists.setLayout('mailing_lists')
        alsoProvides(lists, IListenContainer)
        enableLocalSiteHook(tc.portal)
        setSite(tc.portal)
        setHooks()
        proj.lists.invokeFactory('Open Mailing List', 'list1', title=u'new list')
github socialplanning / opencore / opencore / upgrades / to_0_17_0.py View on Github external
def mark_memsynced_mailing_lists(context):
    """
     http://www.openplans.org/projects/opencore/lists/opencore-dev/archive/2009/04/1239543233615/forum_view
    """
    cat = getToolByName(context, 'portal_catalog')
    lists = cat.unrestrictedSearchResults(portal_type='Open Mailing List')
    i = 0; changed = False
    for list in lists:
        print list.getId
        i += 1
        if list.getId.endswith('-discussion'):
            list = list.getObject()
            alsoProvides(list, ISyncWithProjectMembership)
            logger.info("marked list %s with ISyncWithProjectMembership" % list.getId)
            changed = True

        if changed and i % 400 == 0:
            transaction.commit()
            logger.info('===== COMMITTING (%d of %d) ====' %(i, len(lists)))
            changed = False

    transaction.commit()
    logger.info('==== COMMITTING (%d of %d) ====' %(i, len(lists)))
github zopefoundation / z3c.form / src / z3c / form / util.py View on Github external
# Step 1: Calculate an interface name
        ifaceName = 'IGeneratedForObject_%i' %id(spec)

        # Step 2: Find out if we already have such an interface
        existingInterfaces = [
                i for i in zope.interface.directlyProvidedBy(spec)
                    if i.__name__ == ifaceName
            ]

        # Step 3a: Return an existing interface if there is one
        if len(existingInterfaces) > 0:
            spec = existingInterfaces[0]
        # Step 3b: Create a new interface if not
        else:
            iface = zope.interface.interface.InterfaceClass(ifaceName)
            zope.interface.alsoProvides(spec, iface)
            spec = iface
    return spec
github liqd / adhocracy3 / src / adhocracy_core / adhocracy_core / evolution / __init__.py View on Github external
def make_users_badgeable(root, registry):  # pragma: no cover
    """Add badge services and make user badgeable."""
    principals = find_service(root, 'principals')
    if not IHasBadgesPool.providedBy(principals):
        logger.info('Add badges service to {0}'.format(principals))
        add_badges_service(principals, registry, {})
        alsoProvides(principals, IHasBadgesPool)
    users = find_service(root, 'principals', 'users')
    assignments = find_service(users, 'badge_assignments')
    if assignments is None:
        logger.info('Add badge assignments service to {0}'.format(users))
        add_badge_assignments_service(users, registry, {})
    migrate_new_sheet(root, IUser, IBadgeable)
github senaite / senaite.core / bika / lims / upgrade / v01_03_001.py View on Github external
def mark_analyses_transitions(portal):
    logger.info("Marking Analyses with ISubmitted and IVerified ...")
    statuses = ["to_be_verified", "verified", "published"]
    query = dict(review_state=statuses)
    brains = api.search(query, CATALOG_ANALYSIS_LISTING)
    total = len(brains)
    for num, brain in enumerate(brains):
        if num % 100 == 0:
            logger.info("Marking Analyses with ISubmitted and IVerified: {}/{}"
                        .format(num, total))

        an = api.get_object(brain)
        alsoProvides(an, ISubmitted)
        if brain.review_state in ["verified", "published"]:
            alsoProvides(an, IVerified)

        if num % 1000 == 0 and num > 0:
            commit_transaction(portal)
github senaite / senaite.core / bika / lims / workflow / analysisrequest / events.py View on Github external
def after_receive(analysis_request):
    """Method triggered after "receive" transition for the Analysis Request
    passed in is performed
    """
    # Mark this analysis request as IReceived
    alsoProvides(analysis_request, IReceived)

    analysis_request.setDateReceived(DateTime())
    do_action_to_analyses(analysis_request, "initialize")
github socialplanning / opencore / siteui / member.py View on Github external
def initializeMemberArea(mtool, request):
    """
    This method is triggered by the 'notifyMemberAreaCreated' script
    that is called at the end of the membership tool's
    createMemberArea() method.  Will switch to an event as soon as the
    membership tool starts firing one.
    """
    member = mtool.getAuthenticatedMember()
    member_id = member.getId()

    folder = mtool.getHomeFolder(member_id)
    alsoProvides(folder, IMemberFolder)
    apply_member_folder_redirection(folder, request)

    page_id = "%s-home" % member_id
    title = "%s Home" % member_id
    folder.invokeFactory('Document', page_id, title=title)
    folder.setDefaultPage(page_id)

    page = getattr(folder, page_id)
    # XXX acquisition, ugh @@ huh?
    page_text = member.member_index(member_id=member_id)
    page.setText(page_text)

    # the page is the homepage
    alsoProvides(page, IMemberHomePage)

    # make profile the default view on the homepage
github Pylons / pyramid_tm / src / pyramid_tm / __init__.py View on Github external
def maybe_tag_retryable(request, exc_info):
    exc = exc_info[1]
    txn = request.tm.get()
    if hasattr(txn, 'isRetryableError'):
        if txn.isRetryableError(exc):
            zope.interface.alsoProvides(exc, IRetryableError)

    # bw-compat transaction < 2.4
    elif hasattr(request.tm, '_retryable'):  # pragma: no cover
        if request.tm._retryable(*exc_info[:-1]):
            zope.interface.alsoProvides(exc, IRetryableError)
github plone / plone.restapi / src / plone / restapi / services / registry / update.py View on Github external
def reply(self):
        records_to_update = json.loads(self.request.get('BODY', '{}'))
        registry = getUtility(IRegistry)

        # Disable CSRF protection
        if 'IDisableCSRFProtection' in dir(plone.protect.interfaces):
            alsoProvides(self.request,
                         plone.protect.interfaces.IDisableCSRFProtection)

        for key, value in records_to_update.items():
            if key not in registry:
                raise NotImplementedError(
                    "This endpoint is only intended to update existing "
                    "records! Couldn't find key %r" % key)
            registry[key] = value
        self.request.response.setStatus(204)
        return None
github senaite / senaite.core / bika / lims / upgrade / v01_03_001.py View on Github external
def mark_analyses_transitions(portal):
    logger.info("Marking Analyses with ISubmitted and IVerified ...")
    statuses = ["to_be_verified", "verified", "published"]
    query = dict(review_state=statuses)
    brains = api.search(query, CATALOG_ANALYSIS_LISTING)
    total = len(brains)
    for num, brain in enumerate(brains):
        if num % 100 == 0:
            logger.info("Marking Analyses with ISubmitted and IVerified: {}/{}"
                        .format(num, total))

        an = api.get_object(brain)
        alsoProvides(an, ISubmitted)
        if brain.review_state in ["verified", "published"]:
            alsoProvides(an, IVerified)

        if num % 1000 == 0 and num > 0:
            commit_transaction(portal)