Skip to main content

Control who can view your djangocms-blog posts

Project description

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 %}

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_view_restrictions-0.3.0.tar.gz (18.9 kB view hashes)

Uploaded Source

Built Distribution

Supported by

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