author | Tero Marttila <terom@fixme.fi> |
Wed, 11 Feb 2009 22:56:43 +0200 | |
changeset 112 | 090192b64d7e |
parent 107 | 67f48e288102 |
child 113 | 9fc0eb751b6a |
permissions | -rw-r--r-- |
50
f13cf27a360b
implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1 |
""" |
f13cf27a360b
implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
2 |
Some additional helpers |
f13cf27a360b
implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
3 |
""" |
f13cf27a360b
implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
4 |
|
60 | 5 |
import datetime, calendar |
6 |
||
54
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
7 |
import qmsk.web.helpers |
50
f13cf27a360b
implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
8 |
|
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
9 |
import preferences, urls, config |
54
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
10 |
|
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
11 |
class Helpers (qmsk.web.helpers.Helpers) : |
50
f13cf27a360b
implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
12 |
""" |
54
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
13 |
Our set of helpers, inheriting from base helpers |
50
f13cf27a360b
implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
14 |
""" |
f13cf27a360b
implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
15 |
|
112
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
16 |
# set contructor... |
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
17 |
set = set |
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
18 |
|
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
19 |
# reference to calendar instance |
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
20 |
calendar = calendar.Calendar() |
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
21 |
|
54
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
22 |
def tz_name (self, tz) : |
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
23 |
""" |
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
24 |
Returns a string describing the given timezone |
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
25 |
""" |
50
f13cf27a360b
implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
26 |
|
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
27 |
return self.now().strftime(config.TIMEZONE_FMT) |
50
f13cf27a360b
implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
28 |
|
54
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
29 |
def fmt_month (self, date) : |
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
30 |
""" |
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
31 |
Formats a month |
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
32 |
""" |
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
33 |
|
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
34 |
return date.strftime(config.MONTH_FMT) |
54
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
35 |
|
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
36 |
def fmt_weekday (self, wday) : |
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
37 |
""" |
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
38 |
Formats an abbreviated weekday name |
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
39 |
""" |
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
40 |
|
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
41 |
return calendar.day_abbr[wday] |
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
42 |
|
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
43 |
def build_date (self, month, mday) : |
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
44 |
""" |
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
45 |
Returns a datetime.date for the given (month.year, month.month, mday) |
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
46 |
""" |
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
47 |
|
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
48 |
return datetime.date(month.year, month.month, mday) |
58
ce028d356e1f
special-case current month in calendar
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
49 |
|
ce028d356e1f
special-case current month in calendar
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
50 |
def now (self) : |
ce028d356e1f
special-case current month in calendar
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
51 |
""" |
ce028d356e1f
special-case current month in calendar
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
52 |
Build current time |
ce028d356e1f
special-case current month in calendar
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
53 |
""" |
ce028d356e1f
special-case current month in calendar
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
54 |
|
62
e7ca94b94a4e
add prefs to render context, and remove old timezone/formatter from it
Tero Marttila <terom@fixme.fi>
parents:
60
diff
changeset
|
55 |
return self.ctx['prefs'][preferences.timezone].localize(datetime.datetime.now()) |
58
ce028d356e1f
special-case current month in calendar
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
56 |
|
ce028d356e1f
special-case current month in calendar
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
57 |
def today (self) : |
ce028d356e1f
special-case current month in calendar
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
58 |
""" |
ce028d356e1f
special-case current month in calendar
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
59 |
Build today's date |
ce028d356e1f
special-case current month in calendar
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
60 |
""" |
ce028d356e1f
special-case current month in calendar
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
61 |
|
ce028d356e1f
special-case current month in calendar
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
62 |
return self.now().date() |
54
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
63 |
|
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
64 |
def is_today (self, date) : |
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
65 |
""" |
58
ce028d356e1f
special-case current month in calendar
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
66 |
Checks if the given date is today |
54
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
67 |
""" |
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
68 |
|
b65a95eb9f6b
implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
69 |
# construct current date |
58
ce028d356e1f
special-case current month in calendar
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
70 |
return date == self.today() |
55 | 71 |
|
58
ce028d356e1f
special-case current month in calendar
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
72 |
def is_this_month (self, month) : |
ce028d356e1f
special-case current month in calendar
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
73 |
""" |
ce028d356e1f
special-case current month in calendar
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
74 |
Checks the given month is the current month |
ce028d356e1f
special-case current month in calendar
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
75 |
""" |
ce028d356e1f
special-case current month in calendar
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
76 |
|
ce028d356e1f
special-case current month in calendar
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
77 |
today = self.today() |
ce028d356e1f
special-case current month in calendar
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
78 |
|
ce028d356e1f
special-case current month in calendar
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
79 |
return (month.year == today.year and month.month == today.month) |
ce028d356e1f
special-case current month in calendar
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
80 |
|
112
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
81 |
@staticmethod |
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
82 |
def _wrap_year (year, month) : |
55 | 83 |
""" |
112
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
84 |
Wraps month to between [1, 12], spilling overflow/underflow by to year. |
55 | 85 |
|
112
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
86 |
Returns (year, month) |
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
87 |
""" |
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
88 |
|
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
89 |
# underflow? |
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
90 |
if month == 0 : |
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
91 |
# wrap to previous year |
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
92 |
return (year - 1, 12) |
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
93 |
|
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
94 |
# overflow? |
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
95 |
elif month == 13 : |
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
96 |
# wrap to next year |
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
97 |
return (year + 1, 1) |
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
98 |
|
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
99 |
# sane value |
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
100 |
elif 1 <= month <= 12 : |
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
101 |
return (year, month) |
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
102 |
|
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
103 |
# insane value |
55 | 104 |
else : |
112
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
105 |
assert False, "invalid year/month: %d/%d" % (year, month) |
55 | 106 |
|
107 |
def prev_month (self, month) : |
|
108 |
""" |
|
112
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
109 |
Returns the month preceding the given one (as a datetime.datetime) |
55 | 110 |
""" |
112
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
111 |
|
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
112 |
# previous month |
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
113 |
y, m = self._wrap_year(month.year, month.month - 1) |
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
114 |
|
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
115 |
# build datetime |
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
116 |
return datetime.datetime(year=y, month=m, day=1, tzinfo=month.tzinfo) |
55 | 117 |
|
118 |
def next_month (self, month) : |
|
119 |
""" |
|
112
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
120 |
Returns the month following the given one (as a datetime.datetime) |
55 | 121 |
""" |
112
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
122 |
|
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
123 |
# previous month |
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
124 |
y, m = self._wrap_year(month.year, month.month + 1) |
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
125 |
|
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
126 |
# build datetime |
090192b64d7e
add three calendars to the channel_calendar view
Tero Marttila <terom@fixme.fi>
parents:
107
diff
changeset
|
127 |
return datetime.datetime(year=y, month=m, day=1, tzinfo=month.tzinfo) |
60 | 128 |
|
129 |
def fmt_time (self, time=None) : |
|
130 |
""" |
|
131 |
Format given time, or current time |
|
132 |
""" |
|
133 |
||
134 |
# defaults |
|
135 |
if not time : |
|
136 |
time = self.now() |
|
55 | 137 |
|
60 | 138 |
return time.strftime(self.ctx['prefs'][preferences.time_format]) |
139 |
||
140 |
def fmt_date (self, date=None) : |
|
141 |
""" |
|
142 |
Format given date, or current date |
|
143 |
""" |
|
144 |
||
145 |
# defaults |
|
146 |
if not date : |
|
147 |
date = self.now() |
|
148 |
||
149 |
return date.strftime(self.ctx['prefs'][preferences.date_format]) |
|
150 |
||
63 | 151 |
def build_url (self, url, **params) : |
152 |
""" |
|
153 |
Build URL with our request object |
|
154 |
""" |
|
155 |
||
156 |
return url.build(self.ctx['req'], **params) |
|
72
5ade0288f2ec
implement line-links as UTC timestamps
Tero Marttila <terom@fixme.fi>
parents:
71
diff
changeset
|
157 |
|
5ade0288f2ec
implement line-links as UTC timestamps
Tero Marttila <terom@fixme.fi>
parents:
71
diff
changeset
|
158 |
def utc_timestamp (self, dtz) : |
5ade0288f2ec
implement line-links as UTC timestamps
Tero Marttila <terom@fixme.fi>
parents:
71
diff
changeset
|
159 |
""" |
5ade0288f2ec
implement line-links as UTC timestamps
Tero Marttila <terom@fixme.fi>
parents:
71
diff
changeset
|
160 |
Build an UTC timestamp from the given datetime |
5ade0288f2ec
implement line-links as UTC timestamps
Tero Marttila <terom@fixme.fi>
parents:
71
diff
changeset
|
161 |
""" |
63 | 162 |
|
72
5ade0288f2ec
implement line-links as UTC timestamps
Tero Marttila <terom@fixme.fi>
parents:
71
diff
changeset
|
163 |
return urls.types['ts'].build(dtz) |
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
164 |
|
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
165 |
def skip_next (self, count, skip) : |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
166 |
""" |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
167 |
Return skip offset for next page |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
168 |
""" |
72
5ade0288f2ec
implement line-links as UTC timestamps
Tero Marttila <terom@fixme.fi>
parents:
71
diff
changeset
|
169 |
|
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
170 |
return count + skip |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
171 |
|
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
172 |
def skip_page (self, count, page) : |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
173 |
""" |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
174 |
Skip to page |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
175 |
""" |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
176 |
|
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
177 |
if page : |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
178 |
return count * page |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
179 |
|
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
180 |
else : |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
181 |
return None |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
182 |
|
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
183 |
def skip_prev (self, count, skip) : |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
184 |
""" |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
185 |
Return skip offset for previous page, None for first page |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
186 |
""" |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
187 |
|
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
188 |
if skip > count : |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
189 |
return skip - count |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
190 |
|
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
191 |
else : |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
192 |
return None |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
193 |
|
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
194 |
def max (self, *values) : |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
195 |
""" |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
196 |
Returns the largest of the given values |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
197 |
""" |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
198 |
|
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
199 |
return max(values) |
79 | 200 |
|
201 |
def select_options (self, key_values, selected_key) : |
|
202 |
""" |
|
203 |
Render a series of <option> tags for <select> |
|
204 |
""" |
|
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
205 |
|
79 | 206 |
return '\n'.join( |
207 |
'\t<option%s%s>%s</option>' % ( |
|
208 |
' value="%s"' % key if key != value else '', |
|
209 |
' selected="selected"' if key == selected_key else '', |
|
210 |
value |
|
211 |
) for key, value in key_values |
|
212 |
) |
|
107
67f48e288102
add prev/next date links to channel_date pagination
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
213 |
|
67f48e288102
add prev/next date links to channel_date pagination
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
214 |
def prev_date (self, date) : |
67f48e288102
add prev/next date links to channel_date pagination
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
215 |
""" |
67f48e288102
add prev/next date links to channel_date pagination
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
216 |
Returns the previous date for the given datetime-date |
67f48e288102
add prev/next date links to channel_date pagination
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
217 |
""" |
79 | 218 |
|
107
67f48e288102
add prev/next date links to channel_date pagination
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
219 |
return datetime.datetime(date.year, date.month, date.day, tzinfo=date.tzinfo) - datetime.timedelta(days=1) |
67f48e288102
add prev/next date links to channel_date pagination
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
220 |
|
67f48e288102
add prev/next date links to channel_date pagination
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
221 |
def next_date (self, date) : |
67f48e288102
add prev/next date links to channel_date pagination
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
222 |
""" |
67f48e288102
add prev/next date links to channel_date pagination
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
223 |
Returns the previous date for the given datetime-date |
67f48e288102
add prev/next date links to channel_date pagination
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
224 |
""" |
67f48e288102
add prev/next date links to channel_date pagination
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
225 |
|
67f48e288102
add prev/next date links to channel_date pagination
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
226 |
return datetime.datetime(date.year, date.month, date.day, tzinfo=date.tzinfo) + datetime.timedelta(days=1) |
67f48e288102
add prev/next date links to channel_date pagination
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
227 |