Skip to content
Snippets Groups Projects
Commit a9eba4dc authored by Fabien Meghazi's avatar Fabien Meghazi
Browse files

Detect if controller name correspond to a model name

parent 6b678f37
Branches
Tags
No related merge requests found
......@@ -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)
......
......@@ -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 %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment