Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Adds cms 2.4 & 3.x compatibility. #9

Merged
merged 4 commits into from

2 participants

@czpython
Collaborator

Adds ckeditor support.
Drops django < 1.4 support.
PEP 8 cleanup.

@KristianOellegaard

@czpython added you as a collaborator - have fun :dancers:

@czpython
Collaborator

@KristianOellegaard thanks. pypi ?

@czpython
Collaborator

Fixes #7 #8

@czpython czpython merged commit c88a880 into KristianOellegaard:master
@KristianOellegaard

What is your pypi username?

@czpython
Collaborator

czpython :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 20, 2013
  1. @czpython

    Adds cms 2.4 & 3.x compatibility.

    czpython authored
    Drops django < 1.4 support.
    PEP 8 cleanup.
  2. @czpython

    version bump to 0.4

    czpython authored
Commits on Dec 21, 2013
  1. @czpython

    updates README

    czpython authored
  2. @czpython
This page is out of date. Refresh to see the latest.
View
3  CONTRIBUTORS
@@ -1,3 +1,4 @@
Marco Bonetti
Kristian Øllegaard
-Benjamin Wohlwend
+Benjamin Wohlwend
+Paulo Alvarado
View
10 README.rst
@@ -10,8 +10,16 @@ the text plugin inside a template selectable by the CMS content editor.
probably still use ``cms.plugins.text`` or write a specifically tailored
plugin.
+Requirements
+------------
+
+* Django 1.4+
+* Django CMS 2.3+
+* djangocms-text-ckeditor (only if using cms 3+)
+
+
Installation
-============
+------------
* Add ``cmsplugin_text_ng`` to your ``INSTALLED_APPS``.
* Create some templates (more on that soon) and add them in the admin.
View
2  cmsplugin_text_ng/__init__.py
@@ -1 +1 @@
-__version__ = '0.3'
+__version__ = '0.4'
View
6 cmsplugin_text_ng/admin.py
@@ -1,6 +1,8 @@
-from cmsplugin_text_ng.models import TextNGTemplate, TextNGTemplateCategory
from django.contrib import admin
+from cmsplugin_text_ng.models import TextNGTemplate, TextNGTemplateCategory
+
+
class TextNGTemplateAdmin(admin.ModelAdmin):
list_display = ('title', 'category', 'path')
list_filter = ('category',)
@@ -8,4 +10,4 @@ class TextNGTemplateAdmin(admin.ModelAdmin):
admin.site.register(TextNGTemplate, TextNGTemplateAdmin)
-admin.site.register(TextNGTemplateCategory)
+admin.site.register(TextNGTemplateCategory)
View
38 cmsplugin_text_ng/cms_plugins.py
@@ -1,13 +1,13 @@
from collections import defaultdict
-from django import template
+from django.template.loader import get_template
from django.contrib.admin import StackedInline
from django.utils.translation import ugettext_lazy as _
from django.utils.safestring import mark_safe
-from cms.plugins.text.cms_plugins import TextPlugin
from cms.plugin_pool import plugin_pool
from cmsplugin_text_ng.forms import PluginAddForm, PluginEditForm
+from cmsplugin_text_ng.compat import TextPlugin
from cmsplugin_text_ng.models import TextNG
from cmsplugin_text_ng.utils import get_variables_from_template
@@ -37,29 +37,25 @@ def save_model(self, request, obj, form, change):
for label, variable in get_variables_from_template(obj.template.path).items():
variable['type'].objects.get_or_create(text_ng=obj, label=label)
- def change_view(self, request, object_id, extra_context=None):
- obj = self.get_object(request, object_id)
- types = defaultdict(lambda: 0)
- for label, variable in get_variables_from_template(obj.template.path).items():
- types[variable['type']] += 1
- variable['type'].objects.get_or_create(text_ng=obj, label=label)
- self.inline_instances = []
- self.inlines = []
- for model_class in types.keys():
- inline = self.get_inline_for_model(model_class)
- inline.max_num = types[model_class]
- self.inlines.append(inline)
- self.inline_instances.append(inline(self.model, self.admin_site))
- return super(TextPluginNextGeneration, self).change_view(request, object_id, extra_context)
+ def get_inline_instances(self, request, obj=None):
+ inline_instances = []
+
+ if obj and obj.pk:
+ types = defaultdict(lambda: 0)
+
+ for label, variable in get_variables_from_template(obj.template.path).items():
+ types[variable['type']] += 1
+ variable['type'].objects.get_or_create(text_ng=obj, label=label)
- def add_view(self, request, form_url='', extra_context=None):
- self.inlines = []
- self.inline_instances = []
- return super(TextPluginNextGeneration, self).add_view(request, form_url, extra_context)
+ for model_class in types.keys():
+ inline = self.get_inline_for_model(model_class)
+ inline.max_num = types[model_class]
+ inline_instances.append(inline(self.model, self.admin_site))
+ return inline_instances
def render(self, context, instance, placeholder):
context = super(TextPluginNextGeneration, self).render(context, instance, placeholder)
- t = template.loader.get_template(instance.template.path)
+ t = get_template(instance.template.path)
variables = get_variables_from_template(t)
for label, variable in variables.items():
model_type = variable['type']
View
12 cmsplugin_text_ng/compat.py
@@ -0,0 +1,12 @@
+from django.conf import settings
+from django.core.exceptions import ImproperlyConfigured
+
+if 'djangocms_text_ckeditor' in settings.INSTALLED_APPS:
+ from djangocms_text_ckeditor.models import AbstractText
+ from djangocms_text_ckeditor.cms_plugins import TextPlugin
+else:
+ try:
+ from cms.plugins.text.models import AbstractText
+ from cms.plugins.text.cms_plugins import TextPlugin
+ except ImportError:
+ raise ImproperlyConfigured('For django-cms >= 3 you need to install djangocms-text-ckeditor')
View
1  cmsplugin_text_ng/contrib/textng_filer/models.py
@@ -7,6 +7,7 @@
from cmsplugin_text_ng.models import TextNGVariableBase
from cmsplugin_text_ng.type_registry import register_type
+
class TextNGVariableFilerImage(TextNGVariableBase):
value = FilerImageField(null=True, blank=True, verbose_name=_('value'))
View
5 cmsplugin_text_ng/forms.py
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
-
from django import forms
+
from cmsplugin_text_ng.models import TextNG
+
class PluginAddForm(forms.ModelForm):
class Meta:
fields = ('template',)
@@ -12,4 +13,4 @@ class Meta:
class PluginEditForm(forms.ModelForm):
class Meta:
fields = ('body',)
- model = TextNG
+ model = TextNG
View
5 cmsplugin_text_ng/models.py
@@ -2,8 +2,7 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
-from cms.plugins.text.models import AbstractText
-
+from cmsplugin_text_ng.compat import AbstractText
from cmsplugin_text_ng.type_registry import register_type, get_type_list
@@ -73,4 +72,4 @@ class Meta:
verbose_name = _('text')
verbose_name_plural = _('texts')
-register_type('text', TextNGVariableText)
+register_type('text', TextNGVariableText)
View
4 cmsplugin_text_ng/type_registry.py
@@ -25,8 +25,10 @@ def register_type(type_name, model_class):
raise exceptions.InvalidType('"value" field of %s is not nullable' % model_class.__name__)
_registry[type_name] = model_class
+
def get_type(type_name):
return _registry[type_name]
+
def get_type_list():
- return _registry.values()
+ return _registry.values()
Something went wrong with that request. Please try again.