Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions djangocms_inline_comment/cms_plugins.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from django.utils.translation import ugettext_lazy as _

from cms.plugin_base import CMSPluginBase
from cms.plugin_base import CMSPluginBase, PluginMenuItem
from cms.plugin_pool import plugin_pool

from cms.utils.urlutils import admin_reverse
from django.conf.urls import url
from django.http import HttpResponseForbidden, HttpResponseBadRequest, HttpResponse
from django.middleware.csrf import get_token
from djangocms_inline_comment.models import InlineComment


Expand All @@ -12,5 +15,40 @@ class InlineCommentPlugin(CMSPluginBase):
render_template = "djangocms_inline_comment/inline_comment.html"
allow_children = True

def get_extra_local_plugin_menu_items(self, request, plugin):
return [
PluginMenuItem(
_("Hide contents (currently visible)") if plugin.show_contents else _("Show contents (currently hidden)"),
admin_reverse("djangocms_inline_comment_change_show_contents"),
data={
'plugin_id': plugin.pk,
'show_contents': '0' if plugin.show_contents else '1',
'csrfmiddlewaretoken': get_token(request),
},
)
]

def get_plugin_urls(self):
return [
url(r'^change_show_contents/$', self.change_show_contents, name='djangocms_inline_comment_change_show_contents'),
]

def change_show_contents(self, request):
if not request.user.is_staff:
return HttpResponseForbidden("not enough privileges")
if not 'plugin_id' in request.POST or not 'show_contents' in request.POST:
return HttpResponseBadRequest("plugin_id and show_contents POST parameter missing.")
plugin = None
if 'plugin_id' in request.POST:
pk = request.POST['plugin_id']
try:
plugin = self.model.objects.get(pk=pk)
except CMSPlugin.DoesNotExist:
return HttpResponseBadRequest("plugin with id %s not found." % pk)
show_contents = bool(int(request.POST['show_contents']))
plugin.show_contents = show_contents
plugin.save(update_fields=['show_contents'])
return HttpResponse("ok")


plugin_pool.register_plugin(InlineCommentPlugin)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('djangocms_inline_comment', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='inlinecomment',
name='show_contents',
field=models.BooleanField(default=False, verbose_name='Show Contents'),
),
]
2 changes: 2 additions & 0 deletions djangocms_inline_comment/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.conf import settings
from django.db import models
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _

Expand All @@ -20,6 +21,7 @@ def _get_html_field_class():

class InlineComment(CMSPlugin):
body = _get_html_field_class()(_("Comment"), null=True, blank=True)
show_contents = models.BooleanField(_("Show Contents"), default=False)

def get_short_description(self):
if not self.body:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
{% load sekizai_tags cms_tags %}{% if request.toolbar.edit_mode %}
{# Code is only rendered in edit mode #}
{% load sekizai_tags cms_tags %}

{% comment %} CMS needs render_plugin to be called, but the plugins should not be
anywhere in the page. So we use a sekizai block which is never rendered {% endcomment %}
{% addtoblock "null" %}
<div class="plugin parent">
{% if request.toolbar.edit_mode %}
{% include 'djangocms_inline_comment/inline_comment_style.html' %}
{% endif %}

{% if request.toolbar.edit_mode and not instance.show_contents %}
{# Code is only rendered in edit mode #}

{% comment %} CMS needs render_plugin to be called, but the plugins should not be
anywhere in the page. So we use a sekizai block which is never rendered {% endcomment %}
{% addtoblock "null" %}
<div class="plugin parent">
{% for plugin in instance.child_plugin_instances %}
{% render_plugin plugin %}
{% endfor %}
</div>
{% endaddtoblock "null" %}

{% addtoblock "css" %}
{% endaddtoblock %}
{% elif instance.show_contents %}
{% for plugin in instance.child_plugin_instances %}
{% render_plugin plugin %}
{% endfor %}
</div>
{% endaddtoblock "null" %}

{% addtoblock "css" %}
{% include 'djangocms_inline_comment/inline_comment_style.html' %}
{% endaddtoblock %}{% endif %}
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
<style>
/* Styles for inline comment draggable */
div.cms .cms-structure .cms-draggable-{{ instance.pk|unlocalize }} > .cms-dragitem {
background: transparent;
{% if instance.show_contents %}
opacity: 0.6;
{% else %}
background: transparent;
{% endif %}
}

.cms-draggable-{{ instance.pk|unlocalize }} > .cms-dragitem > .cms-dragitem-text > strong {
Expand All @@ -16,6 +20,6 @@

/* Styles for other plugins' draggables nested inside */
div.cms .cms-structure .cms-draggable-{{ instance.pk|unlocalize }} .cms-dragitem-text {
opacity: 0.7;
opacity: 0.6;
}
</style>