Skip to content

Commit

Permalink
Made things a little more readable with some PEP8 inspired changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
marksweb committed May 21, 2015
1 parent 116c8ba commit 96183eb
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ build
env*
dist
djangocms_column.egg-info
.idea
30 changes: 21 additions & 9 deletions djangocms_column/cms_plugins.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from cms.plugin_pool import plugin_pool
from cms.models import CMSPlugin
from cms.plugin_base import CMSPluginBase
from djangocms_column.models import MultiColumns, Column
from cms.plugin_pool import plugin_pool
from django.utils.translation import ugettext_lazy as _
from djangocms_column.forms import MultiColumnForm
from cms.models import CMSPlugin

from .forms import MultiColumnForm
from .models import MultiColumns, Column


class MultiColumnPlugin(CMSPluginBase):
model = MultiColumns
Expand All @@ -17,17 +19,27 @@ class MultiColumnPlugin(CMSPluginBase):
def render(self, context, instance, placeholder):
context.update({
'instance': instance,
'placeholder':placeholder,
'placeholder': placeholder,
})
return context

def save_model(self, request, obj, form, change):
response = super(MultiColumnPlugin, self).save_model(request, obj, form, change)
response = super(MultiColumnPlugin, self).save_model(
request, obj, form, change
)
for x in range(int(form.cleaned_data['create'])):
col = Column(parent=obj, placeholder=obj.placeholder, language=obj.language, width=form.cleaned_data['create_width'], position=CMSPlugin.objects.filter(parent=obj).count(), plugin_type=ColumnPlugin.__name__)
col = Column(
parent=obj,
placeholder=obj.placeholder,
language=obj.language,
width=form.cleaned_data['create_width'],
position=CMSPlugin.objects.filter(parent=obj).count(),
plugin_type=ColumnPlugin.__name__
)
col.save()
return response


class ColumnPlugin(CMSPluginBase):
model = Column
module = _("Multi Columns")
Expand All @@ -39,8 +51,8 @@ class ColumnPlugin(CMSPluginBase):
def render(self, context, instance, placeholder):
context.update({
'instance': instance,
'placeholder':placeholder,
})
'placeholder': placeholder,
})
return context

plugin_pool.register_plugin(MultiColumnPlugin)
Expand Down
21 changes: 16 additions & 5 deletions djangocms_column/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from django import forms
from djangocms_column.models import MultiColumns, WIDTH_CHOICES
from django.utils.translation import ugettext_lazy as _

from .models import MultiColumns, WIDTH_CHOICES


class MultiColumnForm(forms.ModelForm):
NUM_COLUMNS = (
(0, "0"),
Expand All @@ -17,10 +19,19 @@ class MultiColumnForm(forms.ModelForm):
(10, "10"),
)


create = forms.ChoiceField(choices=NUM_COLUMNS, label=_("Create Columns"), help_text=_("Create this number of columns"))
create_width = forms.ChoiceField(choices=WIDTH_CHOICES, label=_("Column width"), help_text=("Width of created columns. You can still change the width of the column afterwards."))

create = forms.ChoiceField(
choices=NUM_COLUMNS,
label=_("Create Columns"),
help_text=_("Create this number of columns")
)
create_width = forms.ChoiceField(
choices=WIDTH_CHOICES,
label=_("Column width"),
help_text=(
"Width of created columns. You can still change the width of the "
"column afterwards."
)
)

class Meta:
model = MultiColumns
Expand Down
13 changes: 9 additions & 4 deletions djangocms_column/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from cms.models import CMSPlugin
from cms.utils.compat.dj import python_2_unicode_compatible
from django.conf import settings
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from cms.utils.compat.dj import python_2_unicode_compatible

if hasattr(settings, "COLUMN_WIDTH_CHOICES"):
WIDTH_CHOICES = settings.COLUMN_WIDTH_CHOICES
Expand All @@ -17,6 +17,7 @@
('100%', _('100%')),
)


@python_2_unicode_compatible
class MultiColumns(CMSPlugin):
"""
Expand All @@ -31,8 +32,12 @@ class Column(CMSPlugin):
"""
A Column for the MultiColumns Plugin
"""

width = models.CharField(_("width"), choices=WIDTH_CHOICES, default=WIDTH_CHOICES[0][0], max_length=50)
width = models.CharField(
_("width"),
choices=WIDTH_CHOICES,
default=WIDTH_CHOICES[0][0],
max_length=50
)

def __str__(self):
return u"%s" % self.get_width_display()
Expand Down

0 comments on commit 96183eb

Please sign in to comment.