示例#1
0
class Breeze(object):

    def __init__(self, project_dir, exclude_apps=()):

        self.project_dir = project_dir
        self.breeze_dir = os.path.abspath(os.path.dirname(__file__))

        self.parse_options()

        self.apps = AppRegistry((self.breeze_dir, self.project_dir), exclude=exclude_apps)
        self.admins = AdminRegistry(self.apps)
        self.forms = FormRegistry(self.apps)

        self.settings = {
            'cookie_secret': options.cookie_secret,
            'debug': options.debug,
            'login_url': '/sign-in/',
            'static_path': os.path.join(self.breeze_dir, 'static'),
            'static_handler_class': AppStaticFileHandler.create(self),
            'template_loader': self.get_template_loader(),
            'ui_modules': list(self.get_ui_modules()),
        }

    def get_template_loader(self):
        def get_template_paths():
            yield 'breeze', os.path.join(self.breeze_dir, 'templates')
            for app in self.apps.keys():
                for root in (self.breeze_dir, self.project_dir):
                    path = os.path.join(root, 'apps', app, 'templates')
                    if os.path.exists(path):
                        yield app, path
        main_templates = (
            os.path.join(self.project_dir, 'templates'),
            os.path.join(self.breeze_dir, 'templates'),
        )
        return MapTemplateLoader(dict(get_template_paths()), *main_templates)

    def get_ui_modules(self):
        yield uimodules
        for app in self.apps.values():
            if hasattr(app, 'uimodules'):
                yield app.uimodules

    def get_urls(self):
        if options.setup:
            urls = list(setup_urls)
        else:
            urls = []
        for app_name, app in self.apps.iteritems():
            if hasattr(app, 'urls'):
                try:
                    urls += app.urls.urls
                except AttributeError, error:
                    raise AttributeError('%s: %s' % (app_name, error))
        urls.append((r'/.*', NotFoundHandler))
        return urls
示例#2
0
    def __init__(self, project_dir, exclude_apps=()):

        self.project_dir = project_dir
        self.breeze_dir = os.path.abspath(os.path.dirname(__file__))

        self.parse_options()

        self.apps = AppRegistry((self.breeze_dir, self.project_dir), exclude=exclude_apps)
        self.admins = AdminRegistry(self.apps)
        self.forms = FormRegistry(self.apps)

        self.settings = {
            'cookie_secret': options.cookie_secret,
            'debug': options.debug,
            'login_url': '/sign-in/',
            'static_path': os.path.join(self.breeze_dir, 'static'),
            'static_handler_class': AppStaticFileHandler.create(self),
            'template_loader': self.get_template_loader(),
            'ui_modules': list(self.get_ui_modules()),
        }