Skip to main content

Expiry date extension for django CMS blog posts (expired in template context).

Project description

djangocms-blog-expiry-date

djangoCMS blog expiry date logo

Extension for django CMS blog that adds an optional expiry date per post.


Installation

  1. Install the package:

    python3 -m pip install djangocms-blog-expiry-date
    
  2. Add it to INSTALLED_APPS:

        "djangocms_blog_expiry_date",
    
  3. Run migrations:

    python3 manage.py migrate djangocms_blog_expiry_date
    
  4. Update your templates to load the templatetag, and use it to test if the post is expired

    {% load djangocms_blog_expiry_date_tags %}
    
    {% post_expiry_expired post as post_expired %}
    {% if post_expired %}
      {# show a notice, or hide booking links, etc. #}
    {% endif %}
    

Behaviour

post_expiry_expired (Python)

djangocms_blog_expiry_date.utils.post_expiry_expired(post) returns:

  • True if an extension linked to post has _meta.app_label == 'djangocms_blog_expiry_date' and is_expired() is True for that instance.
  • False if post is None, there is no such extension, expiry_date is empty, or the date is still in the future.

Extensions whose model belongs to another app are ignored (so several extension types can coexist on the same post).

Template tag

Load the tag library, assign the result, then branch (simple tags must use the as form to work inside {% if %}):

{% load djangocms_blog_expiry_date_tags %}

{% post_expiry_expired post as post_expired %}
{% if post_expired %}
  {# show a notice or hide booking links, etc. #}
{% endif %}

This uses the same rules as post_expiry_expired() above.

Calling is_expired on a single extension

If you know the extension is this app’s model (e.g. only one extension type), you can still use:

{% with ext=post.extension.first %}
  {% if ext and ext.is_expired %}

  {% endif %}
{% endwith %}

Optional settings

Multisite

With BLOG_MULTISITE = True, the app registers a get_sites function on the user model (see apps.py), using django CMS global page permissions.


Tests

Install test dependencies using the following commands:

python3 -m venv .venv
. .venv/bin/activate
python3 -m pip install -e ".[test]"

Launch tests using these commands:

. .venv/bin/activate
pytest

Project details


Download files

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

Source Distribution

djangocms_blog_expiry_date-0.0.3.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

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

djangocms_blog_expiry_date-0.0.3-py3-none-any.whl (25.3 kB view details)

Uploaded Python 3

File details

Details for the file djangocms_blog_expiry_date-0.0.3.tar.gz.

File metadata

File hashes

Hashes for djangocms_blog_expiry_date-0.0.3.tar.gz
Algorithm Hash digest
SHA256 bafcd543c43613d20c6fe6cb7503542f464126c9fbf94822b1c8d9eb12f077dd
MD5 6f22a6c7699576579e5c28e615b6f64d
BLAKE2b-256 212e95a866419e99c27f20c32b9af7ff25fa2dcebaa0f3062baf520db76d8656

See more details on using hashes here.

File details

Details for the file djangocms_blog_expiry_date-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for djangocms_blog_expiry_date-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 88a96cf956a8ee9b98af36603d35dad6c2bc91a5db6efc2e2ee35e8762fbb02c
MD5 b9e73aada079c21fe46b6df7c435f2f7
BLAKE2b-256 1b443d5d46abee61e5800dd8ca9a76efe0889fbb6dc28daaf1d47bded23ace6a

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