Opened 6 years ago

Closed 3 years ago

Last modified 3 years ago

#10890 closed New feature (fixed)

generic views archive_week and archive_day should have next/previous as Template Context

Reported by: ee_lars Owned by: aaugustin
Component: Generic views Version: master
Severity: Normal Keywords: generic views date_based archive_day archive_week
Cc: ben.welsh@…, michel@… Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Theses two generic views don't manage next/previous day/week.
It could be usefull and more coherent with archive_month and archive_year views which deal with these feature.

Attachments (2)

week_pagination.diff (2.2 KB) - added by palewire 5 years ago.
An addition to the archive_week generic view that adds next_week and previous_week objects to the context for easier pagination in your templates
week_pagination2.diff (2.2 KB) - added by michelts 5 years ago.
Fix over the first attachment.

Download all attachments as: .zip

Change History (16)

comment:1 Changed 6 years ago by jacob

  • milestone 1.1 deleted
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Changed 5 years ago by palewire

An addition to the archive_week generic view that adds next_week and previous_week objects to the context for easier pagination in your templates

comment:2 Changed 5 years ago by palewire

  • Has patch set
  • Needs tests set

I've attached a patch that tries to tackle the issue.

One complication: There isn't a week attribute on datetime objects, or at least I'm not aware of it. Typically, I use dt.isocalendar()[1] to get week numbers. But that's a pretty big hassle to do in your templates, so I'm not sure that just passing out a datetime object, as is done with the other date_based generic views, will work here.

If you check out my patch, what I tried was passing out dictionaries instead. Each with a 'year' and 'week' attribute that contains integers, and a 'date' key that hooks you up with the datetime object, if you happen to want that as well.

Dumb idea?

comment:3 Changed 5 years ago by palewire

  • Cc ben.welsh@… added

comment:4 Changed 5 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

comment:5 Changed 5 years ago by michelts

  • Cc michel@… added

comment:6 Changed 5 years ago by michelts

Palewire: I think you can use "day.strftime('%U')" instead of "day.isocalendar()[1]". With the second choice, you can't do an easy navigation because the week numbers of day.isocalendar() are different from the result of the '%U'.

Once django itself uses the '%U' to know what week we are, using it in the dates will be better. I will send a patch.

I will make the tests and documentation for it too, maybe it can appear in the django1.3?

Changed 5 years ago by michelts

Fix over the first attachment.

comment:7 Changed 5 years ago by palewire

I'm totally open to alternatives and if your fix dovetails with a broader change to the Django core, all the better.

comment:8 Changed 4 years ago by russellm

  • Needs documentation set
  • Patch needs improvement set

Patch needs to be updated for class-based views.

comment:9 Changed 4 years ago by SmileyChris

  • Severity set to Normal
  • Type set to New feature

comment:10 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:11 Changed 3 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:12 Changed 3 years ago by aaugustin

  • Owner changed from nobody to aaugustin

comment:13 Changed 3 years ago by Aymeric Augustin <aymeric.augustin@…>

  • Resolution set to fixed
  • Status changed from new to closed

In [fcb09b5746192fea1b672346c915ee11e4120d7e]:

Fixed #10890: added prev/next_week in the context

of per-week date-based generic views. Thanks ee_lars for the report.

comment:14 Changed 3 years ago by Aymeric Augustin <aymeric.augustin@…>

In [b0c1e5c081472436bf2300af3073cef1df1bd696]:

Documented next/previous_week. Refs #10890.

Note: See TracTickets for help on using tickets.
Back to Top