lib/dynamic.py
branchxbelweb
changeset 47 2781ac85b807
child 51 7015d65beb3d
equal deleted inserted replaced
46:d3c1de4d929e 47:2781ac85b807
       
     1 #!/usr/bin/python
       
     2 
       
     3 from keywords import get_keywords, sort_keywords
       
     4 from templates import Template
       
     5 
       
     6 def process_index(bk, kw, pref):
       
     7     tmpl = Template("dynamic.tmpl", pref)
       
     8     bk.sort(lambda x,y: cmp(x['name'],y['name']))
       
     9     tmpl.set("Bookmarks", bk)
       
    10     kw = sort_keywords(kw, pref)
       
    11     tmpl.set("Keywords", kw)
       
    12     tmpl.set("curl", get_curl())
       
    13     tmpl.set("total", len(bk))
       
    14     print tmpl.process()
       
    15 
       
    16 def do_dynamic(db, prefs, form = []):
       
    17     if form:
       
    18         selection = get_keywords(form, 'sel')
       
    19         exclusion = get_keywords(form, 'exc')
       
    20     else:
       
    21     	selection = exclusion = []
       
    22     if len(selection) == 0:
       
    23     	keywords = set_selection(db, [], selection, exclusion)
       
    24     	exc = map(lambda e: int(e['id']), keywords[1:])
       
    25    	bookmarks = db.select_bookmarks([0], exc)
       
    26     else:
       
    27     	bookmarks = db.select_bookmarks(selection, exclusion)
       
    28    	keywords = set_selection(db,
       
    29 		map(lambda e: e[0], bookmarks),
       
    30 		selection, exclusion)
       
    31     total = len(bookmarks)
       
    32     if len(bookmarks) > 0:
       
    33     	bookmarks = db.get_bookmarks(map(lambda x: x[0], bookmarks))
       
    34     bookmarks = map(lambda bk: bk.dict(), bookmarks)
       
    35     process_index(bookmarks, keywords[1:], prefs)