def get_context_data(self, **kwargs): """Bootstrap data for Backbone models and collections""" context = { 'asset_types_json': mark_safe(self.get_asset_types_json()), 'help_json': mark_safe(escape_json_for_html( self.get_help_json())), 'layouts_json': mark_safe(self.get_layouts_json()), 'organizations_json': mark_safe(self.get_organizations_json()), 'places_json': mark_safe(self.get_places_json()), 'projects_json': mark_safe(self.get_projects_json()), 'story_template_json': mark_safe(self.get_story_template_json()), 'topics_json': mark_safe(self.get_topics_json()), } if self.object: context['story'] = self.object context['story_json'] = mark_safe(self.get_story_json()) context['featured_assets_json'] = mark_safe(escape_json_for_html( self.get_assets_json(featured=True))) context['assets_json'] = mark_safe(escape_json_for_html( self.get_assets_json())) if self.object.template_story: context['template_story_json'] = mark_safe( self.get_story_json(self.object.template_story)) context['template_sections_json'] = mark_safe( self.get_sections_json(self.object.template_story)) context['container_templates_json'] = mark_safe(self.get_container_templates_json(self.object.template_story)) elif self.template_object: context['template_story_json'] = mark_safe( self.get_story_json(self.template_object.story)) context['template_sections_json'] = mark_safe( self.get_sections_json(self.template_object.story)) context['container_templates_json'] = mark_safe( self.get_container_templates_json(self.template_object.story)) if (self.template_object and self.template_object.slug == settings.STORYBASE_CONNECTED_STORY_TEMPLATE): context['show_story_info_inline'] = True related_stories_json = self.get_related_stories_json() if related_stories_json: context['related_stories_json'] = mark_safe( related_stories_json) context['options_json'] = mark_safe(self.get_options_json()) return context
def test_escape_json_for_html(self): data = { 'title': "Test Title", 'body': "<script src=\"http://floodlightproject.org/fake.js\"></script>", } json_str = simplejson.dumps(data, cls=json.DjangoJSONEncoder, sort_keys=True, ensure_ascii=False) escaped_json_str = escape_json_for_html(json_str) self.assertEqual(simplejson.loads(json_str)['body'], simplejson.loads(escaped_json_str)['body'])
def test_escape_json_for_html(self): data = { 'title': "Test Title", 'body': "<script src=\"http://floodlightproject.org/fake.js\"></script>", } json_str = simplejson.dumps(data, cls=json.DjangoJSONEncoder, sort_keys=True, ensure_ascii=False) escaped_json_str = escape_json_for_html(json_str) self.assertEqual( simplejson.loads(json_str)['body'], simplejson.loads(escaped_json_str)['body'])