author | fabien |
Sun, 26 Oct 2003 22:26:03 -0500 | |
branch | xbelweb |
changeset 51 | 7015d65beb3d |
parent 47 | 2781ac85b807 |
child 58 | 004a32370ba5 |
permissions | -rwxr-xr-x |
47
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
1 |
#!/usr/bin/python |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
2 |
|
51
7015d65beb3d
[svn r1608] Correct the keywords bugs and some other in folder view, plus mutual
fabien
parents:
47
diff
changeset
|
3 |
from keywords import get_keywords, sort_keywords, set_selection |
47
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
4 |
from templates import Template |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
5 |
|
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
6 |
def process_index(bk, kw, pref): |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
7 |
tmpl = Template("dynamic.tmpl", pref) |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
8 |
bk.sort(lambda x,y: cmp(x['name'],y['name'])) |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
9 |
tmpl.set("Bookmarks", bk) |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
10 |
kw = sort_keywords(kw, pref) |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
11 |
tmpl.set("Keywords", kw) |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
12 |
tmpl.set("total", len(bk)) |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
13 |
print tmpl.process() |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
14 |
|
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
15 |
def do_dynamic(db, prefs, form = []): |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
16 |
if form: |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
17 |
selection = get_keywords(form, 'sel') |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
18 |
exclusion = get_keywords(form, 'exc') |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
19 |
else: |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
20 |
selection = exclusion = [] |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
21 |
if len(selection) == 0: |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
22 |
keywords = set_selection(db, [], selection, exclusion) |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
23 |
exc = map(lambda e: int(e['id']), keywords[1:]) |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
24 |
bookmarks = db.select_bookmarks([0], exc) |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
25 |
else: |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
26 |
bookmarks = db.select_bookmarks(selection, exclusion) |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
27 |
keywords = set_selection(db, |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
28 |
map(lambda e: e[0], bookmarks), |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
29 |
selection, exclusion) |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
30 |
total = len(bookmarks) |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
31 |
if len(bookmarks) > 0: |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
32 |
bookmarks = db.get_bookmarks(map(lambda x: x[0], bookmarks)) |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
33 |
bookmarks = map(lambda bk: bk.dict(), bookmarks) |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
34 |
process_index(bookmarks, keywords[1:], prefs) |