Make sure paginated DRF views play nicely with Fireplace/Commonplace

RESOLVED WORKSFORME

Status

Marketplace
Consumer Pages
RESOLVED WORKSFORME
4 years ago
4 years ago

People

(Reporter: cvan, Unassigned)

Tracking

Points:
---

Details

(Reporter)

Description

4 years ago
I think django-rest-framework's paginated responses are different from those of django-tasty-pie's. We'll probably need to adjust things, so we'll need to accommodate things in Fireplace and keep this in mind for Rocketfuel.

Compare

DRF
    "meta": {
        "next": null, 
        "page": 1, 
        "prev": null, 
        "total_count": 4
    }, 

vs.

Flue
    "meta": {
        "limit": 5, 
        "next": "/api/v1/rocketfuel/collections/?limit=5&offset=5", 
        "offset": 0, 
        "total_count": 24
    },

Comment 1

4 years ago
That's fine. The builder is fine so long as there's a URL available when there's a next page and a falsey value when there's not.
Status: NEW → RESOLVED
Last Resolved: 4 years ago
Resolution: --- → WORKSFORME

Comment 2

4 years ago
To elaborate now that I'm not on a phone:

The pagination code that we use only looks at `next` and `total_count`. Otherwise, we look at objects.length (which we don't need a meta field for). Limit and offset aren't used at all.

The code that handles pagination exploits the concept that rendering the same view a second time with the `next` URL instead of the current URL will render the second page of results. The `pagination` keyword in the defer block's signature says which element contains the results. We render the second page in the background, then rip out the selector defined by `pagination` and slap it at the end of the same selector in the DOM. So you end up with:

{% defer (... pagination=".stuff") %}
<ul class="stuff">
  <li>First</li>
  <li>Second</li>
</ul>
{% end %}

And the next page gets rendered as:

<ul class="stuff">
  <li>Third</li>
  <li>Fourth</li>
</ul>

We select `.stuff` and rip out the content and stick it in `.stuff` in the first document:

<ul class="stuff">
  <li>First</li>
  <li>Second</li>
  <li>Third</li>
  <li>Fourth</li>
</ul>

...and stick in a More button and whatever else we do.
(Reporter)

Comment 3

4 years ago
Excellent - good to hear. And thanks for the explanation.
You need to log in before you can comment on or make changes to this bug.