Skip to content

Commit

Permalink
[#1656] Added CKEditor widget to category description field
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed Oct 3, 2023
1 parent ddaa5e9 commit b092fc6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 23 deletions.
20 changes: 0 additions & 20 deletions src/open_inwoner/components/templatetags/category_tags.py

This file was deleted.

1 change: 1 addition & 0 deletions src/open_inwoner/pdc/models/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from treebeard.exceptions import InvalidMoveToDescendant
from treebeard.mp_tree import MP_MoveHandler, MP_Node

from ...utils.ckeditor import get_rendered_content
from ..managers import CategoryPublishedQueryset


Expand Down
4 changes: 4 additions & 0 deletions src/open_inwoner/pdc/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from open_inwoner.questionnaire.models import QuestionnaireStep
from open_inwoner.utils.views import LoginMaybeRequiredMixin

from ..utils.ckeditor import get_rendered_content
from ..utils.views import CommonPageMixin
from .choices import YesNo
from .forms import ProductFinderForm
Expand Down Expand Up @@ -173,6 +174,9 @@ def get_context_data(self, **kwargs):
context["questionnaire_roots"] = QuestionnaireStep.get_root_nodes().filter(
category=self.object
)
context["category_rendered_description"] = get_rendered_content(
self.object.description
)
return context

def get_breadcrumb_name(self):
Expand Down
2 changes: 1 addition & 1 deletion src/open_inwoner/templates/pages/category/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h1 class="h1">
{% button icon="edit" text=_("Open in admin") hide_text=True href="admin:pdc_category_change" object_id=object.pk %}
{% endif %}
</h1>
{{ object.description|category_ckeditor_content|safe }}
{{ category_rendered_description|safe }}

{% if subcategories %}
{% card_container subcategories=subcategories parent_category=object %}
Expand Down
4 changes: 2 additions & 2 deletions src/open_inwoner/utils/ckeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
]


def get_rendered_content(content):
def get_rendered_content(content: str) -> str:
"""
Takes object's content as an input and returns the rendered one.
"""
Expand All @@ -37,7 +37,7 @@ def get_rendered_content(content):
if element.name == "a" and element.attrs.get("href", "").startswith("http"):
element.attrs["target"] = "_blank"

return soup
return str(soup)


def get_product_rendered_content(product):
Expand Down

0 comments on commit b092fc6

Please sign in to comment.