Skip to content

Commit

Permalink
[CHG] Fixed some flake feedback and enable 'todo' extension in docume…
Browse files Browse the repository at this point in the history
…ntation
  • Loading branch information
sveetch committed Oct 5, 2024
1 parent a5889c6 commit a0b2af1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Version 1.5.2 - Unreleased
* Added more explicit error messages for invalid items in Feature import form;
* Made some minor improvements on Feature admin;
* Updated PO and MO files for last Feature changes;
* Enabled "todo" extension module in documentation;


Version 1.5.1 - 2024/09/30
Expand Down
28 changes: 20 additions & 8 deletions cmsplugin_blocks/forms/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def clean_json_file(self):
"""
Open file to validate it as JSON and return its content.
NOTE: This could have been done more robustly with Python library "schema".
.. Todo::
This could have been done more robustly with Python library "schema".
"""
data = self.cleaned_data["json_file"]

Expand Down Expand Up @@ -87,41 +88,52 @@ def clean_json_file(self):
if not isinstance(payload["items"], list):
raise ValidationError(_("Item 'items' must be a list"))

# Build registry of existing titles
existing_titles = {k: [] for k, v in Feature.SCOPE_CHOICES}

# Check for some errors from items
error_lines = []
existing_titles = {k: [] for k, v in Feature.SCOPE_CHOICES}
for i, feature in enumerate(payload["items"], start=1):
# Get missing field or empty values from loaded items
if (
not feature.get("title", "") or not feature.get("value", "") or
not feature.get("scope", "") or not feature.get("plugins", "")
):
error_lines.append(_("#{} is missing one or more required items").format(i))
msg = _("#{} is missing one or more required items")
error_lines.append(msg.format(i))

# Check we have a knowed scope
elif feature["scope"] not in [k for k, v in Feature.SCOPE_CHOICES]:
error_lines.append(_("#{} define a scope choice that is not enabled").format(i))
msg = _("#{} define a scope choice that is not enabled")
error_lines.append(msg.format(i))

# Check we have only well known plugin names
elif len([
item
for item in feature["plugins"]
if item not in settings.BLOCKS_KNOWED_FEATURES_PLUGINS
]) > 0:
error_lines.append(_("#{} define a plugin name that is not enabled").format(i))
msg = _("#{} define a plugin name that is not enabled")
error_lines.append(msg.format(i))

# Check for duplicate title per scope
elif feature["title"] in existing_titles[feature["scope"]]:
error_lines.append(_("#{} define a title that already exists").format(i))
msg = _("#{} define a title that already exists")
error_lines.append(msg.format(i))

# Almost everything seems ok, finally use value validator before
# storing item
else:
try:
validate_css_classname(feature["value"])
except ValidationError:
error_lines.append(_("#{} has invalid CSS classname(s)").format(i))
msg = _("#{} has invalid CSS classname(s)")
error_lines.append(msg.format(i))
# Everything is ok, store title as an existing one for its scope
else:
existing_titles[feature["scope"]].append(feature["title"])

# Raise error in case of any missing or empty items
# Raise error in case of any error messages
if error_lines:
raise ValidationError(
[_("Some dump items are invalid:")] + error_lines
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"sphinx.ext.autodoc",
"sphinx.ext.viewcode",
"sphinx.ext.napoleon",
"sphinx.ext.todo",
]

# Add any paths that contain templates here, relative to this directory.
Expand Down
2 changes: 1 addition & 1 deletion frozen.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Frozen requirement versions for 'cmsplugin-blocks==1.5.2rc1' installation
# Frozen requirement versions for 'cmsplugin-blocks==1.5.2rc2' installation
django==5.0.9
django-cms==3.11.8
djangocms-text-ckeditor==5.1.6
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;;
[metadata]
name = cmsplugin-blocks
version = 1.5.2-pre.1
version = 1.5.2-pre.2
description = A set of DjangoCMS plugins for structured contents in CMS pages
long_description = file:README.rst
long_description_content_type = text/x-rst
Expand Down

0 comments on commit a0b2af1

Please sign in to comment.