Пример #1
0
def init_docs(app, url_prefix):
    discourse_index_id = 3394

    session = talisker.requests.get_session()
    discourse_docs = Docs(
        parser=DocParser(
            api=DiscourseAPI(base_url="https://discourse.charmhub.io/",
                             session=session),
            index_topic_id=discourse_index_id,
            url_prefix=url_prefix,
        ),
        document_template="docs/document.html",
        url_prefix=url_prefix,
    )

    discourse_docs.init_app(app)

    app.add_url_rule(
        "/docs/search",
        "docs-search",
        build_search_view(
            session=session,
            site="charmhub.io/docs",
            template_path="docs/search.html",
        ),
    )
Пример #2
0
def init_docs(app, url_prefix):
    session = talisker.requests.get_session()
    discourse_docs = Docs(
        parser=DocParser(
            api=DiscourseAPI(
                base_url="https://forum.snapcraft.io/",
                session=session,
                api_key=DISCOURSE_API_KEY,
                api_username=DISCOURSE_API_USERNAME,
                get_topics_query_id=2,
            ),
            index_topic_id=11127,
            url_prefix=url_prefix,
            tutorials_index_topic_id=15409,
            tutorials_url_prefix="/tutorials",
        ),
        document_template="docs/document.html",
        url_prefix=url_prefix,
    )
    discourse_docs.init_app(app)

    app.add_url_rule(
        "/docs/search",
        "docs-search",
        build_search_view(
            session=session,
            site="snapcraft.io/docs",
            template_path="docs/search.html",
        ),
    )
Пример #3
0
def init_docs(app, url_prefix):
    discourse_index_id = 1087
    category_id = 22

    discourse_api = DiscourseAPI(base_url="https://discourse.juju.is/")
    discourse_parser = DocParser(
        api=discourse_api,
        index_topic_id=discourse_index_id,
        category_id=category_id,
        url_prefix=url_prefix,
    )
    discourse_docs = DiscourseDocs(
        parser=discourse_parser,
        document_template="docs/document.html",
        url_prefix=url_prefix,
    )

    discourse_docs.init_app(app)

    app.add_url_rule(
        "/docs/search",
        "docs-search",
        build_search_view(site="juju.is/docs",
                          template_path="docs/search.html"),
    )
Пример #4
0
def init_docs(app, url_prefix):
    discourse_docs = Docs(
        parser=DocParser(
            api=DiscourseAPI(
                base_url="https://forum.snapcraft.io/",
                session=talisker.requests.get_session(),
            ),
            index_topic_id=11127,
            url_prefix=url_prefix,
        ),
        document_template="docs/document.html",
        url_prefix=url_prefix,
    )

    discourse_docs.init_app(app)

    app.add_url_rule(
        "/docs/search",
        "docs-search",
        build_search_view(
            session=talisker.requests.get_session(),
            site="snapcraft.io/docs",
            template_path="docs/search.html",
        ),
    )
Пример #5
0
def init_docs(app, url_prefix):
    discourse_index_id = 1087

    discourse_api = DiscourseAPI(base_url="https://discourse.jujucharms.com/")
    discourse_parser = DocParser(discourse_api, 22, discourse_index_id,
                                 url_prefix)
    discourse_docs = DiscourseDocs(
        parser=discourse_parser,
        document_template="docs/document.html",
        url_prefix=url_prefix,
    )

    discourse_docs.init_app(app)

    @app.route(url_prefix + "/commands")
    def commands():
        """
        Show the static commands page
        """

        discourse_parser.parse()

        return flask.render_template(
            "docs/commands.html",
            document={"title": "Command reference"},
            navigation=discourse_parser.navigation,
        )

    app.add_url_rule(
        "/docs/search",
        "docs-search",
        build_search_view(site="jaas.ai/docs",
                          template_path="docs/search.html"),
    )
Пример #6
0
def init_docs(app):
    discourse_index_id = 1087
    tutorials_index_topic_id = 2628
    tutorials_url_prefix = "/tutorials"

    session = talisker.requests.get_session()
    discourse_docs = Docs(
        parser=DocParser(
            api=DiscourseAPI(
                base_url="https://discourse.charmhub.io/",
                session=session,
                api_key=DISCOURSE_API_KEY,
                api_username=DISCOURSE_API_USERNAME,
                get_topics_query_id=2,
            ),
            index_topic_id=discourse_index_id,
            url_prefix="/docs",
            tutorials_index_topic_id=tutorials_index_topic_id,
            tutorials_url_prefix=tutorials_url_prefix,
        ),
        document_template="docs/document.html",
        url_prefix="/docs",
    )

    discourse_docs.init_app(app)

    sdk_docs_id = 4449
    sdk_docs = Docs(
        parser=DocParser(
            api=DiscourseAPI(
                base_url="https://discourse.charmhub.io/",
                session=session,
                api_key=DISCOURSE_API_KEY,
                api_username=DISCOURSE_API_USERNAME,
                get_topics_query_id=2,
            ),
            index_topic_id=sdk_docs_id,
            url_prefix="/docs/sdk",
            tutorials_index_topic_id=tutorials_index_topic_id,
            tutorials_url_prefix=tutorials_url_prefix,
        ),
        document_template="docs/document.html",
        url_prefix="/docs/sdk",
        blueprint_name="sdk_docs",
    )

    sdk_docs.init_app(app)

    app.add_url_rule(
        "/docs/search",
        "docs-search",
        build_search_view(
            session=session,
            site="juju.is/docs",
            template_path="docs/search.html",
        ),
    )
