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

Add consistency and some clean up. #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions djangocms_grid/cms_plugins.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from django.utils.translation import ugettext_lazy as _

from cms.plugin_pool import plugin_pool
from cms.plugin_base import CMSPluginBase
from djangocms_grid.models import Grid, GridColumn, DJANGOCMS_GRID_SIZE
from django.utils.translation import ugettext_lazy as _
from djangocms_grid.forms import GridPluginForm
from cms.models import CMSPlugin

from .forms import GridPluginForm
from .models import Grid, GridColumn
from .settings import TOTAL_COLUMNS_CHOICES, GRID_COLUMN_PLUGINS


class GridPlugin(CMSPluginBase):
model = Grid
Expand All @@ -19,14 +22,20 @@ def render(self, context, instance, placeholder):
context.update({
'grid': instance,
'placeholder': placeholder,
'GRID_SIZE': DJANGOCMS_GRID_SIZE,
'GRID_SIZE': TOTAL_COLUMNS_CHOICES,
})
return context

def save_model(self, request, obj, form, change):
response = super(GridPlugin, self).save_model(request, obj, form, change)
response = super(GridPlugin, self).save_model(request, obj, form,
change)
for x in xrange(int(form.cleaned_data['create'])):
col = GridColumn(parent=obj, placeholder=obj.placeholder, language=obj.language, size=form.cleaned_data['create_size'], position=CMSPlugin.objects.filter(parent=obj).count(), plugin_type=GridColumnPlugin.__name__)
col = GridColumn(parent=obj, placeholder=obj.placeholder,
language=obj.language,
size=form.cleaned_data['create_size'],
position=CMSPlugin.objects.filter(
parent=obj).count(),
plugin_type=GridColumnPlugin.__name__)
col.save()
return response

Expand All @@ -37,6 +46,7 @@ class GridColumnPlugin(CMSPluginBase):
module = _('Multi Columns')
render_template = 'djangocms_grid/column.html'
allow_children = True
child_classes = GRID_COLUMN_PLUGINS

def render(self, context, instance, placeholder):
context.update({
Expand Down
17 changes: 11 additions & 6 deletions djangocms_grid/forms.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
from django import forms
from djangocms_grid.models import Grid, DJANGOCMS_GRID_CHOICES, DJANGOCMS_GRID_SIZE
from django.utils.translation import ugettext_lazy as _

NUM_COLUMNS = [
(i, '%s' % i) for i in range(0, DJANGOCMS_GRID_SIZE)
]
from .models import Grid
from .settings import COLUMN_CHOICES, TOTAL_COLUMNS_CHOICES


class GridPluginForm(forms.ModelForm):
create = forms.ChoiceField(choices=NUM_COLUMNS, label=_('Create Columns'), help_text=_('Create this number of columns inside'))
create_size = forms.ChoiceField(choices=DJANGOCMS_GRID_CHOICES, label=_('Column size'), help_text=('Width of created columns. You can still change the width of the column afterwards.'))
create = forms.ChoiceField(label=_('Create Columns'),
choices=TOTAL_COLUMNS_CHOICES,
help_text=_('Create this number of columns '
'inside'))
create_size = forms.ChoiceField(label=_('Column size'),
choices=COLUMN_CHOICES,
help_text=('Width of created columns. You '
'can still change the width of '
'the column afterwards.'))

class Meta:
model = Grid
Expand Down
22 changes: 12 additions & 10 deletions djangocms_grid/models.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
from cms.models import CMSPlugin
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.conf import settings

DJANGOCMS_GRID_SIZE = getattr(settings, 'DJANGOCMS_COLUMN_960_COLUMNS', 24)
DJANGOCMS_GRID_CHOICES = [
('%s' % i, 'grid-%s' % i) for i in range(1, DJANGOCMS_GRID_SIZE+1)
]
from cms.models import CMSPlugin

from .settings import COLUMN_CHOICES


class Grid(CMSPlugin):
inner = models.BooleanField(_('inner'), default=True, help_text=_('Defines whether the plugin is already inside a grid container or another Multi-column plugin.'))
custom_classes = models.CharField(_('custom classes'), max_length=200, blank=True)
inner = models.BooleanField(_('inner'), default=True, help_text=_(
'Defines whether the plugin is already inside a grid container or '
'another Multi-column plugin.'))
custom_classes = models.CharField(_('custom classes'), max_length=200,
blank=True)

def __unicode__(self):
return _(u"%s columns") % self.cmsplugin_set.all().count()


class GridColumn(CMSPlugin):
size = models.CharField(_('size'), choices=DJANGOCMS_GRID_CHOICES, default='1', max_length=50)
custom_classes = models.CharField(_('custom classes'), max_length=200, blank=True)
size = models.CharField(_('size'), choices=COLUMN_CHOICES,
default='1', max_length=50)
custom_classes = models.CharField(_('custom classes'), max_length=200,
blank=True)

def __unicode__(self):
return u"%s" % self.get_size_display()
Expand Down
11 changes: 11 additions & 0 deletions djangocms_grid/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.conf import settings

TOTAL_COLUMNS = getattr(settings, 'DJANGOCMS_GRID_TOTAL_COLUMNS', 24)
TOTAL_COLUMNS_CHOICES = [
(i, i) for i in range(0, TOTAL_COLUMNS + 1)
]
COLUMN_CHOICES = [
(str(i), 'grid-{}'.format(i)) for i in range(1, TOTAL_COLUMNS + 1)
]

GRID_COLUMN_PLUGINS = getattr(settings, 'GRID_COLUMN_PLUGINS', None)