pyvideo / richard

video indexing site
Other
216 stars 55 forks source link

allow videos on category page to be resorted #175

Open willkg opened 11 years ago

willkg commented 11 years ago

Some categories can contain a gazillion videos. That's problematic because it's hard to find what you're looking for. Further, if the category page changes, it's difficult to know what changed (e.g. what videos were recently updated).

I suggest at least the following:

  1. add last-updated data to the videos
  2. change the page so that the list of videos is sortable by title, created and last-updated
  3. (optional) persist the sort option for that category page in a cookie

I think this should cover just the videos tab for now. We can think about the other tabs in other issues.

Does this sound like a good way of fixing the problem without adding a ton of complexity?

squiddy commented 11 years ago

Sounds good to me.

Note that we already have an updated field that is changed every time a Video is saved. That leaves us just with points 2 & 3. Unless we somewhere update video data directly (i.e. Video.objects.update), then we have to set the data manually.

willkg commented 11 years ago

For 1, I meant "show the last-updated data for the videos in the category video tab page". It should be a quick template change.

I think I wrote up another issue about how there are certain changes you can make related to M2M fields that don't update the updated field. Regardless, those should be uninteresting cases in respects to this so we can deal with them separately.

squiddy commented 11 years ago

I added a really simple interface for this in 80b9a63937d34f08d621dda9ed41fa663fbb92d4. Sorting by title is ascending, creation and update date is descending (newest first).

Didn't work on 3 so far.

squiddy commented 11 years ago

About storing the preference in a cookie, I've been thinking about it and I'm not sure what you mean.

  1. Store the sort preference for each category page in a separate cookie. With path set, cookies will only be send when needed, however, we would be storing a lot of cookies on the client (not sure what the domain limits are).
  2. Store the sort preference for all categories in a single cookie. That cookie might grow big though and will be sent on every request.
  3. Store the sort preference in the session. While easy, it means that with enough visitors, the session will grow bigger.
willkg commented 11 years ago

If someone is logged in, they have a session. Definitely store it there. And I would store a separate one for each category. You could create a key like "category-sort-{id}" then have it be a tuple of something like (column, asc/desc). That should be fine.

alexandrul commented 11 years ago

A good default might reduce the page reloads, so the server load would be reduced. (I vote for the last updated date)

Is it possible to gather some usage data in the current state?

alexandrul commented 11 years ago

When sorting by dates, please use a secondary sort order by title, it would preserve the order for series recorded in the same day (like 'ABC part 1 - xxx', 'ABC part 2 - yyy', and so on)

willkg commented 11 years ago

Three thoughts:

  1. I was actually hoping the sorting would be done client-side in JavaScript. There's no good reason to do a round-trip to get a newly sorted page of all the stuff, so that should get redone.
  2. It's possible every site will be different so gathering usage data isn't helpful. If someone wants to start a site and spend time doing this, fine. I'm not going to spend time on this.
  3. Doing a secondary sort by title is probably a good idea. I'd be game for that.
alexandrul commented 11 years ago

There is a good reason for using small commits :wink:

@squiddy please submit a patch for showing the last updated date, and another one for the default sort order (ascending by name). After all, the code was already written :smile:

willkg commented 11 years ago

@alexandrul No... A small patch for the last updated date is fine, but the code is not already written for sorting. I suspect it'll require a restructuring of the page to do the sorting in JS.

alexandrul commented 11 years ago

@willkg just the default sort order, no UI changes:

videos = (obj.video_set.live().select_related('category')
-                                  .prefetch_related('speakers'))
+                                  .prefetch_related('speakers')
+                                  .order_by('title')) 
willkg commented 11 years ago

@alexandrul Ahh... Ok. I don't want to change that sort order.

squiddy commented 11 years ago

@alexandrul Feel free to work on it, I won't.