Opened 17 years ago

Closed 12 years ago

#3189 closed Bug (worksforme)

[patch] generic date_based view, allowing week to start on monday

Reported by: nicolaslara@… 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)

date_based.py.diff (1.1 KB ) - added by nicolaslara@… 17 years ago.
date_based.py.diff
date_based.py.2.diff (2.0 KB ) - added by jgomo3 15 years ago.
Calendar based archive_week generic view.

Download all attachments as: .zip

Change History (18)

by nicolaslara@…, 17 years ago

Attachment: date_based.py.diff added

date_based.py.diff

comment:1 by mir@…, 17 years ago

Cc: mir@… added

comment:2 by anonymous, 17 years ago

Cc: nicolaslara@… added

comment:3 by Simon G. <dev@…>, 17 years ago

Triage Stage: UnreviewedDesign 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 anonymous, 17 years ago

Related ticket: http://code.djangoproject.com/ticket/1061
Perhaps it would be exported to admin view

comment:5 by Jacob, 16 years ago

Version: SVN

comment:6 by jgomo3, 15 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 jgomo3, 15 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.

by jgomo3, 15 years ago

Attachment: date_based.py.2.diff added

Calendar based archive_week generic view.

in reply to:  3 comment:8 by jgomo3, 15 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 jgomo3, 15 years ago

Cc: jgomo3@… added

comment:10 by Russell Keith-Magee, 14 years ago

Triage Stage: Design decision neededAccepted

Accepted on the basis that we now have USE_L10N, which this view should be honoring.

comment:11 by Russell Keith-Magee, 14 years ago

Patch needs improvement: set

comment:12 by Russell Keith-Magee, 13 years ago

Also needs to be updated for class-based views.

comment:13 by Łukasz Rekucki, 13 years ago

Severity: minorNormal
Type: defectBug

comment:14 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:15 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:16 by Aymeric Augustin, 12 years ago

Resolution: worksforme
Status: newclosed

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.

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