Open AndrewMagliozzi opened 9 years ago
Looks like the code for iterating through notes in a course is here (for the course page) https://github.com/FinalsClub/karmaworld/blob/3fb9188be79556bd351e3659a341c9aeeb6b4926/karmaworld/templates/courses/course_detail.html#L163-L165
note_set
in template is defined here:
https://github.com/FinalsClub/karmaworld/blob/3fb9188be79556bd351e3659a341c9aeeb6b4926/karmaworld/apps/courses/views.py#L111
Could probably slap an order_by
clause on it after the filter sort of like this:
https://github.com/FinalsClub/karmaworld/blob/3fb9188be79556bd351e3659a341c9aeeb6b4926/karmaworld/apps/courses/views.py#L134
Something like this might work to order notes by upload time:
kwargs['note_set'] = self.object.note_set.filter(is_hidden=False).order_by('-uploaded_at')
On the course page which lists notes, there is already a sort-by column Date Added
which appears to be handled by Javascript. There are two handlers, one is jQuery and the other is something else entirely (nonsense filename).
Unsure where that sorting is defined in the code. Adding the sort to the template as noted above will probably not be the worthwhile, as the JS will override that ordering and try to reorder the incoming list.
Code for sorting notes on a course page is here: https://github.com/FinalsClub/karmaworld/blob/master/karmaworld/assets/js/note-list.js#L3-L33
Code for sorting courses on the front page is here: https://github.com/FinalsClub/karmaworld/blob/master/karmaworld/assets/js/course-list.js#L18-L81
I don't like how similar this code is, it looks like we're opening up copy/paste issues. These should be refactored as much as possible and then share the code. That might resolve the issue outright or might make the solution more trivial.
refactoring moved to #395
From our Brown Editor in Chief:
I don't think that once the notes are uploaded they save on the site in any particular order. Is there any way that could be fixed, or is that already a feature? It would be great if they could be arranged alphabetically, that way they can stay in chronological order if the lectures are named, "Lecture 1, 2, 3, etc..." Or if they could save in the order they were uploaded from the computer that would be great too. This is just a future thing to keep in mind, not on the top of the priorities, though!