Metadata-Version: 2.4
Name: djangocms-blog-expiry-date
Version: 0.0.3
Summary: Expiry date extension for django CMS blog posts (expired in template context).
Home-page: https://gitlab.com/kapt/open-source/djangocms-blog-expiry-date
Author: Corentin Bettiol, Adrien Delhorme
Author-email: dev@kapt.mobi
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django CMS
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: AUTHORS.md
Requires-Dist: djangocms-blog<2
Requires-Dist: aldryn-apphooks-config
Requires-Dist: django-appdata
Provides-Extra: test
Requires-Dist: django-cms<4; extra == "test"
Requires-Dist: django-treebeard<5,>=4.5; extra == "test"
Requires-Dist: pytest-cov>=4.0.0; extra == "test"
Requires-Dist: coverage>=7.0.0; extra == "test"
Requires-Dist: pytest>=7.0.0; extra == "test"
Requires-Dist: pytest-django>=4.5.2; extra == "test"
Requires-Dist: pytest-cov>=4.0.0; extra == "test"
Requires-Dist: django-treebeard<5,>=4.5; extra == "test"
Dynamic: license-file

# djangocms-blog-expiry-date

<div align="center">
  <img src="logo.png" alt="djangoCMS blog expiry date logo">
</div>

Extension for [django CMS blog](https://github.com/nephila/djangocms-blog) that adds an optional **expiry date** per post.

----

## Installation

1) Install the package:
    ```bash
    python3 -m pip install djangocms-blog-expiry-date
    ```

2) Add it to `INSTALLED_APPS`:
    ```python
        "djangocms_blog_expiry_date",
    ```

3) Run migrations:
    ```sh
    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
    ```django
    {% 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 %}`):

```django
{% 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:

```django
{% 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:

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

Launch tests using these commands:

```bash
. .venv/bin/activate
pytest
```
