Detect if controller name correspond to a model name

This commit is contained in:
Fabien Meghazi 2014-05-28 19:16:50 +02:00
parent 6b678f376e
commit a9eba4dc40
2 changed files with 6 additions and 4 deletions

View File

@ -68,6 +68,8 @@ class Scaffold(Command):
if os.path.exists(controller_file):
die("Controller `%s` already exists !" % controller_file)
self.add_init_import(module('__init__.py'), 'controllers')
# Check if the controller name correspond to a model and expose result to templates
args.has_model = self.has_import(module('models', '__init__.py'), controller_module)
self.add_init_import(module('controllers', '__init__.py'), controller_module)
self.dump('controllers.jinja2', module('controllers', controller_file), config=args)

View File

@ -6,8 +6,8 @@ class {{ config.controller }}(main.Home):
@http.route('/{{ config.module }}/{{ config.controller }}', auth='public')
def index(self):
return "Hello, world!"
{% if config.model %}
@http.route('/{{ config.module }}/{{ config.controller }}/{{ config.model }}/<model("{{ config.module }}.{{ config.model }}"):{{ config.model }}>'], type='http', auth='public')
def {{ config.model }}(self, {{ config.model }}, **kw):
return "Hello, %r!" % {{ config.model }}
{% if config.has_model %}
@http.route('/{{ config.module }}/{{ config.controller }}/<model("{{ config.module }}.{{ config.controller }}"):{{ config.controller }}>'], type='http', auth='public')
def {{ config.controller }}(self, {{ config.controller }}, **kw):
return "Hello, %r!" % {{ config.controller }}
{% endif %}