Skip to main content

Canonical blog extension

This extension allows you to add a simple frontend section to your flask app. All the articles are pulled from Canonical's Wordpress back-end through the JSON API.

This extension provides a blueprint with 3 routes:

  • "/": that returns the list of articles
  • "/": the article page
  • "/feed": provides a RSS feed for the page.

Installation

To install this extension as a requirement in your project, you can use PIP;

pip3 install canonicalwebteam.blog

See also the documentation for pip install.

Usage

Local development

For local development, it's best to test this module with one of our website projects like ubuntu.com. For more information, follow this guide (internal only).

How to run tests?

  • Create a virtual environment
  • Install required python dependencies from test-requirements.txt
  • Activate virtual environment and run python3 -m unittest discover tests

How to lint :

  • To check python lint python3 -m flake8 canonicalwebteam setup.py && python3 -m black --line-length 79 --check canonicalwebteam setup.py
  • To run python reformatting python3 -m flake8 canonicalwebteam setup.py && python3 -m black --line-length 79 canonicalwebteam setup.py

Templates

The module expects HTML templates at blog/index.html, blog/article.html, blog/blog-card.html, blog/archives.html, blog/upcoming.html and blog/author.html.

An example of these templates can be found at https://github.com/canonical-websites/jp.ubuntu.com/tree/master/templates/blog.

Usage

In your app you can then do the following:

import flask
import talisker.requests
from flask_reggie import Reggie
from canonicalwebteam.blog import BlogViews, build_blueprint, BlogAPI

app = flask.Flask(__name__)
Reggie().init_app(app)
session = talisker.requests.get_session()

blog = build_blueprint(
    BlogViews(
        api=BlogAPI(session=session),
    )
)
app.register_blueprint(blog, url_prefix="/blog")

You can customise the blog through the following optional arguments:

blog = build_blueprint(
    BlogViews(
        blog_title="Blog",
        blog_path="blog",
        tag_ids=[1, 12, 112],
        excluded_tags=[26, 34],
        category_ids=[4877],
        featured_category_ids=[4881],
        per_page=12,
        feed_description="The Ubuntu Blog Feed",
        api=BlogAPI(
            session=session,
            use_image_template=True,
            thumbnail_width=330,
            thumbnail_height=185,
        ),
    )
)

category_ids scopes the whole blog to one or more categories: it is ANDed into every query, including article detail and related articles, so a post outside it returns 404.

featured_category_ids is ORed into the featured articles query and the single-article lookup. Use it to surface pinned posts from a category the site does not otherwise carry — for example ubuntu.com/blog featuring pinned announcements. Because the main article list keeps the narrower category_ids scope, such a post leaves the page once a newer pinned post displaces it from the featured panel, rather than descending into the list. The single-article lookup honours it so the featured link does not 404; related articles stay scoped to category_ids.

Testing

All tests can be run with ./setup.py test.

Regenerating Fixtures

All API calls are caught with VCR and saved as fixtures in the fixtures directory. If the API updates, all fixtures can easily be updated by just removing the fixtures directory and rerunning the tests.

To do this run rm -rf fixtures && ./setup.py test.

Release files for canonicalwebteam.blog 7.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for canonicalwebteam.blog 7.4.0
File Size Uploaded
canonicalwebteam_blog-7.4.0.tar.gz 21.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for canonicalwebteam.blog 7.4.0
File Interpreter ABI Platform
canonicalwebteam_blog-7.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 46.1 kB

Release files / canonicalwebteam_blog-7.4.0.tar.gz

Download URL canonicalwebteam_blog-7.4.0.tar.gz
Size 21.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d692547b346222a4680febcc5bb3ae26e30fe59b448b0c587f6ed6a1c81a0bdb
BLAKE2b-256 checksum
How to use checksums
27cf85d15c1b983a4a86a5c1d6c700e5b1396b663cb39f71b5225fbca2b1160c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / canonicalwebteam_blog-7.4.0-py3-none-any.whl

Download URL canonicalwebteam_blog-7.4.0-py3-none-any.whl
Size 24.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
27dbf0e7045b2a5d1e398aa2d77538c4b1e5ea51b761b75d213a97a12ee5c649
BLAKE2b-256 checksum
How to use checksums
814269e7466df3b22a1c071794e94e37886e13c1a424fe1b8ffeade690cda1bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

7.4.0 This release

2 release files

7.3.1

2 release files

7.3.0

2 release files

7.2.0

2 release files

7.1.0

2 release files

7.0.0

2 release files

6.8.4

2 release files

6.8.3

2 release files

6.8.2

2 release files

6.8.1

2 release files

6.8.0

2 release files

6.7.0

2 release files

6.6.0

2 release files

6.5.0

2 release files

6.4.6

2 release files

6.4.5

2 release files

6.4.4

3 release files

6.4.3

2 release files

6.4.2

2 release files

6.4.1

2 release files

6.4.0

2 release files

6.3.1

2 release files

6.3.0

2 release files

6.2.6

2 release files

6.2.5

2 release files

6.2.4

2 release files

6.2.3

2 release files

6.2.2

2 release files

6.2.1

2 release files

6.2.0

2 release files

6.1.1

2 release files

6.1.0

2 release files

6.0.0

2 release files

5.0.0

2 release files

4.0.2

2 release files

4.0.1

2 release files

4.0.0

2 release files

3.1.2

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.4.1

2 release files

2.4.0

2 release files

2.3.0

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.12

2 release files

2.0.11

2 release files

2.0.10

2 release files

2.0.9

2 release files

2.0.8

2 release files

2.0.7

2 release files

2.0.6

2 release files

2.0.5

2 release files

2.0.4

2 release files

2.0.3

1 release file

2.0.2

1 release file

2.0.1

1 release file

2.0.0

1 release file

1.5.15

1 release file

1.5.14

1 release file

1.5.13

1 release file

1.5.12

1 release file

1.5.11

1 release file

1.5.10

1 release file

1.5.9

1 release file

1.5.8

1 release file

1.5.7

1 release file

1.5.6

1 release file

1.5.5

1 release file

1.5.4

1 release file

1.5.3

1 release file

1.5.2

1 release file

1.5.1

1 release file

1.5.0

1 release file

1.3.5

1 release file

1.3.4

1 release file

1.3.3

1 release file

1.3.2

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.0

1 release file

1.1.0

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page