diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..d25254b --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,24 @@ +Copyright (c) 2012, Divio AG +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Divio AG nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL DIVIO AG BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..cdc203c --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,5 @@ +include LICENSE.txt +recursive-include aldryn_style/templates * +recursive-include aldryn_style/locale * +recursive-include aldryn_style/migrations * +recursive-exclude * *.pyc diff --git a/aldryn_style/__init__.py b/aldryn_style/__init__.py new file mode 100644 index 0000000..2bb0f2c --- /dev/null +++ b/aldryn_style/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +__version__ = '0.0.1' diff --git a/aldryn_style/cms_plugins.py b/aldryn_style/cms_plugins.py new file mode 100644 index 0000000..91a05ee --- /dev/null +++ b/aldryn_style/cms_plugins.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +from django.utils.translation import ugettext_lazy as _ + +from cms.plugin_base import CMSPluginBase +from cms.plugin_pool import plugin_pool + +from aldryn_style import models + + +class StylePlugin(CMSPluginBase): + + render_template = 'aldryn_style/style.html' + name = _('Style') + model = models.StylePlugin + allow_children = True + + def render(self, context, instance, placeholder): + context['instance'] = instance + return context + +plugin_pool.register_plugin(StylePlugin) diff --git a/aldryn_style/migrations/0001_initial.py b/aldryn_style/migrations/0001_initial.py new file mode 100644 index 0000000..18642bb --- /dev/null +++ b/aldryn_style/migrations/0001_initial.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + # Adding model 'StylePlugin' + db.create_table('cmsplugin_styleplugin', ( + ('cmsplugin_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['cms.CMSPlugin'], unique=True, primary_key=True)), + ('class_name', self.gf('django.db.models.fields.CharField')(max_length=50)), + )) + db.send_create_signal('aldryn_style', ['StylePlugin']) + + + def backwards(self, orm): + # Deleting model 'StylePlugin' + db.delete_table('cmsplugin_styleplugin') + + + models = { + 'aldryn_style.styleplugin': { + 'Meta': {'object_name': 'StylePlugin', 'db_table': "'cmsplugin_styleplugin'", '_ormbases': ['cms.CMSPlugin']}, + 'class_name': ('django.db.models.fields.CharField', [], {'max_length': '50'}), + 'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}) + }, + 'cms.cmsplugin': { + 'Meta': {'object_name': 'CMSPlugin'}, + 'changed_date': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'language': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}), + 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.CMSPlugin']", 'null': 'True', 'blank': 'True'}), + 'placeholder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}), + 'plugin_type': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}), + 'position': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}), + 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}) + }, + 'cms.placeholder': { + 'Meta': {'object_name': 'Placeholder'}, + 'default_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'slot': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}) + } + } + + complete_apps = ['aldryn_style'] \ No newline at end of file diff --git a/aldryn_style/migrations/__init__.py b/aldryn_style/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/aldryn_style/models.py b/aldryn_style/models.py new file mode 100644 index 0000000..aa6f029 --- /dev/null +++ b/aldryn_style/models.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from django.db import models +from django.conf import settings +from django.utils.translation import ugettext_lazy as _ + +from cms.models.pluginmodel import CMSPlugin + + +def get_class_choices(): + return [(x, x) for x in getattr(settings, 'STYLE_CLASS_NAMES', [''])] + + +class StylePlugin(CMSPlugin): + + class_name = models.CharField(_('Class name'), choices=get_class_choices(), max_length=50) + + def __unicode__(self): + return self.class_name diff --git a/aldryn_style/templates/aldryn_style/style.html b/aldryn_style/templates/aldryn_style/style.html new file mode 100644 index 0000000..37cefd2 --- /dev/null +++ b/aldryn_style/templates/aldryn_style/style.html @@ -0,0 +1,6 @@ +{% load cms_tags %} +
+ {% for plugin in instance.child_plugin_instances %} + {% render_plugin plugin %} + {% endfor %} +
diff --git a/app.yaml b/app.yaml new file mode 100644 index 0000000..8fabd73 --- /dev/null +++ b/app.yaml @@ -0,0 +1,13 @@ +name: Style +package-name: aldryn-style +url: https://github.com/aldryn/aldryn-style +author: + name: Divio AG + url: https://www.divio.ch +installed-apps: + - aldryn_style +version: 0.0.1 +description: Wraps inner plugin with a classy div. +license: + name: BSD + text: !literal-include LICENSE.txt diff --git a/cmscloud_config.py b/cmscloud_config.py new file mode 100644 index 0000000..463d018 --- /dev/null +++ b/cmscloud_config.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +from cmscloud_client import forms + +import re + + +class ClassNamesField(forms.CharField): + + CLASS_NAME_RE = re.compile(r'^\w[\w-_]*$') + + def clean(self, value): + value = super(ClassNamesField, self).clean(value) + value = filter(bool, map(lambda x: x.strip(), value.split(','))) + for class_name in value: + if not self.CLASS_NAME_RE.match(class_name): + raise forms.ValidationError(u'%s is not a proper class name.' % (class_name, )) + return value + + +class Form(forms.BaseForm): + + class_names = ClassNamesField('Class names') + + def to_settings(self, data, settings): + settings['STYLE_CLASS_NAMES'] = data['class_names'] + return settings diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..23fd61e --- /dev/null +++ b/setup.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +from setuptools import setup +from aldryn_style import __version__ + + +CLASSIFIERS = [ + 'Development Status :: 2 - Pre-Alpha', + 'Environment :: Web Environment', + 'Framework :: Django', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: BSD License', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Topic :: Communications', + 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', + 'Programming Language :: Python :: 2.6', + 'Programming Language :: Python :: 2.7', +] + +setup( + name='aldryn-style', + version=__version__, + description='Wraps inner plugin with a classy div', + author='Divio AG', + author_email='info@divio.ch', + url='https://github.com/aldryn/aldryn-style', + packages=['aldryn_style'], + license='LICENSE.txt', + platforms=['OS Independent'], + classifiers=CLASSIFIERS, + include_package_data=True, + zip_safe=False +)