From e845ef893f27d2de4e78e9aa344de2722fcb9cd1 Mon Sep 17 00:00:00 2001 From: Martin Koistinen Date: Mon, 4 May 2015 18:58:25 +0300 Subject: [PATCH 1/3] Adds a label field for display in the structure tree --- aldryn_style/cms_plugins.py | 2 +- aldryn_style/models.py | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/aldryn_style/cms_plugins.py b/aldryn_style/cms_plugins.py index fd56d80..823c39b 100644 --- a/aldryn_style/cms_plugins.py +++ b/aldryn_style/cms_plugins.py @@ -13,7 +13,7 @@ class StylePlugin(CMSPluginBase): fieldsets = ( (None, { - 'fields': ('class_name',) + 'fields': ('label', 'class_name', ) }), (_('Advanced Settings'), { 'classes': ('collapse',), diff --git a/aldryn_style/models.py b/aldryn_style/models.py index 5454e18..d6db13d 100644 --- a/aldryn_style/models.py +++ b/aldryn_style/models.py @@ -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) @@ -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): @@ -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 '' - From 96de45877ea082db08398ce0f8d023e687921cbb Mon Sep 17 00:00:00 2001 From: Martin Koistinen Date: Mon, 4 May 2015 19:28:10 +0300 Subject: [PATCH 2/3] Remove old field from frozen model This appears to have been left in when the hand-modified migration was written. --- .../migrations/0005_rename_addional_class_name_field.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/aldryn_style/migrations/0005_rename_addional_class_name_field.py b/aldryn_style/migrations/0005_rename_addional_class_name_field.py index 90ed060..a799084 100644 --- a/aldryn_style/migrations/0005_rename_addional_class_name_field.py +++ b/aldryn_style/migrations/0005_rename_addional_class_name_field.py @@ -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'}, From 9b8cae47ddc3c02ffb5273f7c0bda8d6a9840a50 Mon Sep 17 00:00:00 2001 From: Martin Koistinen Date: Mon, 4 May 2015 19:30:19 +0300 Subject: [PATCH 3/3] South migration --- ..._chg_field_style_additional_class_names.py | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 aldryn_style/migrations/0006_auto__add_field_style_label__chg_field_style_additional_class_names.py diff --git a/aldryn_style/migrations/0006_auto__add_field_style_label__chg_field_style_additional_class_names.py b/aldryn_style/migrations/0006_auto__add_field_style_label__chg_field_style_additional_class_names.py new file mode 100644 index 0000000..95d5706 --- /dev/null +++ b/aldryn_style/migrations/0006_auto__add_field_style_label__chg_field_style_additional_class_names.py @@ -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'] \ No newline at end of file