Skip to main content

Control who can view your djangocms blog posts


Install

  • Install the package

    python3 -m pip install djangocms-blog-view-restrictions
    
  • Add it in your INSTALLED_APPS:

    "djangocms_blog_view_restrictions",
    
  • Run the migration:

    python3 manage.py migrate djangocms_blog_view_restrictions
    

Usage

When creating/editing a blog post, a new "View restriction" section allows you to define multiple users/groups that are allowed to view the post. The user is allowed to view the post if any of the restrictions are met.

You are then responsible to hide partially or totally the post's content in your djangocms_blog/post_detail.html template:

{% extends "djangocms_blog/post_detail.html" %}
{% load blog_view_restrictions_tags %}


{% block content_blog %}
  <article>
    {{ post.abstract }}

    {% if request.user|can_view_post:post %}
      {% if post.app_config.use_placeholder %}
        <div class="blog-content">{% render_placeholder post.content %}</div>
      {% else %}
        <div class="blog-content">{% render_model post "post_text" "post_text" "" "safe" %}</div>
      {% endif %}
    {% else %}
      This post is for subscribers only.
    {% endif %}

    ...

  </article>
{% endblock content_blog %}

Metadata

Release files for djangocms-blog-view-restrictions 0.3.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 djangocms-blog-view-restrictions 0.3.0
File Size Uploaded
djangocms_blog_view_restrictions-0.3.0.tar.gz 18.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for djangocms-blog-view-restrictions 0.3.0
File Interpreter ABI Platform
djangocms_blog_view_restrictions-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 39.4 kB

Release files / djangocms_blog_view_restrictions-0.3.0.tar.gz

Download URL djangocms_blog_view_restrictions-0.3.0.tar.gz
Size 18.9 kB
Tags Source
SHA-256 checksum
How to use checksums
eb593733b4184b6a5c82d33cf34c8bde6d85a0e662b24203fa579325a0430327
BLAKE2b-256 checksum
How to use checksums
825f83298bb46a825f7e2c7784704f3a3377c32545ee41841f867436ce7232f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.8

Release files / djangocms_blog_view_restrictions-0.3.0-py3-none-any.whl

Download URL djangocms_blog_view_restrictions-0.3.0-py3-none-any.whl
Size 20.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ae0647ef8aceffcf4c4b5c1c381245c16bc3e54964a1ca163b096307664efd14
BLAKE2b-256 checksum
How to use checksums
6452263c61805d523622eb9d3741c76c49d8f6a1fc6d2c9c32e84699c21c272d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.8

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

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