silviot
silviot

Reputation: 4768

from plone.app.content.batching import Batch fails with ImportError: No module named batching

I just upgraded to Plone 4.3 and I get this error:

ImportError: No module named batching

Upvotes: 1

Views: 215

Answers (1)

silviot
silviot

Reputation: 4768

plone.app.content no more provides a batching implementation.

Replace

from plone.app.content.batching import Batch

with

try:
    from plone.app.content.batching import Batch # Plone < 4.3
    HAS_PLONE43 = False
except ImportError:
    from plone.batching import Batch # Plone >= 4.3
    HAS_PLONE43 = True

[EDIT]

The two implementations have a different API: the pagesize argument is named size in plone.app.batching; also, instead of a page number a start index is required.

If you have code that looks like this

    b = Batch(items,
            pagesize=pagesize,
            pagenumber=pagenumber)

replace it with

    if HAS_PLONE43:
        b = Batch(items,
                size=pagesize,
                start=pagenumber * pagesize)
    else:
        b = Batch(items,
                pagesize=pagesize,
                pagenumber=pagenumber)

Upvotes: 2

Related Questions