As emocionantes aventuras de um sysadmin linux na procura pelo uptime perfeito!

Multiple AutoComplete options, ugly but works.

Posted: novembro 21st, 2006 | Author: coredump | Filed under: Linux e Open Source, Programação | Tags: ,

So, I was trying to make the Turbogears AutoComplete Widget work like the address field from gmail or hotmail. Basically to continue searching after a comma to add values. My javascript is not that good and I felt a little bad on messing with the default widgets, so I did something on the search controller to mimic this behavior. This is the complete controller I use with the Widget:

def complete(self, tagname):
tags = ['linux', 'security', 'love', 'politics', 'sex', 'religion',
'esports', 'programming', 'scifi', 'theories', 'spaced tag']

old_tagname = None
if ‘,’ in tagname:
new_tagname = tagname.replace(‘ ‘, ”).split(‘,’)
tagname = new_tagname.pop().strip()
old_tagname = ‘, ‘.join(new_tagname)

if tagname == ”:
return dict(tag = [])

reslist = []
for tag in tags:
if tag.startswith(tagname):
if old_tagname:
tag = old_tagname + ‘, ‘ + tag
reslist.append(tag)

return dict(tag = reslist)

@expose()
def default(self, *w, **kw):
raise redirect(“/”)

Yes, it’s kinda ugly but it works. In Brazil this is called gambiarra. I’ll elaborate a little more after, there’re too many variables and I’m sure I can make something more compact. Right now I just need this working :) cya.Technorati Tags: , , ,

Compartilhe:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis
  • Identi.ca
  • Twitter

Posts relacionados:

  1. CherryPy Session e message queue Tem vezes que eu faço umas coisas que eu acho...
  2. Kindness of Strangers Tá bom… Vocês ficaram com dó e não me falaram...
  3. Turbogears Validators, Widgets and i18n (or how I got it to work) <Originally posted on the turbogears mail list> So, for the...
  4. Turbogears, Mysql and UTF. Advice Needed! So, I have this little problem… For design reasons, I...
  5. Cavando! Release de protótipo E então. Nas últimas semanas estive tendo cravings de programação...

No Comments »

Leave a Reply