Пример #7
0
    def setUp(self):
        """
        Set up Flask app with build_search_view extension for testing
        And set up mocking for googleapis.com
        """

        # Suppress annoying warnings from HTTPretty
        # See: https://github.com/gabrielfalcao/HTTPretty/issues/368
        warnings.filterwarnings("ignore",
                                category=ResourceWarning,
                                message="unclosed.*")
        # Tests aren't where we should worry about deprication,
        # as long as everything works
        warnings.filterwarnings("ignore", category=DeprecationWarning)

        # Enable HTTPretty and set up mock URLs
        httpretty.enable()
        register_uris()

        template_folder = f"{this_dir}/fixtures/templates"
        session = requests.Session()

        self.app = flask.Flask("main", template_folder=template_folder)

        # Provide fake API key
        os.environ["SEARCH_API_KEY"] = "test-api-key"

        # Default use-case
        self.app.add_url_rule("/search", "search",
                              build_search_view(session=session))

        # Custom use-case
        self.app.add_url_rule(
            "/docs/search",
            "docs-search",
            build_search_view(
                session=session,
                site="maas.io/docs",
                template_path="docs/search.html",
            ),
        )

        self.client = self.app.test_client()
Пример #8
0
def init_docs(app, url_prefix):
    discourse_index_id = 1087
    category_id = 22

    discourse_api = DiscourseAPI(base_url="https://discourse.jujucharms.com/")
    discourse_parser = DocParser(
        discourse_api, category_id, discourse_index_id, url_prefix
    )
    discourse_docs = DiscourseDocs(
        parser=discourse_parser,
        document_template="docs/document.html",
        url_prefix=url_prefix,
    )

    discourse_docs.init_app(app)

    # Remove homepage route so we can redefine it
    for url in app.url_map._rules:
        if url.rule == url_prefix + "/":
            app.url_map._rules.remove(url)

    @app.route(url_prefix)
    def homepage():
        """
        Show the custom homepage
        """
        discourse_parser.parse()

        return flask.render_template(
            "docs/homepage.html", navigation=discourse_parser.navigation
        )

    @app.route(url_prefix + "/commands")
    def commands():
        """
        Show the static commands page
        """

        discourse_parser.parse()

        return flask.render_template(
            "docs/commands.html", navigation=discourse_parser.navigation
        )

    app.add_url_rule(
        "/docs/search",
        "docs-search",
        build_search_view(
            site="docs.jujucharms.com", template_path="docs/search.html"
        ),
    )
Пример #9
0
def init_docs(app):
    discourse_index_id = 1087

    session = talisker.requests.get_session()
    discourse_docs = Docs(
        parser=DocParser(
            api=DiscourseAPI(base_url="https://discourse.charmhub.io/",
                             session=session),
            index_topic_id=discourse_index_id,
            url_prefix="/docs",
        ),
        document_template="docs/document.html",
        url_prefix="/docs",
    )

    discourse_docs.init_app(app)

    sdk_docs_id = 4449
    sdk_docs = Docs(
        parser=DocParser(
            api=DiscourseAPI(base_url="https://discourse.charmhub.io/",
                             session=session),
            index_topic_id=sdk_docs_id,
            url_prefix="/docs/sdk",
        ),
        document_template="docs/document.html",
        url_prefix="/docs/sdk",
        blueprint_name="sdk_docs",
    )

    sdk_docs.init_app(app)

    app.add_url_rule(
        "/docs/search",
        "docs-search",
        build_search_view(
            session=session,
            site="juju.is/docs",
            template_path="docs/search.html",
        ),
    )
Пример #10
0
def init_docs(app, url_prefix):
    discourse_parser = DocParser(
        api=DiscourseAPI(base_url="https://forum.snapcraft.io/"),
        index_topic_id=11127,
        url_prefix=url_prefix,
    )
    discourse_docs = DiscourseDocs(
        parser=discourse_parser,
        category_id=15,
        document_template="docs/document.html",
        url_prefix=url_prefix,
    )

    discourse_docs.init_app(app)

    app.add_url_rule(
        "/docs/search",
        "docs-search",
        build_search_view(site="snapcraft.io/docs",
                          template_path="docs/search.html"),
    )
