lib/dynamic.py
author fabien@tzone.org
Wed, 31 Dec 2008 01:53:22 -0500
changeset 73 c078d8a04d76
parent 58 004a32370ba5
child 74 6784c4350b41
permissions -rwxr-xr-x
Now only add unique keywords, either they are selected or write down.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
58
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
     6
def process_index(bk, kw, pref, status, status_msg):
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
     7
    tmpl = Template("dynamic.tmpl", pref, status, status_msg)
47
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
58
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
    15
def do_dynamic(db, prefs, form, status, status_msg):
47
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)
58
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
    34
    process_index(bookmarks, keywords[1:], prefs, status, status_msg)