Esempio n. 1
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"),
    )
Esempio n. 2
0
def init_tutorials(app, url_prefix):
    discourse_parser = DocParser(
        api=DiscourseAPI(session=session,
                         base_url="https://discourse.juju.is/"),
        index_topic_id=2628,
        category_id=34,
        url_prefix=url_prefix,
    )
    discourse_docs = DiscourseDocs(
        parser=discourse_parser,
        document_template="tutorials/tutorial.html",
        url_prefix=url_prefix,
        blueprint_name="tutorials",
    )

    @app.route(url_prefix)
    def index():
        page = flask.request.args.get("page", default=1, type=int)
        posts_per_page = 12
        discourse_docs.parser.parse()
        metadata = discourse_docs.parser.metadata
        total_pages = math.ceil(len(metadata) / posts_per_page)

        return flask.render_template(
            "tutorials/index.html",
            navigation=discourse_docs.parser.navigation,
            forum_url=discourse_docs.parser.api.base_url,
            metadata=metadata,
            page=page,
            posts_per_page=posts_per_page,
            total_pages=total_pages,
            active_section="tutorials",
        )

    discourse_docs.init_app(app)
Esempio n. 3
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"),
    )
Esempio n. 4
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"
        ),
    )
Esempio n. 5
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"),
    )
Esempio n. 6
0
def init_tutorials(app, url_prefix):
    discourse_docs = DiscourseDocs(
        parser=DocParser(
            api=DiscourseAPI(
                base_url="https://forum.snapcraft.io/",
                session=talisker.requests.get_session(),
            ),
            index_topic_id=15409,
            category_id=20,
            url_prefix=url_prefix,
        ),
        document_template="tutorials/tutorial.html",
        url_prefix=url_prefix,
        blueprint_name="tutorials",
    )

    @app.route(url_prefix)
    def tutorials():
        page = flask.request.args.get("page", default=1, type=int)
        posts_per_page = 12
        discourse_docs.parser.parse()
        metadata = discourse_docs.parser.metadata
        total_pages = math.ceil(len(metadata) / posts_per_page)

        return flask.render_template(
            "tutorials/index.html",
            navigation=discourse_docs.parser.navigation,
            forum_url=discourse_docs.parser.api.base_url,
            metadata=metadata,
            page=page,
            posts_per_page=posts_per_page,
            total_pages=total_pages,
            page_slug="tutorials",
        )

    discourse_docs.init_app(app)
Esempio n. 7
0
from webapp.feeds import get_rss_feed

app = FlaskBase(
    __name__,
    "maas.io",
    template_folder="../templates",
    static_folder="../static",
)

template_finder_view = TemplateFinder.as_view("template_finder")
app.add_url_rule("/", view_func=template_finder_view)
app.add_url_rule("/<path:subpath>", view_func=template_finder_view)

doc_parser = DocParser(
    api=DiscourseAPI(base_url="https://discourse.maas.io/"),
    index_topic_id=25,
    url_prefix="/docs",
)
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",
Esempio n. 8
0
# All other routes
template_finder_view = TemplateFinder.as_view("template_finder")
app.add_url_rule("/", view_func=template_finder_view)
app.add_url_rule("/snaps", view_func=search_snaps)
app.add_url_rule("/core/build", view_func=build)
app.add_url_rule("/core/build", view_func=post_build, methods=["POST"])
app.add_url_rule(
    "/core/build/notify", view_func=notify_build, methods=["POST"]
)
app.add_url_rule("/<path:subpath>", view_func=template_finder_view)

url_prefix = "/server/docs"
server_docs = DiscourseDocs(
    parser=DocParser(
        api=discourse_api,
        category_id=26,
        index_topic_id=11322,
        url_prefix=url_prefix,
    ),
    document_template="/docs/document.html",
    url_prefix=url_prefix,
)
server_docs.init_app(app)

# Allow templates to be queried from discourse.ubuntu.com
app.add_url_rule(
    "/templates/<filename>",
    "templates",
    lambda filename: (
        flask.render_template(f"templates/{filename}.html"),
        {"Access-Control-Allow-Origin": "*"},
    ),
Esempio n. 9
0
    __name__,
    "maas.io",
    template_folder="../templates",
    static_folder="../static",
)

template_finder_view = TemplateFinder.as_view("template_finder")
app.add_url_rule("/", view_func=template_finder_view)
app.add_url_rule("/<path:subpath>", view_func=template_finder_view)

