Skip to main content

Flask extension to add a nice blog to your website

Project description

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],
        per_page=12,
        feed_description="The Ubuntu Blog Feed",
        api=BlogAPI(
            session=session,
            use_image_template=True,
            thumbnail_width=330,
            thumbnail_height=185,
        ),
    )
)

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.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

canonicalwebteam_blog-6.8.4.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

canonicalwebteam_blog-6.8.4-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

Details for the file canonicalwebteam_blog-6.8.4.tar.gz.

File metadata

  • Download URL: canonicalwebteam_blog-6.8.4.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for canonicalwebteam_blog-6.8.4.tar.gz
Algorithm Hash digest
SHA256 a6470b5a4b8f821e99206569f18185d8298e3a1b2b2e1ab684a9f1a281fe1f08
MD5 9f74a6c2ed2cba4eec7c9091813420b2
BLAKE2b-256 f44e3b8a7cd0c817bea047ff01ba18f56e13958162e16e42d7073421e8466214

See more details on using hashes here.

File details

Details for the file canonicalwebteam_blog-6.8.4-py3-none-any.whl.

File metadata

File hashes

Hashes for canonicalwebteam_blog-6.8.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a93053cf4e3d01349061d4e8928ef2162313154451b8604635e8cb90603daf16
MD5 39d7f75a8b8fc0b78cdf8557a74dab90
BLAKE2b-256 d477ca7189e66793e9facdde7d16b37d065c86481419155c044442c37cb787a5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page