Add basic "new model view" wizard
This commit is contained in:
parent
f4bc280da7
commit
00548a259b
10 changed files with 681 additions and 5 deletions
|
@ -27,8 +27,10 @@ Tailbone Handler
|
|||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import six
|
||||
from mako.lookup import TemplateLookup
|
||||
|
||||
from rattail.app import GenericHandler
|
||||
from rattail.files import resource_path
|
||||
|
||||
from tailbone.providers import get_all_providers
|
||||
|
||||
|
@ -38,6 +40,13 @@ class TailboneHandler(GenericHandler):
|
|||
Base class and default implementation for Tailbone handler.
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(TailboneHandler, self).__init__(*args, **kwargs)
|
||||
|
||||
# TODO: make templates dir configurable?
|
||||
templates = [resource_path('rattail:templates/web')]
|
||||
self.templates = TemplateLookup(directories=templates)
|
||||
|
||||
def get_menu_handler(self, **kwargs):
|
||||
"""
|
||||
Get the configured "menu" handler.
|
||||
|
@ -54,5 +63,18 @@ class TailboneHandler(GenericHandler):
|
|||
return self.menu_handler
|
||||
|
||||
def iter_providers(self):
|
||||
"""
|
||||
Returns an iterator over all registered Tailbone providers.
|
||||
"""
|
||||
providers = get_all_providers(self.config)
|
||||
return six.itervalues(providers)
|
||||
|
||||
def write_model_view(self, data, path, **kwargs):
|
||||
"""
|
||||
Write code for a new model view, based on the given data dict,
|
||||
to the given path.
|
||||
"""
|
||||
template = self.templates.get_template('/new-model-view.mako')
|
||||
content = template.render(**data)
|
||||
with open(path, 'wt') as f:
|
||||
f.write(content)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue