Skip to content

Commit

Permalink
fix: django import error (#162)
Browse files Browse the repository at this point in the history
* fix recent django import error.

* corrected ngettext.

* remove mppt.

* Update djangocms_bootstrap4/contrib/bootstrap4_grid/models.py

* Update settings.py

* Update base.txt

---------

Co-authored-by: Jordan <[email protected]>
Co-authored-by: Fabian Braun <[email protected]>
  • Loading branch information
3 people authored Sep 14, 2023
1 parent 1726033 commit b17bad6
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 47 deletions.
114 changes: 67 additions & 47 deletions djangocms_bootstrap4/contrib/bootstrap4_grid/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,26 @@

from django.db import models
from django.utils.translation import gettext_lazy as _
from django.utils.translation import ungettext

from django.utils.translation import ngettext

from cms.models import CMSPlugin

from djangocms_bootstrap4.constants import DEVICE_SIZES
from djangocms_bootstrap4.fields import AttributesField, IntegerRangeField, TagTypeField
from djangocms_bootstrap4.helpers import get_choices_match, get_first_choice, mark_safe_lazy
from djangocms_bootstrap4.helpers import (
get_choices_match,
get_first_choice,
mark_safe_lazy,
)

from .constants import (
GRID_COLUMN_ALIGNMENT_CHOICES, GRID_COLUMN_CHOICES, GRID_CONTAINER_CHOICES, GRID_ROW_HORIZONTAL_ALIGNMENT_CHOICES,
GRID_ROW_VERTICAL_ALIGNMENT_CHOICES, GRID_SIZE,
GRID_COLUMN_ALIGNMENT_CHOICES,
GRID_COLUMN_CHOICES,
GRID_CONTAINER_CHOICES,
GRID_ROW_HORIZONTAL_ALIGNMENT_CHOICES,
GRID_ROW_VERTICAL_ALIGNMENT_CHOICES,
GRID_SIZE,
)


Expand All @@ -21,15 +30,18 @@ class Bootstrap4GridContainer(CMSPlugin):
Layout > Grid: "Container" Plugin
https://getbootstrap.com/docs/4.0/layout/grid/
"""

container_type = models.CharField(
verbose_name=_('Container type'),
verbose_name=_("Container type"),
choices=GRID_CONTAINER_CHOICES,
default=get_first_choice(GRID_CONTAINER_CHOICES),
max_length=255,
help_text=mark_safe_lazy(_(
'Defines if the grid should use fixed width (<code>.container</code>) '
'or fluid width (<code>.container-fluid</code>).'
)),
help_text=mark_safe_lazy(
_(
"Defines if the grid should use fixed width (<code>.container</code>) "
"or fluid width (<code>.container-fluid</code>)."
)
),
)
tag_type = TagTypeField()
attributes = AttributesField()
Expand All @@ -39,38 +51,45 @@ def __str__(self):

def get_short_description(self):
choice = get_choices_match(GRID_CONTAINER_CHOICES, self.container_type)
return f'({choice})'
return f"({choice})"


class Bootstrap4GridRow(CMSPlugin):
"""
Layout > Grid: "Row" Plugin
https://getbootstrap.com/docs/4.0/layout/grid/
"""

vertical_alignment = models.CharField(
verbose_name=_('Vertical alignment'),
verbose_name=_("Vertical alignment"),
choices=GRID_ROW_VERTICAL_ALIGNMENT_CHOICES,
blank=True,
max_length=255,
help_text=mark_safe_lazy(_(
'Read more in the <a href="{link}" target="_blank">documentation</a>.')
.format(link='https://getbootstrap.com/docs/4.0/layout/grid/#vertical-alignment')
help_text=mark_safe_lazy(
_(
'Read more in the <a href="{link}" target="_blank">documentation</a>.'
).format(
link="https://getbootstrap.com/docs/4.0/layout/grid/#vertical-alignment"
)
),
)
horizontal_alignment = models.CharField(
verbose_name=_('Horizontal alignment'),
verbose_name=_("Horizontal alignment"),
choices=GRID_ROW_HORIZONTAL_ALIGNMENT_CHOICES,
blank=True,
max_length=255,
help_text=mark_safe_lazy(_(
'Read more in the <a href="{link}" target="_blank">documentation</a>.')
.format(link='https://getbootstrap.com/docs/4.0/layout/grid/#horizontal-alignment')
help_text=mark_safe_lazy(
_(
'Read more in the <a href="{link}" target="_blank">documentation</a>.'
).format(
link="https://getbootstrap.com/docs/4.0/layout/grid/#horizontal-alignment"
)
),
)
gutters = models.BooleanField(
verbose_name=_('Remove gutters'),
verbose_name=_("Remove gutters"),
default=False,
help_text=_('Removes the marginal gutters from the grid.'),
help_text=_("Removes the marginal gutters from the grid."),
)
tag_type = TagTypeField()
attributes = AttributesField()
Expand All @@ -80,11 +99,9 @@ def __str__(self):

def get_short_description(self):
column_count = len(self.child_plugin_instances or [])
column_count_str = ungettext(
'(1 column)',
'(%(count)i columns)',
column_count
) % {'count': column_count}
column_count_str = ngettext(
"(1 column)", "(%(count)i columns)", column_count
) % {"count": column_count}

return column_count_str

Expand All @@ -94,15 +111,16 @@ class Bootstrap4GridColumn(CMSPlugin):
Layout > Grid: "Column" Plugin
https://getbootstrap.com/docs/4.0/layout/grid/
"""

column_type = models.CharField(
verbose_name=_('Column type'),
verbose_name=_("Column type"),
choices=GRID_COLUMN_CHOICES,
default=GRID_COLUMN_CHOICES[0][0],
blank=True,
max_length=255,
)
column_alignment = models.CharField(
verbose_name=_('Alignment'),
verbose_name=_("Alignment"),
choices=GRID_COLUMN_ALIGNMENT_CHOICES,
blank=True,
max_length=255,
Expand All @@ -114,33 +132,35 @@ def __str__(self):
return str(self.pk)

def get_short_description(self):
text = ''
text = ""
classes = self.get_grid_values()
if self.xs_col:
text += f'(col-{self.xs_col}) '
text += f"(col-{self.xs_col}) "
else:
text += '(auto) '
if self.column_type != 'col':
text += f'.{self.column_type} '
text += "(auto) "
if self.column_type != "col":
text += f".{self.column_type} "
if classes:
text += '.{}'.format(' .'.join(self.get_grid_values()))
text += ".{}".format(" .".join(self.get_grid_values()))
return text

def get_grid_values(self):
classes = []
for device in DEVICE_SIZES:
for element in ('col', 'order', 'offset', 'ml', 'mr'):
size = getattr(self, f'{device}_{element}')
if isinstance(size, int) and (element == 'col' or element == 'order' or element == 'offset'):
if device == 'xs':
classes.append(f'{element}-{int(size)}')
for element in ("col", "order", "offset", "ml", "mr"):
size = getattr(self, f"{device}_{element}")
if isinstance(size, int) and (
element == "col" or element == "order" or element == "offset"
):
if device == "xs":
classes.append(f"{element}-{int(size)}")
else:
classes.append(f'{element}-{device}-{int(size)}')
classes.append(f"{element}-{device}-{int(size)}")
elif size:
if device == 'xs':
classes.append('{}-{}'.format(element, 'auto'))
if device == "xs":
classes.append("{}-{}".format(element, "auto"))
else:
classes.append('{}-{}-{}'.format(element, device, 'auto'))
classes.append("{}-{}-{}".format(element, device, "auto"))

return classes

Expand All @@ -162,26 +182,26 @@ def get_grid_values(self):
for size in DEVICE_SIZES:
# Grid size
Bootstrap4GridColumn.add_to_class(
f'{size}_col',
f"{size}_col",
IntegerRangeFieldPartial(),
)
# Grid ordering
Bootstrap4GridColumn.add_to_class(
f'{size}_order',
f"{size}_order",
IntegerRangeFieldPartial(),
)
# Grid offset
Bootstrap4GridColumn.add_to_class(
f'{size}_offset',
f"{size}_offset",
IntegerRangeFieldPartial(),
)
# Grid margin left (ml)
Bootstrap4GridColumn.add_to_class(
f'{size}_ml',
f"{size}_ml",
BooleanFieldPartial(),
)
# Grid margin right (ml)
Bootstrap4GridColumn.add_to_class(
f'{size}_mr',
f"{size}_mr",
BooleanFieldPartial(),
)
1 change: 1 addition & 0 deletions tests/requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ isort
flake8
pyflakes>=2.1
wheel
django-filer<3

0 comments on commit b17bad6

Please sign in to comment.