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)
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"), )
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"), )
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" ), )
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"), )
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)
) 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)
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(
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) 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)
view_func=api_create_notice, 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: (
import flask from canonicalwebteam.yaml_responses.flask_helpers import ( prepare_deleted, prepare_redirects, ) from canonicalwebteam.discourse_docs import DiscourseAPI, DiscourseDocs from canonicalwebteam.discourse_docs.parsers import parse_index app = flask.Flask(__name__) app.template_folder = "../templates" app.static_folder = "../static" app.url_map.strict_slashes = False discourse_index_id = 1087 discourse_api = DiscourseAPI(base_url="https://discourse.jujucharms.com/") discourse_docs = DiscourseDocs( api=discourse_api, index_topic_id=discourse_index_id, category_id=22, document_template="document.html", ) discourse_docs.init_app(app, url_prefix="/") # Parse redirects.yaml and permanent-redirects.yaml app.before_request(prepare_redirects()) def deleted_callback(context): index = parse_index(discourse_api.get_topic(discourse_index_id))
"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)
DocParser, DiscourseAPI, ) # Rename your project below app = FlaskBase( __name__, "dqlite.io", template_folder="../templates", static_folder="../static", template_404="404.html", template_500="500.html", ) doc_parser = DocParser( api=DiscourseAPI(base_url="https://discourse.dqlite.io/"), 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("/")
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()
DiscourseAPI, ) # 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():
from flask import render_template # 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)
static_folder="../static", 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(
app.config["SEARCH_API_KEY"] = os.getenv("SEARCH_API_KEY") app.config["SEARCH_API_URL"] = "https://www.googleapis.com/customsearch/v1" app.config["SEARCH_CUSTOM_ID"] = "009048213575199080868:i3zoqdwqk8o" app.template_folder = "../templates" app.static_folder = "../static" app.url_map.strict_slashes = False app.wsgi_app = ProxyFix(app.wsgi_app) talisker.flask.register(app) talisker.logs.set_global_extra({"service": "docs.snapcraft.io"}) discourse_index_id = 11127 discourse_api = DiscourseAPI(base_url="https://forum.snapcraft.io/") discourse_docs = DiscourseDocs( api=discourse_api, index_topic_id=discourse_index_id, category_id=15, document_template="document.html", ) discourse_docs.init_app(app, url_prefix="/") # Parse redirects.yaml and permanent-redirects.yaml app.before_request(prepare_redirects()) def deleted_callback(context): index = parse_index(discourse_api.get_topic(discourse_index_id))