Expiry date extension for django CMS blog posts (expired in template context).
Project description
djangocms-blog-expiry-date
Extension for django CMS blog that adds an optional expiry date per post.
Installation
-
Install the package:
python3 -m pip install djangocms-blog-expiry-date
-
Add it to
INSTALLED_APPS:"djangocms_blog_expiry_date",
-
Run migrations:
python3 manage.py migrate djangocms_blog_expiry_date
-
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:
Trueif an extension linked toposthas_meta.app_label == 'djangocms_blog_expiry_date'andis_expired()isTruefor that instance.FalseifpostisNone, there is no such extension,expiry_dateis 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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file djangocms_blog_expiry_date-0.0.3.tar.gz.
File metadata
- Download URL: djangocms_blog_expiry_date-0.0.3.tar.gz
- Upload date:
- Size: 23.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bafcd543c43613d20c6fe6cb7503542f464126c9fbf94822b1c8d9eb12f077dd
|
|
| MD5 |
6f22a6c7699576579e5c28e615b6f64d
|
|
| BLAKE2b-256 |
212e95a866419e99c27f20c32b9af7ff25fa2dcebaa0f3062baf520db76d8656
|
File details
Details for the file djangocms_blog_expiry_date-0.0.3-py3-none-any.whl.
File metadata
- Download URL: djangocms_blog_expiry_date-0.0.3-py3-none-any.whl
- Upload date:
- Size: 25.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88a96cf956a8ee9b98af36603d35dad6c2bc91a5db6efc2e2ee35e8762fbb02c
|
|
| MD5 |
b9e73aada079c21fe46b6df7c435f2f7
|
|
| BLAKE2b-256 |
1b443d5d46abee61e5800dd8ca9a76efe0889fbb6dc28daaf1d47bded23ace6a
|