Commit d942891b by Marko Jevtic

(SOL-1040) Indexing capa problems

parent 1ba82819
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import json import json
import logging import logging
import sys import sys
import re
from lxml import etree from lxml import etree
from pkg_resources import resource_string from pkg_resources import resource_string
...@@ -10,6 +11,7 @@ import dogstats_wrapper as dog_stats_api ...@@ -10,6 +11,7 @@ import dogstats_wrapper as dog_stats_api
from .capa_base import CapaMixin, CapaFields, ComplexEncoder from .capa_base import CapaMixin, CapaFields, ComplexEncoder
from capa import responsetypes from capa import responsetypes
from .progress import Progress from .progress import Progress
from xmodule.annotator_mixin import html_to_text
from xmodule.x_module import XModule, module_attr, DEPRECATION_VSCOMPAT_EVENT from xmodule.x_module import XModule, module_attr, DEPRECATION_VSCOMPAT_EVENT
from xmodule.raw_module import RawDescriptor from xmodule.raw_module import RawDescriptor
from xmodule.exceptions import NotFoundError, ProcessingError from xmodule.exceptions import NotFoundError, ProcessingError
...@@ -193,16 +195,26 @@ class CapaDescriptor(CapaFields, RawDescriptor): ...@@ -193,16 +195,26 @@ class CapaDescriptor(CapaFields, RawDescriptor):
""" """
Return dictionary prepared with module content and type for indexing. Return dictionary prepared with module content and type for indexing.
""" """
result = super(CapaDescriptor, self).index_dictionary() xblock_body = super(CapaDescriptor, self).index_dictionary()
if not result: # Removing solution
result = {} capa_content = re.sub(re.compile(r"<solution>.*</solution>", re.DOTALL), "", self.data)
index = { # Removing HTML-encoded non-breaking space characters
'content_type': self.INDEX_CONTENT_TYPE, capa_content = re.sub(r"(\s|&nbsp;|//)+", " ", html_to_text(capa_content))
'problem_types': list(self.problem_types), # Removing HTML CDATA
"display_name": self.display_name capa_content = re.sub(r"<!\[CDATA\[.*\]\]>", "", capa_content)
# Removing HTML comments
capa_content = re.sub(r"<!--.*-->", "", capa_content)
capa_body = {
"capa_content": capa_content,
"display_name": self.display_name,
} }
result.update(index) if "content" in xblock_body:
return result xblock_body["content"].update(capa_body)
else:
xblock_body["content"] = capa_body
xblock_body["content_type"] = self.INDEX_CONTENT_TYPE
xblock_body["problem_types"] = list(self.problem_types)
return xblock_body
def has_support(self, view, functionality): def has_support(self, view, functionality):
""" """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment