Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
panikweb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
radiopanik
panikweb
Commits
bc0f8e6a
Commit
bc0f8e6a
authored
Sep 04, 2013
by
fred
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
standardize week numbers on iso format
parent
9a21ca68
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
20 deletions
+36
-20
panikweb/paniktags/templatetags/paniktags.py
panikweb/paniktags/templatetags/paniktags.py
+7
-5
panikweb/utils.py
panikweb/utils.py
+9
-0
panikweb/views.py
panikweb/views.py
+17
-12
panikweb_templates/templates/program.html
panikweb_templates/templates/program.html
+3
-3
No files found.
panikweb/paniktags/templatetags/paniktags.py
View file @
bc0f8e6a
...
...
@@ -10,10 +10,11 @@ from django.conf import settings
from
django.db.models.query
import
QuerySet
from
django.utils
import
simplejson
from
datetime
import
datetime
,
timedelta
from
django.views.generic.dates
import
_date_from_string
from
emissions.utils
import
period_program
from
panikweb
import
utils
register
=
template
.
Library
()
@
register
.
filter
(
name
=
'zip'
)
...
...
@@ -93,11 +94,12 @@ def metanav(context, active=None):
}
@
register
.
inclusion_tag
(
'includes/week.html'
,
takes_context
=
True
)
def
weekview
(
context
,
year
=
None
,
week
=
None
,
weekday
=
None
,
fragment
=
None
):
year
=
year
if
year
else
datetime
.
today
().
year
week
=
week
if
week
else
datetime
.
today
().
isocalendar
()[
1
]
-
1
def
weekview
(
context
,
year
=
None
,
week
=
None
,
weekday
=
None
,
fragment
=
None
):
year
=
year
if
year
else
datetime
.
today
().
isocalendar
()[
0
]
week
=
week
if
week
else
datetime
.
today
().
isocalendar
()[
1
]
weekday
=
weekday
if
weekday
else
datetime
.
today
().
weekday
()
date
=
_date_from_string
(
str
(
year
),
'%Y'
,
'1'
,
'%w'
,
str
(
week
),
'%W'
)
date
=
utils
.
tofirstdayinisoweek
(
year
,
week
)
date
=
datetime
(
*
date
.
timetuple
()[:
3
])
program
=
period_program
(
date
,
date
+
timedelta
(
days
=
7
))
...
...
panikweb/utils.py
0 → 100644
View file @
bc0f8e6a
from
datetime
import
datetime
,
timedelta
def
tofirstdayinisoweek
(
year
,
week
):
# from http://stackoverflow.com/questions/5882405/get-date-from-iso-week-number-in-python
ret
=
datetime
.
strptime
(
'%04d-%02d-1'
%
(
year
,
week
),
'%Y-%W-%w'
)
if
datetime
(
year
,
1
,
4
).
isoweekday
()
>
4
:
ret
-=
timedelta
(
days
=
7
)
return
ret
panikweb/views.py
View file @
bc0f8e6a
...
...
@@ -19,6 +19,8 @@ from emissions.models import Category, Emission, Episode, Diffusion, SoundFile,
from
emissions.utils
import
whatsonair
,
period_program
from
.
import
utils
class
EmissionMixin
:
def
get_emission_context
(
self
,
emission
,
episode_ids
=
None
):
...
...
@@ -109,19 +111,22 @@ class ProgramView(TemplateView):
def
get_context_data
(
self
,
year
=
None
,
week
=
None
,
**
kwargs
):
context
=
super
(
ProgramView
,
self
).
get_context_data
(
**
kwargs
)
context
[
'sectionName'
]
=
"Emissions"
schedules
=
Schedule
.
objects
.
select_related
().
order_by
(
'datetime'
)
days
=
[]
for
day
in
range
(
7
):
days
.
append
({
'schedules'
:
[
x
for
x
in
schedules
if
x
.
is_on_weekday
(
day
+
1
)],
'datetime'
:
datetime
(
2007
,
1
,
day
+
1
)})
context
[
'days'
]
=
days
context
[
'weekday'
]
=
datetime
.
today
().
weekday
()
context
[
'week'
]
=
week
=
int
(
week
)
if
week
is
not
None
else
datetime
.
today
().
isocalendar
()[
1
]
-
1
context
[
'year'
]
=
year
=
int
(
year
)
if
year
is
not
None
else
datetime
.
today
().
year
context
[
'week_first_day'
]
=
datetime
.
strptime
(
str
(
year
)
+
' '
+
str
(
week
)
+
' 1'
,
'%Y %U %w'
)
context
[
'week_last_day'
]
=
context
[
'week_first_day'
]
+
timedelta
(
days
=+
6
)
context
[
'week_previous'
]
=
context
[
'week_first_day'
]
+
timedelta
(
days
=-
7
)
context
[
'week_next'
]
=
context
[
'week_last_day'
]
context
[
'week'
]
=
week
=
int
(
week
)
if
week
is
not
None
else
datetime
.
today
().
isocalendar
()[
1
]
context
[
'year'
]
=
year
=
int
(
year
)
if
year
is
not
None
else
datetime
.
today
().
isocalendar
()[
0
]
context
[
'week_first_day'
]
=
utils
.
tofirstdayinisoweek
(
year
,
week
)
context
[
'week_last_day'
]
=
context
[
'week_first_day'
]
+
timedelta
(
days
=
6
)
previous_week
=
context
[
'week_first_day'
]
-
timedelta
(
days
=
7
)
context
[
'previous_week_no'
]
=
previous_week
.
isocalendar
()[
1
]
context
[
'previous_week_year'
]
=
previous_week
.
isocalendar
()[
0
]
next_week
=
context
[
'week_first_day'
]
+
timedelta
(
days
=
7
)
context
[
'next_week_no'
]
=
next_week
.
isocalendar
()[
1
]
context
[
'next_week_year'
]
=
next_week
.
isocalendar
()[
0
]
return
context
program
=
ProgramView
.
as_view
()
...
...
panikweb_templates/templates/program.html
View file @
bc0f8e6a
...
...
@@ -8,10 +8,10 @@
<div
class=
"program "
>
<nav
class=
"center"
>
<ul
class=
"custom distributed"
>
{% if
week_previous
%}
{% if
previous_week_no
%}
<li>
<a
href=
"{% url 'program_week' year=
week_previous|date:"
Y
"
week=
week_previous|date:"W"
%}"
href=
"{% url 'program_week' year=
previous_week_year week=previous_week_no
%}"
class=
"icon-chevron-sign-left"
></a>
</li>
...
...
@@ -19,7 +19,7 @@
<li>
Du {{week_first_day|date:"l j N"}} au {{week_last_day|date:"l j N"}}
</li>
<li>
<a
href=
"{% url 'program_week' year=
week_last_day|date:"
Y
"
week=
week_last_day|date:"W"
%}"
href=
"{% url 'program_week' year=
next_week_year week=next_week_no
%}"
class=
"icon-chevron-sign-right"
></a>
</li>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment