author | fabien |
Fri, 24 Oct 2003 17:24:19 -0400 | |
branch | xbelweb |
changeset 48 | 9cde0ea6f411 |
parent 47 | 2781ac85b807 |
child 51 | 7015d65beb3d |
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 |
|
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
3 |
from keywords import get_keywords, sort_keywords |
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("curl", get_curl()) |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
13 |
tmpl.set("total", len(bk)) |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
14 |
print tmpl.process() |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
15 |
|
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
16 |
def do_dynamic(db, prefs, form = []): |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
17 |
if form: |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
18 |
selection = get_keywords(form, 'sel') |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
19 |
exclusion = get_keywords(form, 'exc') |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
20 |
else: |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
21 |
selection = exclusion = [] |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
22 |
if len(selection) == 0: |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
23 |
keywords = set_selection(db, [], selection, exclusion) |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
24 |
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
|
25 |
bookmarks = db.select_bookmarks([0], exc) |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
26 |
else: |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
27 |
bookmarks = db.select_bookmarks(selection, exclusion) |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
28 |
keywords = set_selection(db, |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
29 |
map(lambda e: e[0], bookmarks), |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
30 |
selection, exclusion) |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
31 |
total = len(bookmarks) |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
32 |
if len(bookmarks) > 0: |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
33 |
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
|
34 |
bookmarks = map(lambda bk: bk.dict(), bookmarks) |
2781ac85b807
[svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff
changeset
|
35 |
process_index(bookmarks, keywords[1:], prefs) |