Пример #11
0
docs_url_prefix = "/docs"
discourse_docs = Docs(
    parser=DocParser(
        api=DiscourseAPI(
            base_url="https://discourse.dqlite.io/",
            session=session,
        ),
        index_topic_id=34,
        url_prefix=docs_url_prefix,
    ),
    document_template="docs/document.html",
    url_prefix=docs_url_prefix,
)

app.add_url_rule(
    "/docs/search",
    "docs-search",
    build_search_view(
        session=session,
        site="https://dqlite.io/docs",
        template_path="docs/search.html",
    ),
)

discourse_docs.init_app(app)


@app.route("/")
def index():
    return render_template("index.html")
Пример #12
0
    return response


url_prefix = "/docs"
server_docs_parser = DocParser(
    api=DiscourseAPI(
        base_url="https://discourse.ubuntu.com/",
        session=session,
    ),
    category_id=24,
    index_topic_id=8294,
    url_prefix=url_prefix,
)
server_docs = DiscourseDocs(
    parser=server_docs_parser,
    document_template="/docs/document.html",
    url_prefix=url_prefix,
)

server_docs.init_app(app)

app.add_url_rule(
    "/docs/search",
    "docs-search",
    build_search_view(
        session=session,
        site="multipass.run/docs",
        template_path="docs/search.html",
    ),
)
Пример #13
0
)
if app.debug:
    doc_parser.api.session.adapters["https://"].timeout = 99
discourse_docs = DiscourseDocs(
    parser=doc_parser,
    document_template="docs/document.html",
    category_id=5,
    url_prefix="/docs",
)
discourse_docs.init_app(app)

# Search
app.add_url_rule(
    "/docs/search",
    "docs-search",
    build_search_view(site="maas.io/docs", template_path="docs/search.html"),
)


@app.errorhandler(404)
def not_found_error(error):
    return flask.render_template("404.html"), 404


@app.errorhandler(500)
def internal_error(error):
    return flask.render_template("500.html"), 500


@app.context_processor
def context():
Пример #14
0
                                 is_standalone=True)


@app.route("/contribute")
def contribute_index():
    all_contributors = _get_contributors()
    team_members = list(_get_team_members(all_contributors))
    contributors = _filter_contributors(all_contributors)

    response = flask.make_response(
        flask.render_template(
            "contribute.html",
            team_members=team_members,
            contributors=contributors,
        ))

    response.cache_control.max_age = 86400
    response.cache_control.public = True

    return response


app.add_url_rule("/", view_func=template_finder_view)
app.add_url_rule(
    "/docs/search",
    "search",
    build_search_view(site="vanillaframework.io/docs",
                      template_path="docs/search.html"),
)
app.add_url_rule("/<path:subpath>", view_func=template_finder_view)
Пример #15
0
app.add_url_rule(
    "/advantage/renewals/<renewal_id>/process-payment",
    view_func=accept_renewal,
    methods=["POST"],
)
app.add_url_rule(
    (
        "/download"
        "/<regex('server|desktop|cloud|raspberry-pi'):category>"
        "/thank-you"
    ),
    view_func=download_thank_you,
)
app.add_url_rule("/getubuntu/releasenotes", view_func=releasenotes_redirect)
app.add_url_rule(
    "/search", "search", build_search_view(template_path="search.html")
)
app.add_url_rule(
    "/appliance/<regex('.+'):app>/<regex('.+'):device>",
    view_func=appliance_install,
)
# blog section

blog_views = BlogViews(
    api=Wordpress(session=session),
    excluded_tags=[3184, 3265, 3408],
    per_page=11,
)
app.add_url_rule(
    "/blog/topics/<regex('maas|design|juju|robotics|snapcraft'):slug>",
    view_func=BlogCustomTopic.as_view("blog_topic", blog_views=blog_views),
Пример #16
0
        "/thank-you"
    ),
    view_func=download_thank_you,
)

app.add_url_rule(
    "/download/server",
    methods=["GET", "POST"],
    view_func=download_server_steps,
)

app.add_url_rule("/getubuntu/releasenotes", view_func=releasenotes_redirect)
app.add_url_rule(
    "/search",
    "search",
    build_search_view(session=session, template_path="search.html"),
)
app.add_url_rule(
    (
        "/appliance/<regex('[a-z-]+'):appliance>/"
        "<regex('(raspberry-pi2?|intel-nuc|vm)'):device>"
    ),
    view_func=appliance_install,
)
app.add_url_rule(
    "/appliance/portfolio",
    view_func=appliance_portfolio,
)