session = talisker.requests.get_session()
docs_discourse_api = DiscourseAPI(base_url="https://discourse.maas.io/",
                                  session=session)
doc_parser = DocParser(
    api=docs_discourse_api,
    index_topic_id=25,
    category_id=5,
    url_prefix="/docs",
)
if app.debug:
    doc_parser.api.session.adapters["https://"].timeout = 99
discourse_docs = DiscourseDocs(
    parser=doc_parser,
    document_template="docs/document.html",
    url_prefix="/docs",
)
discourse_docs.init_app(app)

# Search
app.add_url_rule(
    "/docs/search",
    "docs-search",
Esempio n. 10
0
                 methods=["POST"])
app.add_url_rule("/security/notices/<notice_id>", view_func=notice)

# Login
app.add_url_rule("/login", methods=["GET", "POST"], view_func=login_handler)
app.add_url_rule("/logout", view_func=logout)

# All other routes
template_finder_view = TemplateFinder.as_view("template_finder")
app.add_url_rule("/", view_func=template_finder_view)
app.add_url_rule("/<path:subpath>", view_func=template_finder_view)

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

# Allow templates to be queried from discourse.ubuntu.com
app.add_url_rule(
    "/templates/<filename>",
    "templates",
    lambda filename: (
        flask.render_template(f"templates/{filename}.html"),
        {
Esempio n. 11
0
app.add_url_rule(
    "/blog/<regex('cloud-and-server|desktop|internet-of-things'):slug>",
    view_func=blog_custom_group,
)
app.add_url_rule("/blog/press-centre", view_func=blog_press_centre)
app.register_blueprint(blog_blueprint, url_prefix="/blog")

# Login
app.add_url_rule("/login", methods=["GET", "POST"], view_func=login_handler)
app.add_url_rule("/logout", view_func=logout)

# All other routes
template_finder_view = TemplateFinder.as_view("template_finder")
app.add_url_rule("/", view_func=template_finder_view)
app.add_url_rule("/<path:subpath>", view_func=template_finder_view)

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

server_docs.init_app(app)
Esempio n. 12
0
    def setUp(self):
        """
        Set up Flask app with DiscourseDocs extension for testing
        And set up mocking for discourse.example.com
        """

        # Suppress annoying warnings from HTTPretty
        # See: https://github.com/gabrielfalcao/HTTPretty/issues/368
        warnings.filterwarnings("ignore",
                                category=ResourceWarning,
                                message="unclosed.*")

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

        template_folder = f"{this_dir}/fixtures/templates"

        app = flask.Flask("main", template_folder=template_folder)
        app_no_nav = flask.Flask("no-nav", template_folder=template_folder)
        app_no_mappings = flask.Flask("no-mappings",
                                      template_folder=template_folder)
        app_broken_mappings = flask.Flask("broken-mappings",
                                          template_folder=template_folder)

        app.testing = True
        app_no_nav.testing = True
        app_no_mappings.testing = True
        app_broken_mappings.testing = True

        discourse_api = DiscourseAPI(base_url="https://discourse.example.com/")
        discourse_parser = DocParser(discourse_api, 34, "/")
        DiscourseDocs(
            parser=discourse_parser,
            category_id=2,
            document_template="document.html",
            url_prefix="/",
        ).init_app(app)

        discourse_api = DiscourseAPI(base_url="https://discourse.example.com/")
        discourse_parser = DocParser(discourse_api, 42, "/")
        DiscourseDocs(
            parser=discourse_parser,
            category_id=2,
            document_template="document.html",
            url_prefix="/",
        ).init_app(app_no_nav)

        discourse_api = DiscourseAPI(base_url="https://discourse.example.com/")
        discourse_parser = DocParser(discourse_api, 35, "/")
        DiscourseDocs(
            parser=discourse_parser,
            category_id=2,
            document_template="document.html",
            url_prefix="/",
        ).init_app(app_no_mappings)

        discourse_api = DiscourseAPI(base_url="https://discourse.example.com/")
        discourse_parser = DocParser(discourse_api, 36, "/")
        DiscourseDocs(
            parser=discourse_parser,
            category_id=2,
            document_template="document.html",
            url_prefix="/",
        ).init_app(app_broken_mappings)

        self.client = app.test_client()
        self.client_no_nav = app_no_nav.test_client()
        self.client_no_mappings = app_no_mappings.test_client()
        self.client_broken_mappings = app_broken_mappings.test_client()
Esempio n. 13
0
@app.after_request
def no_cache(response):
    if request.path == "/static/latest-release.json":
        response.cache_control.max_age = None
        response.cache_control.no_store = True
        response.cache_control.public = False

    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",
Esempio n. 14
0
# Rename your project below
app = FlaskBase(
    __name__,
    "microk8s.io",
    template_folder="../templates",
    static_folder="../static",
    template_404="404.html",
    template_500="500.html",
)


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


url_prefix = "/docs"
server_docs_parser = DocParser(
    api=DiscourseAPI(base_url="https://discourse.ubuntu.com/"),
    category_id=41,
    index_topic_id=15536,
    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)
Esempio n. 15
0
)

# Rename your project below
app = FlaskBase(
    __name__,
    "microk8s.io",
    template_folder="../templates",
    static_folder="../static",
    template_404="404.html",
    template_500="500.html",
)

session = talisker.requests.get_session()
doc_parser = DocParser(
    api=DiscourseAPI(base_url="https://discuss.kubernetes.io/",
                     session=session),
    index_topic_id=11243,
    url_prefix="/docs",
)
if app.debug:
    doc_parser.api.session.adapters["https://"].timeout = 99
discourse_docs = DiscourseDocs(
    parser=doc_parser,
    document_template="docs/document.html",
    url_prefix="/docs",
)
discourse_docs.init_app(app)


@app.route("/")
def index():
    return render_template("index.html")
Esempio n. 16
0
# Rename your project below
app = FlaskBase(
    __name__,
    "charmed-kubeflow.io",
    template_folder="../templates",
    static_folder="../static",
    template_404="404.html",
    template_500="500.html",
)
session = talisker.requests.get_session()


doc_parser = DocParser(
    api=DiscourseAPI(base_url="https://discourse.juju.is/", session=session),
    index_topic_id=3749,
    url_prefix="/docs",
)

if app.debug:
    doc_parser.api.session.adapters["https://"].timeout = 99

discourse_docs = DiscourseDocs(
    parser=doc_parser,
    document_template="docs/document.html",
    url_prefix="/docs",
)
discourse_docs.init_app(app)


@app.context_processor
Esempio n. 17
0
from flask import render_template

# Rename your project below
app = FlaskBase(
    __name__,
    "dqlite.io",
    template_folder="../templates",
    static_folder="../static",
    template_404="404.html",
    template_500="500.html",
)
session = talisker.requests.get_session()

doc_parser = DocParser(
    api=DiscourseAPI(base_url="https://discourse.dqlite.io/", session=session),
    index_topic_id=21,
    category_id=5,
    url_prefix="/docs",
)

if app.debug:
    doc_parser.api.session.adapters["https://"].timeout = 99

discourse_docs = DiscourseDocs(
    parser=doc_parser,
    document_template="docs/document.html",
    url_prefix="/docs",
)
discourse_docs.init_app(app)


@app.route("/")
Esempio n. 18
0
    "multipass.run",
    template_folder="../templates",
    static_folder="../static",
    template_404="404.html",
    template_500="500.html",
)


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


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

server_docs.init_app(app)
Esempio n. 19
0
    template_404="404.html",
    template_500="500.html",
)

app.secret_key = os.environ["SECRET_KEY"]
open_id = OpenID(stateless=True,
                 safe_roots=[],
                 extension_responses=[MacaroonResponse])

# Discourse docs
session = talisker.requests.get_session()

discourse_docs = DiscourseDocs(
    parser=DocParser(
        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)


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,
Esempio n. 20
0
from webapp.feeds import get_rss_feed

app = FlaskBase(
    __name__,
    "maas.io",
    template_folder="../templates",
    static_folder="../static",
)

template_finder_view = TemplateFinder.as_view("template_finder")
app.add_url_rule("/", view_func=template_finder_view)
app.add_url_rule("/<path:subpath>", view_func=template_finder_view)

doc_parser = DocParser(
    api=DiscourseAPI(base_url="https://discourse.maas.io/"),
    index_topic_id=25,
    category_id=5,
    url_prefix="/docs",
)
if app.debug:
    doc_parser.api.session.adapters["https://"].timeout = 99
discourse_docs = DiscourseDocs(
    parser=doc_parser,
    document_template="docs/document.html",
    url_prefix="/docs",
)
discourse_docs.init_app(app)

# Search
app.add_url_rule(
    "/docs/search",
    "docs-search",