Opened 18 years ago
Closed 13 years ago
#3189 closed Bug (worksforme)
[patch] generic date_based view, allowing week to start on monday
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Generic views | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | mir@…, nicolaslara@…, jgomo3@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
I found a bit contradictory that the date filter believes weeks start on Monday while generic date_based views believe weeks start on Sunday.
Here is a patch to the date_based generic view to allow an extra argument week_starts_monday=False that, if true, makes the weeks start on monday.
(its pretty straight forward)
Attachments (2)
Change History (18)
by , 18 years ago
Attachment: | date_based.py.diff added |
---|
comment:1 by , 18 years ago
Cc: | added |
---|
comment:2 by , 18 years ago
Cc: | added |
---|
follow-up: 8 comment:3 by , 18 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
Is it possible to change this from the rather restrictive "week_starts_monday" to a generic "week_start_day" option?
comment:4 by , 17 years ago
Related ticket: http://code.djangoproject.com/ticket/1061
Perhaps it would be exported to admin view
comment:5 by , 17 years ago
Version: | → SVN |
---|
comment:6 by , 16 years ago
Replying to mir@noris.de:
Justo to comment that the format of strptime support a directive to express the number of a week with monday beeing the first day of the week: it is %W. So, if week_starts_monday is False the line wich define tha local var date states unchanged like this:
date = datetime.date(*time.strptime(year+'-0-'+week, '%Y-%w-%U')[:3])
but if week_starts_monday is True, it can be changed to:
date = datetime.date(*time.strptime(year+'-0-'+week, '%Y-%w-%W')[:3])
I think it is cleaner than adding a day to date.
comment:7 by , 16 years ago
Also has to be changed the number representing the day of the week (%w). So, the stuff is like, for sunday beeing the first day:
date = datetime.date(*time.strptime(year+'-0-'+week, '%Y-%w-%U')[:3])
but for monday beeing the first day:
date = datetime.date(*time.strptime(year+'-1-'+week, '%Y-%w-%W')[:3])
I think that's all.
comment:8 by , 16 years ago
Replying to Simon G. <dev@simon.net.nz>:
Is it possible to change this from the rather restrictive "week_starts_monday" to a generic "week_start_day" option?
Yes. I did this patch (date_based.py.2.diff) to prove the concept and i let it in my django install. The generic option would be firstweekday. Is based on the python standar calendar module, wich define tha Calendar class wich by default set monday as the first week day, but let you specify one of the seven days of the week as the first day (0 is monday and 6 is sunday).
Note: but, i think people is working on this issue and more here #7980, and maybe this ticket should be closed and the diff's should be exported to the #7980.
comment:9 by , 16 years ago
Cc: | added |
---|
comment:10 by , 14 years ago
Triage Stage: | Design decision needed → Accepted |
---|
Accepted on the basis that we now have USE_L10N, which this view should be honoring.
comment:11 by , 14 years ago
Patch needs improvement: | set |
---|
comment:13 by , 14 years ago
Severity: | minor → Normal |
---|---|
Type: | defect → Bug |
comment:16 by , 13 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
It seems to me that WeekMixin.week_format
provides this feature in the class-based generic views. The function-based generic views no longer exist.
date_based.py.diff