# blog section
Пример #17
0
template_finder_view = TemplateFinder.as_view("template_finder")


@app.route("/examples")
def examples_index():
    return flask.render_template("examples/index.html",
                                 examples=_get_examples())


@app.route("/examples/standalone")
def standalone_examples_index():
    return flask.render_template("examples/standalone.html",
                                 examples=_get_examples())


@app.route("/examples/standalone/<path:example_path>")
def standalone_example(example_path):
    return flask.render_template(f"examples/{example_path}.html",
                                 is_standalone=True)


app.add_url_rule("/", view_func=template_finder_view)
app.add_url_rule(
    "/search",
    "search",
    build_search_view(site="docs.vanillaframework.io",
                      template_path="search.html"),
)
app.add_url_rule("/<path:subpath>", view_func=template_finder_view)
Пример #18
0
    return flask.render_template(
        "docs/examples/index.html", examples=_get_examples()
    )


@app.route("/docs/examples/standalone")
def standalone_examples_index():
    return flask.render_template(
        "docs/examples/standalone.html", examples=_get_examples()
    )


@app.route("/docs/examples/standalone/<path:example_path>")
def standalone_example(example_path):
    return flask.render_template(
        f"docs/examples/{example_path}.html", is_standalone=True
    )


app.add_url_rule("/", view_func=template_finder_view)
app.add_url_rule(
    "/docs/search",
    "search",
    build_search_view(
        # temporarly keep docs.vanillaframework.io until /docs are live and indexed
        # change to vanillaframework.io/docs
        site="docs.vanillaframework.io", template_path="docs/search.html"
    ),
)
app.add_url_rule("/<path:subpath>", view_func=template_finder_view)
Пример #19
0
        api=DiscourseAPI(base_url="https://discourse.ubuntu.com/",
                         session=session),
        index_topic_id=17029,
        url_prefix="/docs",
    ),
    document_template="docs/document.html",
    url_prefix="/docs",
)
discourse_docs.init_app(app)

app.add_url_rule(
    "/docs/search",
    "docs-search",
    build_search_view(
        session=session,
        site="anbox-cloud.io/docs",
        template_path="docs/search.html",
    ),
)


def _api_request(url_path, method="GET", params=None, json=None, headers=None):
    """
    Make API calls to the anbox API, passing any 401 errors to Flask to handle
    """

    response = session.request(
        method,
        f"{ANBOXCLOUD_API_BASE.rstrip('/')}/{url_join(url_path).lstrip('/')}",
        params=params,
        json=json,
Пример #20
0
     "/<regex('server|desktop|cloud|raspberry-pi'):category>"
     "/thank-you"),
    view_func=download_thank_you,
)

app.add_url_rule(
    "/download/server",
    methods=["GET", "POST"],
    view_func=download_server_steps,
)

app.add_url_rule("/getubuntu/releasenotes", view_func=releasenotes_redirect)
app.add_url_rule(
    "/search",
    "search",
    build_search_view(session=session, template_path="search.html"),
)
app.add_url_rule(
    ("/appliance/<regex('[a-z-]+'):appliance>/"
     "<regex('(raspberry-pi2?|intel-nuc|vm)'):device>"),
    view_func=appliance_install,
)
app.add_url_rule(
    "/appliance/portfolio",
    view_func=appliance_portfolio,
)

# blog section

blog_views = BlogViews(
    api=BlogAPI(session=session),
Пример #21
0
    view_func=download_thank_you,
)

app.add_url_rule(
    "/download/server",
    methods=["GET", "POST"],
    view_func=download_server_steps,
)

app.add_url_rule("/getubuntu/releasenotes", view_func=releasenotes_redirect)
app.add_url_rule(
    "/search",
    "search",
    build_search_view(
        session=session,
        template_path="search.html",
        search_engine_id=search_engine_id,
    ),
)
app.add_url_rule(
    (
        "/appliance/<regex('[a-z-]+'):appliance>/"
        "<regex('(raspberry-pi2?|intel-nuc|vm)'):device>"
    ),
    view_func=appliance_install,
)
app.add_url_rule(
    "/appliance/portfolio",
    view_func=appliance_portfolio,
)
Пример #22
0
discourse = Docs(
    parser=DocParser(
        api=DiscourseAPI(base_url="https://discuss.kubernetes.io/",
                         session=session),
        index_topic_id=11243,
        url_prefix="/docs",
    ),
    document_template="docs/document.html",
    url_prefix="/docs",
)
app.add_url_rule(
    "/docs/search",
    "docs-search",
    build_search_view(
        session=session,
        site="microk8s.io/docs",
        template_path="docs/search.html",
    ),
)
discourse.init_app(app)


@app.route("/")
def index():
    return render_template("index.html")


@app.route("/contact-us")
def contact():
    return render_template("contact-us.html")