Skip to content
This repository has been archived by the owner on Feb 1, 2019. It is now read-only.

Commit

Permalink
Merge pull request #9 from aldryn/issues/add_label_to_plugin
Browse files Browse the repository at this point in the history
Issues/add label to plugin
  • Loading branch information
mkoistinen committed May 4, 2015
2 parents 84d000c + 9b8cae4 commit d7d0293
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 9 deletions.
2 changes: 1 addition & 1 deletion aldryn_style/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class StylePlugin(CMSPluginBase):

fieldsets = (
(None, {
'fields': ('class_name',)
'fields': ('label', 'class_name', )
}),
(_('Advanced Settings'), {
'classes': ('collapse',),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ def backwards(self, orm):
'padding_left': ('django.db.models.fields.SmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
'padding_right': ('django.db.models.fields.SmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
'padding_top': ('django.db.models.fields.SmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
'tag_type': ('django.db.models.fields.CharField', [], {'default': "'div'", 'max_length': '50'}),
'txt_additional_class_names': ('django.db.models.fields.TextField', [], {'blank': 'True'})
'tag_type': ('django.db.models.fields.CharField', [], {'default': "'div'", 'max_length': '50'})
},
'cms.cmsplugin': {
'Meta': {'object_name': 'CMSPlugin'},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*-
from south.utils import datetime_utils as datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models


class Migration(SchemaMigration):

def forwards(self, orm):
# Adding field 'Style.label'
db.add_column(u'aldryn_style_style', 'label',
self.gf('django.db.models.fields.CharField')(default='', max_length=128, blank=True),
keep_default=False)


# Changing field 'Style.additional_class_names'
db.alter_column(u'aldryn_style_style', 'additional_class_names', self.gf('django.db.models.fields.TextField')())

def backwards(self, orm):
# Deleting field 'Style.label'
db.delete_column(u'aldryn_style_style', 'label')


# Changing field 'Style.additional_class_names'
db.alter_column(u'aldryn_style_style', 'additional_class_names', self.gf('django.db.models.fields.CharField')(max_length=200))

models = {
u'aldryn_style.style': {
'Meta': {'object_name': 'Style', '_ormbases': ['cms.CMSPlugin']},
'additional_class_names': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'class_name': ('django.db.models.fields.CharField', [], {'default': "'container'", 'max_length': '50', 'blank': 'True'}),
'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'+'", 'unique': 'True', 'primary_key': 'True', 'to': "orm['cms.CMSPlugin']"}),
'id_name': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '50', 'blank': 'True'}),
'label': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '128', 'blank': 'True'}),
'margin_bottom': ('django.db.models.fields.SmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
'margin_left': ('django.db.models.fields.SmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
'margin_right': ('django.db.models.fields.SmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
'margin_top': ('django.db.models.fields.SmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
'padding_bottom': ('django.db.models.fields.SmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
'padding_left': ('django.db.models.fields.SmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
'padding_right': ('django.db.models.fields.SmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
'padding_top': ('django.db.models.fields.SmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
'tag_type': ('django.db.models.fields.CharField', [], {'default': "'div'", 'max_length': '50'})
},
'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'}),
u'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'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'slot': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'})
}
}

complete_apps = ['aldryn_style']
18 changes: 12 additions & 6 deletions aldryn_style/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ class Style(CMSPlugin):
(INLINE_TAG, _('inline')),
)

label = models.CharField(_('label'), max_length=128, default="", blank=True,
help_text=_('Optional label for this style plugin.'))

cmsplugin_ptr = models.OneToOneField(CMSPlugin, related_name='+', parent_link=True)

class_name = models.CharField(_("class name"), choices=CLASS_NAMES, default=CLASS_NAMES[0][0], max_length=50, blank=True)
class_name = models.CharField(_("class name"), choices=CLASS_NAMES,
default=CLASS_NAMES[0][0], max_length=50, blank=True)
id_name = models.CharField(_("id name"), max_length=50, blank=True, default='')

tag_type = models.CharField(verbose_name=_('tag Type'), max_length=50, choices=HTML_TAG_TYPES, default=DIV_TAG)
tag_type = models.CharField(verbose_name=_('tag Type'), max_length=50,
choices=HTML_TAG_TYPES, default=DIV_TAG)

padding_left = models.SmallIntegerField(_("padding left"), blank=True, null=True)
padding_right = models.SmallIntegerField(_("padding right"), blank=True, null=True)
Expand All @@ -63,7 +68,9 @@ class Style(CMSPlugin):
def __unicode__(self):
display = self.get_class_name_display() or self.tag_type or u''
if self.additional_class_names:
display = u'{} ({})'.format(display, self.additional_class_names)
display = u'{0} ({1})'.format(display, self.additional_class_names)
if self.label:
display = u'“{0}”: {1}'.format(self.label, display)
return u"%s" % display

def inline_style(self):
Expand All @@ -88,18 +95,17 @@ def inline_style(self):

def clean(self):
if self.additional_class_names:
additional_class_names = list(html_class.strip() for html_class in self.additional_class_names.split(','))
additional_class_names = list(
html_class.strip() for html_class in self.additional_class_names.split(','))
for class_name in additional_class_names:
class_name = class_name.strip()
if not CLASS_NAME_FORMAT.match(class_name):
raise ValidationError(u'"%s" is not a proper css class name.' % (class_name, ))
self.additional_class_names = u", ".join(set(additional_class_names))


@property
def get_additional_class_names(self):
if self.additional_class_names:
# Removes any extra spaces
return ' '.join((html_class.strip() for html_class in self.additional_class_names.split(',')))
return ''

0 comments on commit d7d0293

Please sign in to comment.