lib/actions/edit_prefs.py
author fabien@tzone.org
Sun, 28 Dec 2008 13:45:41 -0500
changeset 61 a1bcf5e4b8a4
parent 60 dad9733c99f0
child 74 6784c4350b41
permissions -rwxr-xr-x
Correct a bug when saving preferences.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
60
dad9733c99f0 Convert the prefs editor to the action library.
fabien@tzone.org
parents: 47
diff changeset
     1
from templates import Template
dad9733c99f0 Convert the prefs editor to the action library.
fabien@tzone.org
parents: 47
diff changeset
     2
from webutils import load_index
38
c30e2402deca [svn r1582] Add some user preferences support (kw sorting and kw select box size).
fabien
parents:
diff changeset
     3
60
dad9733c99f0 Convert the prefs editor to the action library.
fabien@tzone.org
parents: 47
diff changeset
     4
def edit_prefs(db, prefs, form):
dad9733c99f0 Convert the prefs editor to the action library.
fabien@tzone.org
parents: 47
diff changeset
     5
    if form.has_key('kw_size'):
dad9733c99f0 Convert the prefs editor to the action library.
fabien@tzone.org
parents: 47
diff changeset
     6
    	prefs['keywords_box'] = int(form['kw_size'].value)
dad9733c99f0 Convert the prefs editor to the action library.
fabien@tzone.org
parents: 47
diff changeset
     7
    if form.has_key('kw_sort'):
dad9733c99f0 Convert the prefs editor to the action library.
fabien@tzone.org
parents: 47
diff changeset
     8
    	prefs['keywords_sort'] = form['kw_sort'].value
dad9733c99f0 Convert the prefs editor to the action library.
fabien@tzone.org
parents: 47
diff changeset
     9
    if form.has_key('default_view'):
dad9733c99f0 Convert the prefs editor to the action library.
fabien@tzone.org
parents: 47
diff changeset
    10
    	prefs['default_view'] = int(form['default_view'].value)
dad9733c99f0 Convert the prefs editor to the action library.
fabien@tzone.org
parents: 47
diff changeset
    11
    prefs['keywords_reverse'] = form.has_key('kw_reverse')
dad9733c99f0 Convert the prefs editor to the action library.
fabien@tzone.org
parents: 47
diff changeset
    12
    if form.has_key('fullname'):
dad9733c99f0 Convert the prefs editor to the action library.
fabien@tzone.org
parents: 47
diff changeset
    13
    	prefs['fullname'] = form['fullname'].value
dad9733c99f0 Convert the prefs editor to the action library.
fabien@tzone.org
parents: 47
diff changeset
    14
    db.set_preferences(prefs)
61
a1bcf5e4b8a4 Correct a bug when saving preferences.
fabien@tzone.org
parents: 60
diff changeset
    15
    load_index(db, db.get_preferences(), form, "result", "Preferences saved.")
38
c30e2402deca [svn r1582] Add some user preferences support (kw sorting and kw select box size).
fabien
parents:
diff changeset
    16
60
dad9733c99f0 Convert the prefs editor to the action library.
fabien@tzone.org
parents: 47
diff changeset
    17
def view_prefs(prefs):
47
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents: 38
diff changeset
    18
    tmpl = Template("prefs.tmpl", prefs)
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents: 38
diff changeset
    19
    sortfields = []
38
c30e2402deca [svn r1582] Add some user preferences support (kw sorting and kw select box size).
fabien
parents:
diff changeset
    20
    for field in ['keyword', 'count']:
47
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents: 38
diff changeset
    21
      sortfields.append({'field': field,
38
c30e2402deca [svn r1582] Add some user preferences support (kw sorting and kw select box size).
fabien
parents:
diff changeset
    22
                     'selected' : prefs['keywords_sort'] == field })
47
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents: 38
diff changeset
    23
    tmpl.set('Sortfields', sortfields)
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents: 38
diff changeset
    24
    views = []
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents: 38
diff changeset
    25
    for view in [(0, 'dynamic'), (1, 'folder')]:
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents: 38
diff changeset
    26
    	views.append({ 'view': view[0],
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents: 38
diff changeset
    27
	        'name': view[1],
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents: 38
diff changeset
    28
		'selected': prefs['default_view'] == view[0]} )
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents: 38
diff changeset
    29
    tmpl.set('Views', views)
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents: 38
diff changeset
    30
    print tmpl.process()
38
c30e2402deca [svn r1582] Add some user preferences support (kw sorting and kw select box size).
fabien
parents:
diff changeset
    31
60
dad9733c99f0 Convert the prefs editor to the action library.
fabien@tzone.org
parents: 47
diff changeset
    32
def do_it(action, db, prefs, form):
dad9733c99f0 Convert the prefs editor to the action library.
fabien@tzone.org
parents: 47
diff changeset
    33
	if form.has_key('step'):
61
a1bcf5e4b8a4 Correct a bug when saving preferences.
fabien@tzone.org
parents: 60
diff changeset
    34
		step = form['step'].value
60
dad9733c99f0 Convert the prefs editor to the action library.
fabien@tzone.org
parents: 47
diff changeset
    35
	else:
dad9733c99f0 Convert the prefs editor to the action library.
fabien@tzone.org
parents: 47
diff changeset
    36
		step = 'view'
dad9733c99f0 Convert the prefs editor to the action library.
fabien@tzone.org
parents: 47
diff changeset
    37
	if step == 'view':
dad9733c99f0 Convert the prefs editor to the action library.
fabien@tzone.org
parents: 47
diff changeset
    38
		view_prefs(prefs)
dad9733c99f0 Convert the prefs editor to the action library.
fabien@tzone.org
parents: 47
diff changeset
    39
	elif step == 'edit':
61
a1bcf5e4b8a4 Correct a bug when saving preferences.
fabien@tzone.org
parents: 60
diff changeset
    40
		edit_prefs(db, prefs, form)
60
dad9733c99f0 Convert the prefs editor to the action library.
fabien@tzone.org
parents: 47
diff changeset
    41
	else:	
dad9733c99f0 Convert the prefs editor to the action library.
fabien@tzone.org
parents: 47
diff changeset
    42
		load_index(db, prefs, form, "error", "Operation cancel.")