1.1 --- a/imiptools/period.py Tue Oct 20 17:44:45 2015 +0200
1.2 +++ b/imiptools/period.py Tue Oct 20 18:01:13 2015 +0200
1.3 @@ -573,7 +573,7 @@
1.4
1.5 # Period layout.
1.6
1.7 -def get_scale(periods, tzid):
1.8 +def get_scale(periods, tzid, view_period=None):
1.9
1.10 """
1.11 Return an ordered time scale from the given list of 'periods'.
1.12 @@ -581,17 +581,23 @@
1.13 The given 'tzid' is used to make sure that the times are defined according
1.14 to the chosen time zone.
1.15
1.16 + An optional 'view_period' is used to constrain the scale to the given
1.17 + period.
1.18 +
1.19 The returned scale is a mapping from time to (starting, ending) tuples,
1.20 where starting and ending are collections of periods.
1.21 """
1.22
1.23 scale = {}
1.24 + view_start = view_period and to_timezone(view_period.get_start_point(), tzid) or None
1.25 + view_end = view_period and to_timezone(view_period.get_end_point(), tzid) or None
1.26
1.27 for p in periods:
1.28
1.29 # Add a point and this event to the starting list.
1.30
1.31 start = to_timezone(p.get_start(), tzid)
1.32 + start = view_start and max(start, view_start) or start
1.33 if not scale.has_key(start):
1.34 scale[start] = [], []
1.35 scale[start][0].append(p)
1.36 @@ -599,6 +605,7 @@
1.37 # Add a point and this event to the ending list.
1.38
1.39 end = to_timezone(p.get_end(), tzid)
1.40 + end = view_end and min(end, view_end) or end
1.41 if not scale.has_key(end):
1.42 scale[end] = [], []
1.43 scale[end][1].append(p)
2.1 --- a/imipweb/calendar.py Tue Oct 20 17:44:45 2015 +0200
2.2 +++ b/imipweb/calendar.py Tue Oct 20 18:01:13 2015 +0200
2.3 @@ -390,7 +390,7 @@
2.4
2.5 # Get the time scale with start and end points.
2.6
2.7 - scale = get_scale(periods, tzid)
2.8 + scale = get_scale(periods, tzid, view_period)
2.9
2.10 # Get the time slots for the periods.
2.11 # Time slots are collections of Point objects with lists of active