PageRenderTime 22ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/handlers/Search.py

https://gitlab.com/manoj-makkuboy/vikuit
Python | 53 lines | 23 code | 6 blank | 24 comment | 5 complexity | aec6b701121dc928bd6173467f22fd7c MD5 | raw file
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # (C) Copyright 2008 Alberto Gimeno <gimenete at gmail dot com>
  5. # (C) Copyright 2008 Ignacio Andreu <plunchete at gmail dot com>
  6. # (C) Copyright 2008 NĂ©stor Salceda <nestor.salceda at gmail dot com>
  7. #
  8. # This file is part of "debug_mode_on".
  9. #
  10. # "debug_mode_on" is free software: you can redistribute it and/or modify
  11. # it under the terms of the GNU Affero General Public License as published by
  12. # the Free Software Foundation, either version 3 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # "debug_mode_on" is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU Affero General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU Affero General Public License
  21. # along with "debug_mode_on". If not, see <http://www.gnu.org/licenses/>.
  22. #
  23. from handlers.BaseHandler import *
  24. class Search(BaseHandler):
  25. def execute(self):
  26. q = self.get_param('q')
  27. typ = self.get_param('t')
  28. if typ == 'articles':
  29. query = model.Article.all().filter('draft', False).filter('deletion_date', None).search(q)
  30. self.values['articles'] = self.paging(query, 10)
  31. self.add_tag_cloud()
  32. elif typ == 'forums':
  33. query = model.Thread.all().search(q)
  34. threads = self.paging(query, 10)
  35. # migration
  36. for t in threads:
  37. if not t.url_path:
  38. t.url_path = t.parent_thread.url_path
  39. t.put()
  40. # end migration
  41. self.values['threads'] = threads
  42. else:
  43. query = model.Community.all().search(q)
  44. self.values['communities'] = self.paging(query, 10)
  45. self.values['q'] = q
  46. self.values['t'] = typ
  47. self.render('templates/search.html')