Code

Opened 7 years ago

Closed 2 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: master
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@… 7 years ago.
date_based.py.diff
date_based.py.2.diff (2.0 KB) - added by jgomo3 6 years ago.
Calendar based archive_week generic view.

Download all attachments as: .zip

Change History (18)

Changed 7 years ago by nicolaslara@…

date_based.py.diff

comment:1 Changed 7 years ago by mir@…

  • Cc mir@… added

comment:2 Changed 7 years ago by anonymous

  • Cc nicolaslara@… added

comment:3 follow-up: Changed 7 years ago by Simon G. <dev@…>

  • Triage Stage changed from Unreviewed to 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 Changed 7 years ago by anonymous

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

comment:5 Changed 6 years ago by jacob

  • Version set to SVN

comment:6 Changed 6 years ago by jgomo3

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 Changed 6 years ago by jgomo3

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.

Changed 6 years ago by jgomo3

Calendar based archive_week generic view.

comment:8 in reply to: ↑ 3 Changed 6 years ago by jgomo3

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 Changed 6 years ago by jgomo3

  • Cc jgomo3@… added

comment:10 Changed 4 years ago by russellm

  • Triage Stage changed from Design decision needed to Accepted

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

comment:11 Changed 4 years ago by russellm

  • Patch needs improvement set

comment:12 Changed 3 years ago by russellm

Also needs to be updated for class-based views.

comment:13 Changed 3 years ago by lrekucki

  • Severity changed from minor to Normal
  • Type changed from defect to Bug

comment:14 Changed 2 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:15 Changed 2 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:16 Changed 2 years ago by aaugustin

  • Resolution set to worksforme
  • Status changed from new to 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.