Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1.     categories_string = fields.Function(fields.Char('Categories'
  2. #, order_field='aikidokas.get_categories_string %(order)s, aikidokas.name %(order)s'
  3. ), 'get_categories_string', searcher='search_categories_string')
  4.  
  5.     def get_categories_string(self, ids, name):
  6.         if not ids:
  7.             return []
  8.         res = {}
  9.         for party in self.browse(ids):
  10.             res[party.id] = ', '.join(sorted(cat.rec_name for cat in party.categories))
  11.             if 'Fukushidoin, ' in res[party.id]:
  12.                 res[party.id] = res[party.id].replace('Fukushidoin, ', '') + ', Fukushidoin'
  13.             if 'Shidoin, ' in res[party.id]:
  14.                 res[party.id] = res[party.id].replace('Shidoin, ', '') + ', Shidoin'
  15.             if 'Dojocho, ' in res[party.id]:
  16.                 res[party.id] = res[party.id].replace('Dojocho, ', '') + ', Dojocho'
  17.             if ', Dojo' == res[party.id][-6:]:
  18.                 res[party.id] = 'Dojo, ' + res[party.id][:len(res[party.id])-6]
  19.         return res
  20.  
  21.     def search_categories_string(self, name, clause):
  22.         ids = self.search([('name', '!=', '')], order=[])
  23.         res = []
  24.         value = clause[2]
  25.         cats = self.get_categories_string(ids, name)
  26.         for cat in cats.keys():
  27.             if value.lower() in cats[cat].lower():
  28.                 res.append('categories', '=', cats[cat])
  29.         res.append(('categories', clause[1], value))
  30.         return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement