author | Tero Marttila <terom@fixme.fi> |
Sun, 15 Feb 2009 23:55:48 +0200 | |
changeset 130 | 4212fd69d671 |
parent 129 | 67a30d680f60 |
child 131 | 67f5d2fdca1d |
permissions | -rw-r--r-- |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
2 |
Handling user preferences |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
3 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
4 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
5 |
import functools |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
6 |
import Cookie |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
7 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
8 |
from qmsk.web import urltree |
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
9 |
import utils |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
10 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
11 |
class Preference (urltree.URLType) : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
12 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
13 |
A specific preference |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
14 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
15 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
16 |
# the name to use |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
17 |
name = None |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
18 |
|
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
19 |
# the default value, as from parse() |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
20 |
default = None |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
21 |
|
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
22 |
def is_default (self, value) : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
23 |
""" |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
24 |
Returns True if the given post-value is the default value for this preference. |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
25 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
26 |
Defaults to just compare against self.default |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
27 |
""" |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
28 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
29 |
return (value == self.default) |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
30 |
|
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
31 |
def process (self, preferences, value) : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
32 |
""" |
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
33 |
Post-process this preference value. This can access the post-processed values of all other preferences that |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
34 |
were defined before this one in the list given to Preferences. |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
35 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
36 |
Defaults to just return value. |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
37 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
38 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
39 |
return value |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
40 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
41 |
class RequestPreferences (object) : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
42 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
43 |
Represents the specific preferences for some request |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
44 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
45 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
46 |
def __init__ (self, preferences, request, value_map=None) : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
47 |
""" |
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
48 |
Initialize with the given Preferences object, http Request, and { key: value } mapping of raw preference values. |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
49 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
50 |
This will build a mapping of { name: pre-value } using Preference.parse/Preference.default, and then |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
51 |
post-process them into the final { name: value } mapping using Preference.process, in strict pref_list |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
52 |
order. Note that the process() method will only have access to those preferences processed before it was. |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
53 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
54 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
55 |
# store |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
56 |
self.preferences = preferences |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
57 |
self.request = request |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
58 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
59 |
# initialize |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
60 |
self.values = {} |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
61 |
self.set_cookies = {} |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
62 |
|
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
63 |
# initial value map |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
64 |
pre_values = {} |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
65 |
|
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
66 |
# load preferences |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
67 |
for pref in preferences.pref_list : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
68 |
# got a value for it? |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
69 |
if value_map and pref.name in value_map : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
70 |
# get value |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
71 |
value = value_map[pref.name] |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
72 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
73 |
# parse it |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
74 |
value = pref.parse(value) |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
75 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
76 |
else : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
77 |
# use default value |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
78 |
value = pref.default |
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
79 |
|
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
80 |
# add |
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
81 |
pre_values[pref.name] = value |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
82 |
|
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
83 |
# then post-process using Preferences.process(), in strict pref_list order |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
84 |
for pref in preferences.pref_list : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
85 |
# store into self.values, so that pref.get(...) will be able to access the still-incomplete self.values |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
86 |
# dict |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
87 |
self.values[pref.name] = pref.process(self, pre_values[pref.name]) |
59
8ec729c5d998
ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
88 |
|
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
89 |
def _get_name (self, pref) : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
90 |
""" |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
91 |
Look up a Preference's name, either by class, object or name. |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
92 |
""" |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
93 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
94 |
# Preference -> name |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
95 |
if isinstance(pref, Preference) : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
96 |
pref = pref.name |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
97 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
98 |
return pref |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
99 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
100 |
def pref (self, name) : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
101 |
""" |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
102 |
Look up a Preference by object, name |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
103 |
""" |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
104 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
105 |
# Preference |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
106 |
if isinstance(name, Preference) : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
107 |
return name |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
108 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
109 |
# Preference.name |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
110 |
elif isinstance(name, basestring) : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
111 |
return self.preferences.pref_map[name] |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
112 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
113 |
# XXX: class? |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
114 |
else : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
115 |
assert False |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
116 |
|
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
117 |
def get (self, pref) : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
118 |
""" |
62
e7ca94b94a4e
add prefs to render context, and remove old timezone/formatter from it
Tero Marttila <terom@fixme.fi>
parents:
59
diff
changeset
|
119 |
Return the value for the given Preference, or preference name |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
120 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
121 |
|
62
e7ca94b94a4e
add prefs to render context, and remove old timezone/formatter from it
Tero Marttila <terom@fixme.fi>
parents:
59
diff
changeset
|
122 |
# look up |
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
123 |
return self.values[self._get_name(pref)] |
59
8ec729c5d998
ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
124 |
|
8ec729c5d998
ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
125 |
# support dict-access |
8ec729c5d998
ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
126 |
__getitem__ = get |
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
127 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
128 |
def is_default (self, pref) : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
129 |
""" |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
130 |
Returns True if the given preference is at its default value |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
131 |
""" |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
132 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
133 |
# determine using Preference.is_default |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
134 |
return self.pref(pref).is_default(self.get(pref)) |
59
8ec729c5d998
ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
135 |
|
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
136 |
def build (self, pref) : |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
137 |
""" |
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
138 |
Like 'get', but return the raw cookie value |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
139 |
""" |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
140 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
141 |
# the Preference |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
142 |
pref = self.pref(pref) |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
143 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
144 |
# build |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
145 |
return pref.build(self.get(pref)) |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
146 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
147 |
def parse (self, pref, value=None) : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
148 |
""" |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
149 |
Parse+process the raw value for some pref into a value object. |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
150 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
151 |
Is the given raw value is None, this uses Preference.default |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
152 |
""" |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
153 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
154 |
# lookup pref |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
155 |
pref = self.pref(pref) |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
156 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
157 |
# build value |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
158 |
if value is not None : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
159 |
# parse |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
160 |
value = pref.parse(value) |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
161 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
162 |
else : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
163 |
# default |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
164 |
value = pref.default |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
165 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
166 |
# post-process |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
167 |
value = pref.process(self, value) |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
168 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
169 |
# return |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
170 |
return value |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
171 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
172 |
def set (self, name, value_obj=None) : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
173 |
""" |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
174 |
Set a new value for the given preference (by str name). |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
175 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
176 |
If value_obj is None, then the preference cookie is unset |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
177 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
178 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
179 |
# sanity-check to make sure we're not setting it twice... |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
180 |
assert name not in self.set_cookies |
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
181 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
182 |
# None? |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
183 |
if value_obj is not None : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
184 |
# encode using the Preference object |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
185 |
value_str = self.preferences.pref_map[name].build(value_obj) |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
186 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
187 |
else : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
188 |
# unset as None |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
189 |
value_str = None |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
190 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
191 |
# update in our dict |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
192 |
self.values[name] = value_obj |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
193 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
194 |
# add to set_cookies |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
195 |
self.set_cookies[name] = value_str |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
196 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
197 |
class Preferences (object) : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
198 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
199 |
Handle user preferences using cookies |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
200 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
201 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
202 |
def __init__ (self, pref_list) : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
203 |
""" |
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
204 |
Use the given list of Preference objects. |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
205 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
206 |
The ordering of the given pref_list is significant for the process() implementation, as the |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
207 |
Preferences are process()'d in order. |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
208 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
209 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
210 |
# store |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
211 |
self.pref_list = pref_list |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
212 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
213 |
# translate to mapping as well |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
214 |
self.pref_map = dict((pref.name, pref) for pref in pref_list) |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
215 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
216 |
def load (self, request, ) : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
217 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
218 |
Load the set of preferences for the given request, and return as a { name -> value } dict |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
219 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
220 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
221 |
# the dict of values |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
222 |
values = {} |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
223 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
224 |
# load the cookies |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
225 |
cookie_data = request.env.get('HTTP_COOKIE') |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
226 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
227 |
# got any? |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
228 |
if cookie_data : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
229 |
# parse into a SimpleCookie |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
230 |
cookies = Cookie.SimpleCookie(cookie_data) |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
231 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
232 |
# update the the values |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
233 |
values.update((morsel.key, morsel.value) for morsel in cookies.itervalues()) |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
234 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
235 |
else : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
236 |
cookies = None |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
237 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
238 |
# apply any query parameters |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
239 |
for pref in self.pref_list : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
240 |
# look for a query param |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
241 |
value = request.get_arg(pref.name) |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
242 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
243 |
if value : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
244 |
# override |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
245 |
values[pref.name] = value |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
246 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
247 |
# build the RequestPreferences object |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
248 |
return cookies, RequestPreferences(self, request, values) |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
249 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
250 |
def handler (self, *pref_list) : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
251 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
252 |
Intended to be used as a decorator for a request handler, this will load the give Preferences and pass |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
253 |
them to the wrapped handler as keyword arguments, in addition to any others given. |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
254 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
255 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
256 |
def _decorator (func) : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
257 |
@functools.wraps(func) |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
258 |
def _handler (request, **args) : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
259 |
# load preferences |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
260 |
cookies, prefs = self.load(request) |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
261 |
|
59
8ec729c5d998
ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
262 |
# bind to request.prefs |
8ec729c5d998
ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
263 |
# XXX: better way to do this? :/ |
8ec729c5d998
ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
264 |
request.prefs = prefs |
8ec729c5d998
ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
265 |
|
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
266 |
# update args with new ones |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
267 |
args.update(((pref.name, prefs.get(pref)) for pref in pref_list)) |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
268 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
269 |
# handle to get response |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
270 |
response = func(request, **args) |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
271 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
272 |
# set cookies? |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
273 |
if prefs.set_cookies : |
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
274 |
# default, empty, cookiejar |
59
8ec729c5d998
ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
275 |
if not cookies : |
8ec729c5d998
ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
276 |
cookies = Cookie.SimpleCookie('') |
8ec729c5d998
ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
277 |
|
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
278 |
# update cookies |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
279 |
for key, value in prefs.set_cookies.iteritems() : |
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
280 |
if value is None : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
281 |
assert False, "Not implemented yet..." |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
282 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
283 |
else : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
284 |
# set |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
285 |
cookies[key] = value |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
286 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
287 |
# add headers |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
288 |
for morsel in cookies.itervalues() : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
289 |
response.add_header('Set-cookie', morsel.OutputString()) |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
290 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
291 |
return response |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
292 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
293 |
# return wrapped handler |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
294 |
return _handler |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
295 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
296 |
# return decorator... |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
297 |
return _decorator |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
298 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
299 |
# now for our defined preferences.... |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
300 |
import pytz |
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
62
diff
changeset
|
301 |
import config |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
302 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
303 |
class TimeFormat (urltree.URLStringType, Preference) : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
304 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
305 |
Time format |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
306 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
307 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
308 |
# set name |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
309 |
name = 'time_format' |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
310 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
311 |
# default value |
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
62
diff
changeset
|
312 |
default = config.PREF_TIME_FMT_DEFAULT |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
313 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
314 |
class DateFormat (urltree.URLStringType, Preference) : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
315 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
316 |
Date format |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
317 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
318 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
319 |
# set name |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
320 |
name = 'date_format' |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
321 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
322 |
# default value |
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
62
diff
changeset
|
323 |
default = config.PREF_DATE_FMT_DEFAULT |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
324 |
|
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
325 |
class TimezoneOffset (Preference) : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
326 |
""" |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
327 |
If the DST-aware 'timezone' is missing, we can fallback to a fixed-offset timezone as detected by |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
328 |
Javascript. |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
329 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
330 |
This is read-only, and None by default |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
331 |
""" |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
332 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
333 |
name = 'timezone_offset' |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
334 |
default = None |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
335 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
336 |
def parse (self, offset) : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
337 |
""" |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
338 |
Offset in minutes -> said minutes |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
339 |
""" |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
340 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
341 |
return int(offset) |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
342 |
|
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
343 |
class Timezone (Preference) : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
344 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
345 |
Timezone |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
346 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
347 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
348 |
# set name |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
349 |
name = 'timezone' |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
350 |
|
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
351 |
# default is handled via process() |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
352 |
default = 'auto' |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
353 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
354 |
# the list of available (value, name) options for use with helpers.select_options |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
355 |
OPTIONS = [('auto', "Autodetect")] + [(None, tz_name) for tz_name in pytz.common_timezones] |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
356 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
357 |
def parse (self, name) : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
358 |
""" |
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
359 |
default -> default |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
360 |
tz_name -> pytz.timezone |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
361 |
""" |
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
362 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
363 |
# special-case for 'auto' |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
364 |
if name == self.default : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
365 |
return self.default |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
366 |
|
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
367 |
else : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
368 |
return pytz.timezone(name) |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
369 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
370 |
def is_default (self, tz) : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
371 |
""" |
130
4212fd69d671
remove debug crap and fix Timezone.is_default to detect config.PREF_TIMEZONE_DEFAULT as well
Tero Marttila <terom@fixme.fi>
parents:
129
diff
changeset
|
372 |
True if it's a FixedOffsetTimezone or PREF_TIMEZONE_DEFAULT |
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
373 |
""" |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
374 |
|
130
4212fd69d671
remove debug crap and fix Timezone.is_default to detect config.PREF_TIMEZONE_DEFAULT as well
Tero Marttila <terom@fixme.fi>
parents:
129
diff
changeset
|
375 |
return (isinstance(tz, utils.FixedOffsetTimezone) or tz == config.PREF_TIMEZONE_DEFAULT) |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
376 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
377 |
def build (self, tz) : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
378 |
""" |
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
379 |
FixedOffsetTimezone -> None |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
380 |
pytz.timezone -> tz_name |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
381 |
""" |
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
382 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
383 |
# special-case for auto/no explicit timezone |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
384 |
if self.is_default(tz) : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
385 |
return self.default |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
386 |
|
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
387 |
else : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
388 |
# pytz.timezone zone name |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
389 |
return tz.zone |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
390 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
391 |
def process (self, prefs, tz) : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
392 |
""" |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
393 |
If this timezone is given, simply build that. Otherwise, try and use TimezoneOffset, and if that fails, |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
394 |
just return the default. |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
395 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
396 |
None -> FixedOffsetTimezone/PREF_TIMEZONE_DEFAULT |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
397 |
pytz.timezone -> pytz.timezone |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
398 |
""" |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
399 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
400 |
# specific timezone set? |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
401 |
if tz != self.default : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
402 |
return tz |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
403 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
404 |
# fixed offset? |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
405 |
elif prefs[timezone_offset] is not None : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
406 |
return utils.FixedOffsetTimezone(prefs[timezone_offset]) |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
407 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
408 |
# default |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
409 |
else : |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
410 |
return config.PREF_TIMEZONE_DEFAULT |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
411 |
|
79 | 412 |
class ImageFont (Preference) : |
413 |
""" |
|
414 |
Font for ImageFormatter |
|
415 |
""" |
|
416 |
||
417 |
# set name |
|
418 |
name = 'image_font' |
|
419 |
||
420 |
def __init__ (self, font_dict, default_name) : |
|
421 |
""" |
|
422 |
Use the given { name: (path, title) } dict and default the given name |
|
423 |
""" |
|
424 |
||
425 |
self.font_dict = font_dict |
|
426 |
self.default = self.parse(default_name) |
|
427 |
||
428 |
def parse (self, name) : |
|
429 |
""" |
|
430 |
name -> (name, path, title) |
|
431 |
""" |
|
432 |
||
433 |
path, title = self.font_dict[name] |
|
434 |
||
435 |
return name, path, title |
|
436 |
||
437 |
def build (self, font_info) : |
|
438 |
""" |
|
439 |
(name, path, title) -> name |
|
440 |
""" |
|
441 |
||
442 |
name, path, title = font_info |
|
443 |
||
444 |
return name |
|
445 |
||
446 |
class ImageFontSize (urltree.URLIntegerType, Preference) : |
|
447 |
# set name, default |
|
448 |
name = 'image_font_size' |
|
449 |
default = config.PREF_IMAGE_FONT_SIZE_DEFAULT |
|
450 |
||
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
451 |
# XXX: constraints for valid values |
79 | 452 |
|
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
453 |
class Formatter (Preference) : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
454 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
455 |
LogFormatter to use |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
456 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
457 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
458 |
# set name |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
459 |
name = 'formatter' |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
460 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
461 |
def __init__ (self, formatters, default) : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
462 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
463 |
Use the given { name -> class LogFormatter } dict and default (a LogFormatter class) |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
464 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
465 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
466 |
self.formatters = formatters |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
467 |
self.default = default |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
468 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
469 |
def parse (self, fmt_name) : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
470 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
471 |
fmt_name -> class LogFormatter |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
472 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
473 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
474 |
return self.formatters[fmt_name] |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
475 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
476 |
def build (self, fmt_cls) : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
477 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
478 |
class LogFormatter -> fmt_name |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
479 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
480 |
|
59
8ec729c5d998
ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
481 |
return fmt_cls.name |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
482 |
|
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
483 |
def process (self, prefs, fmt_cls) : |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
484 |
""" |
79 | 485 |
class LogFormatter -> LogFormatter(tz, time_fmt, image_font.path) |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
486 |
""" |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
487 |
|
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
488 |
# time stuff |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
489 |
tz = prefs[timezone] |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
490 |
time_fmt = prefs[time_format] |
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
491 |
|
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
492 |
# font stuff |
79 | 493 |
font_name, font_path, font_title = prefs[image_font] |
494 |
font_size = prefs[image_font_size] |
|
495 |
||
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
496 |
return fmt_cls(tz, time_fmt, font_path, font_size) |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
497 |
|
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
62
diff
changeset
|
498 |
class Count (urltree.URLIntegerType, Preference) : |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
62
diff
changeset
|
499 |
""" |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
62
diff
changeset
|
500 |
Number of lines of log data to display per page |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
62
diff
changeset
|
501 |
""" |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
502 |
|
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
62
diff
changeset
|
503 |
# set name |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
62
diff
changeset
|
504 |
name = "count" |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
62
diff
changeset
|
505 |
|
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
62
diff
changeset
|
506 |
# default |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
62
diff
changeset
|
507 |
default = config.PREF_COUNT_DEFAULT |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
62
diff
changeset
|
508 |
|
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
62
diff
changeset
|
509 |
def __init__ (self) : |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
62
diff
changeset
|
510 |
super(Count, self).__init__(allow_negative=False, allow_zero=False, max=config.PREF_COUNT_MAX) |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
62
diff
changeset
|
511 |
|
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
62
diff
changeset
|
512 |
# and then build the Preferences object |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
62
diff
changeset
|
513 |
time_format = TimeFormat() |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
62
diff
changeset
|
514 |
date_format = DateFormat() |
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
515 |
timezone_offset = TimezoneOffset() |
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
62
diff
changeset
|
516 |
timezone = Timezone() |
79 | 517 |
image_font = ImageFont(config.FORMATTER_IMAGE_FONTS, config.PREF_IMAGE_FONT_DEFAULT) |
518 |
image_font_size = ImageFontSize() |
|
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
62
diff
changeset
|
519 |
formatter = Formatter(config.LOG_FORMATTERS, config.PREF_FORMATTER_DEFAULT) |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
62
diff
changeset
|
520 |
count = Count() |
59
8ec729c5d998
ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
521 |
|
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
522 |
preferences = Preferences([ |
59
8ec729c5d998
ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
523 |
time_format, |
8ec729c5d998
ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
524 |
date_format, |
129
67a30d680f60
Autodetect user timezone using Javascript, this makes the Preferences code a bit more complicated in terms of interaction between default/parse/is_default/build/process/etc, but it should work as intended now
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
525 |
timezone_offset, |
59
8ec729c5d998
ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
526 |
timezone, |
79 | 527 |
image_font, |
528 |
image_font_size, |
|
59
8ec729c5d998
ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
529 |
formatter, |
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
62
diff
changeset
|
530 |
count, |
53
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
531 |
]) |
8103d18907a0
add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
532 |