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 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # -*- coding: utf-8 -*-
  2. from werkzeug.wrappers import Response
  3. from ..template.loader import TemplateLoader
  4. # This module contains the web UI controllers that will be called from the web ui class
  5. ##@brief Render a template and return a respone
  6. #@param tpl str : template relativ path
  7. #@param tpl_vars : templates variables (obsolete)
  8. #@param mimetype
  9. #@param status_code
  10. #@param **kwargs : new version of tpl_vars
  11. #@return a response...
  12. def get_response(tpl='empty.html', tpl_vars={}, mimetype='text/html', status_code=200, **kwargs):
  13. tpl_vars.update(kwargs)
  14. loader = TemplateLoader()
  15. response = Response(loader.render_to_response(tpl, template_vars=tpl_vars), mimetype=mimetype)
  16. response.status_code = status_code
  17. return response
  18. ## @brief gets the html template corresponding to a given component type
  19. # @param type str : name of the component type
  20. # @param params dict : extra parameters to customize the template
  21. def get_component_html(type='text', params={}):
  22. params['type'] = type
  23. template_loader = TemplateLoader()
  24. return template_loader.render_to_html(template_file='components/components.html', template_vars=params)
  25. def index(request):
  26. return get_response('index/index.html')
  27. def not_found(request):
  28. return get_response('errors/404.html', status_code=404)
  29. def test(request):
  30. if 'id' not in request.url_args:
  31. id = None
  32. else:
  33. id = request.url_args['id']
  34. template_vars = {
  35. 'id': id,
  36. 'params': request.GET
  37. }
  38. return get_response('test.html', tpl_vars=template_vars)