Пример #1
0
def serve_schema_js(schema: APISchema, templates: Templates) -> http.Response:
    codec = CoreJSONCodec()
    base64_schema = base64.b64encode(codec.encode(schema)).decode('latin1')
    template = templates.get_template('apistar/schema.js')
    content = template.render(base64_schema=base64_schema)
    headers = {'Content-Type': 'application/javascript'}
    return http.Response(content, headers=headers)
Пример #2
0
    def __init__(self,
                 routes: List[routing.Route] = None,
                 commands: List[Callable] = None,
                 settings: Dict[str, Any] = None) -> None:
        from apistar.settings import Settings
        from apistar.templating import Templates
        from apistar.backends.sqlalchemy import SQLAlchemy

        routes = [] if (routes is None) else routes
        commands = [] if (commands is None) else commands

        self.routes = routes
        self.commands = list(self.built_in_commands) + commands
        self.settings = Settings(settings or {})

        initial_types = [App]  # type: List[type]
        self.preloaded = {
            'app': self
        }
        if 'TEMPLATES' in self.settings:
            initial_types.append(Templates)
            self.preloaded['templates'] = Templates.build(self.settings)
        if 'DATABASE' in self.settings:
            initial_types.append(SQLAlchemy)
            self.preloaded['sql_alchemy'] = SQLAlchemy.build(self.settings)
            self.commands += [cmd.create_tables]

        self.router = routing.Router(self.routes, initial_types)
        self.wsgi = get_wsgi_server(app=self)
        self.click = get_click_client(app=self)
Пример #3
0
def serve_schema_js(schema: APISchema, templates: Templates) -> http.Response:
    codec = CoreJSONCodec()
    base64_schema = base64.b64encode(codec.encode(schema)).decode('latin1')
    template = templates.get_template('apistar/schema.js')
    content = template.render(base64_schema=base64_schema)
    headers = {'Content-Type': 'application/javascript'}
    return http.Response(content, headers=headers)
Пример #4
0
def serve_docs(schema: APISchema, templates: Templates, path: Path):
    index = templates.get_template('apistar/docs/index.html')
    langs = ['python', 'javascript', 'shell']

    def static(path):
        return '/static/' + path

    def get_fields(link, location):
        return [field for field in link.fields if field.location == location]

    return index.render(document=schema,
                        static=static,
                        langs=langs,
                        get_fields=get_fields,
                        render_form=render_form,
                        path=path)
Пример #5
0
def serve_docs(schema: APISchema, templates: Templates, path: Path):
    index = templates.get_template('apistar/docs/index.html')
    langs = ['python', 'javascript', 'shell']

    def static(path):
        return '/static/' + path

    def get_fields(link, location):
        return [
            field for field in link.fields
            if field.location == location
        ]

    return index.render(
        document=schema,
        static=static,
        langs=langs,
        get_fields=get_fields,
        render_form=render_form,
        path=path
    )
Пример #6
0
def get_and_render_template(username: str, templates: Templates):
    index = templates.get_template('index.html')
    return index.render(username=username)
Пример #7
0
def get_and_render_template(username: str, templates: Templates):
    index = templates.get_template('index.html')
    return index.render(username=username)