No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

base.py 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #
  2. # This file is part of Lodel 2 (https://github.com/OpenEdition)
  3. #
  4. # Copyright (C) 2015-2017 Cléo UMS-3287
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as published
  8. # by the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. from werkzeug.wrappers import Response
  20. from ..template.loader import TemplateLoader
  21. # This module contains the web UI controllers that will be called from the web ui class
  22. ##@brief Render a template and return a respone
  23. #@param tpl str : template relativ path
  24. #@param tpl_vars : templates variables (obsolete)
  25. #@param mimetype
  26. #@param status_code
  27. #@param **kwargs : new version of tpl_vars
  28. #@return a response...
  29. def get_response(tpl='empty.html', tpl_vars={}, mimetype='text/html', status_code=200, **kwargs):
  30. tpl_vars.update(kwargs)
  31. loader = TemplateLoader()
  32. response = Response(loader.render_to_response(tpl, template_vars=tpl_vars), mimetype=mimetype)
  33. response.status_code = status_code
  34. return response
  35. ## @brief gets the html template corresponding to a given component type
  36. # @param type str : name of the component type
  37. # @param params dict : extra parameters to customize the template
  38. def get_component_html(type='text', params={}):
  39. params['type'] = type
  40. template_loader = TemplateLoader()
  41. return template_loader.render_to_html(template_file='components/components.html', template_vars=params)
  42. def index(request):
  43. return get_response('index/index.html')
  44. def not_found(request):
  45. return get_response('errors/404.html', status_code=404)
  46. def test(request):
  47. if 'id' not in request.url_args:
  48. id = None
  49. else:
  50. id = request.url_args['id']
  51. template_vars = {
  52. 'id': id,
  53. 'params': request.GET
  54. }
  55. return get_response('test.html', tpl_vars=template_vars)