Skip to content

Commit

Permalink
Add support for XBlock 2.0 (#151)
Browse files Browse the repository at this point in the history
* feat: add support for XBlock 2.0 in a backwards compatible way.

The location of fragments code has moved so import from the new location and fall back to the old one.

---------

Co-authored-by: Feanil Patel <[email protected]>
  • Loading branch information
irtazaakram and Feanil Patel authored Mar 19, 2024
1 parent 2e95eb3 commit 06014da
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion acid/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .acid import AcidBlock, AcidParentBlock, AcidAside

__version__ = '0.2.1'
__version__ = '0.3.0'
25 changes: 18 additions & 7 deletions acid/acid.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
"""An XBlock checking container/block relationships for correctness."""

import logging
import pkg_resources
import random

import pkg_resources
import webob
from lazy import lazy
from mako.lookup import TemplateLookup

from xblock.core import XBlock, XBlockAside
from xblock.fields import Scope, Dict
from xblock.fragment import Fragment
import six
from xblock.fields import Dict, Scope

try:
from web_fragments.fragment import Fragment
except:
from xblock.fragment import Fragment # For backward compatibility with quince and earlier.


def generate_fields(cls):
Expand Down Expand Up @@ -335,8 +338,16 @@ def fallback_view(self, view_name, context=None): # pylint: disabl
rendered_children=(fragment.content for fragment in rendered_children),
local_resource_url=self.runtime.local_resource_url(self, 'public/test_data.json'),
))
frag.add_frag_resources(acid_fragment)
frag.add_frags_resources(rendered_children)
try:
frag.add_fragment_resources(acid_fragment)

for rendered_child in rendered_children:
frag.add_fragment_resources(rendered_child)

except: # Add fragment resources using deprecated xblock.fragment for backward compatibility for quince and earlier releases
frag.add_frag_resources(acid_fragment)
frag.add_frags_resources(rendered_children)

frag.add_javascript(self.resource_string('static/js/acid_parent.js'))
frag.initialize_js('AcidParentBlock')
return frag
Expand Down

0 comments on commit 06014da

Please sign in to comment.