コード例 #1
0
 def test_import_module_raises_improperly_configured(self):
     """We can only import attributes from modules, not modules directly"""
     with self.assertRaises(ImproperlyConfigured) as cm:
         import_element('fiber')
     self.assertEqual(
         str(cm.exception),
         'Error importing fiber: fiber doesn\'t look like a module path')
コード例 #2
0
 def test_import_invalid_module_raises_improperly_configured(self):
     """Fail trying to import a missing module"""
     with self.assertRaises(ImproperlyConfigured) as cm:
         import_element("fiber.missing_module.missing_attribute")
     self.assertEqual(
         str(cm.exception), "Error importing fiber.missing_module.missing_attribute: No module named missing_module"
     )
コード例 #3
0
 def test_import_invalid_module_raises_improperly_configured(self):
     """Fail trying to import a missing module"""
     with self.assertRaises(ImproperlyConfigured) as cm:
         import_element('fiber.missing_module.missing_attribute')
     self.assertRegexpMatches(
         str(cm.exception),
         r'Error importing fiber.missing_module.missing_attribute: No module named .+'
     )
コード例 #4
0
 def test_import_invalid_attribute_raises_improperly_configured(self):
     """Fail trying to import a missing attribute"""
     with self.assertRaises(ImproperlyConfigured) as cm:
         import_element("fiber.missing_attribute")
     self.assertEqual(
         str(cm.exception),
         'Error importing fiber.missing_attribute: Module "fiber.missing_attribute" does not define a "missing_attribute" attribute/class',
     )
コード例 #5
0
 def test_import_invalid_attribute_raises_improperly_configured(self):
     """Fail trying to import a missing attribute"""
     with self.assertRaises(ImproperlyConfigured) as cm:
         import_element('fiber.missing_attribute')
     msgs = [
         'Error importing fiber.missing_attribute: Module "fiber.missing_attribute" does not define a "missing_attribute" attribute/class',
         'Error importing fiber.missing_attribute: Module "fiber" does not define a "missing_attribute" attribute/class',  # Django 1.8 and later
     ]
     self.assertIn(str(cm.exception), msgs)
コード例 #6
0
 def test_import_invalid_attribute_raises_improperly_configured(self):
     """Fail trying to import a missing attribute"""
     with self.assertRaises(ImproperlyConfigured) as cm:
         import_element('fiber.missing_attribute')
     msgs = [
         'Error importing fiber.missing_attribute: Module "fiber.missing_attribute" does not define a "missing_attribute" attribute/class',
         'Error importing fiber.missing_attribute: Module "fiber" does not define a "missing_attribute" attribute/class',  # Django 1.8 and later
     ]
     self.assertIn(str(cm.exception), msgs)
コード例 #7
0
 def __init__(self, *args, **kwargs):
     super(AdminPageMiddleware, self).__init__(*args, **kwargs)
     self.editor_settings = import_element(EDITOR)
コード例 #8
0
ファイル: middleware.py プロジェクト: xumaoxuan/django-fiber
 def __init__(self):
     self.editor_settings = import_element(EDITOR)
コード例 #9
0
ファイル: editor.py プロジェクト: gijs/django-fiber
from fiber.utils.import_util import import_element
from fiber.app_settings import EDITOR


editor = import_element(EDITOR)
renderer = editor.get('renderer', None)


def get_editor_field_name(html_field_name):
    """
    Returns markup or html field name, depending on editor.
    Input is html field_name:

    get_editor_field_name('content_html')

    returns: 'content_html' or 'content_markup'
    """
    if renderer:
        return html_field_name.replace('_html', '_markup')
    else:
        return html_field_name
コード例 #10
0
 def __init__(self, *args, **kwargs):
     super(AdminPageMiddleware, self).__init__(*args, **kwargs)
     self.editor_settings = import_element(EDITOR)
コード例 #11
0
 def test_import_module_raises_improperly_configured(self):
     """We can only import attributes from modules, not modules directly"""
     with self.assertRaises(ImproperlyConfigured) as cm:
         import_element('fiber')
     self.assertEqual(str(cm.exception), 'Error importing fiber: fiber doesn\'t look like a module path')
コード例 #12
0
 def test_import_element(self):
     """Import TestClass by name"""
     path = '.'.join([self.__module__, 'TestClass'])
     self.assertEqual(import_element(path), TestClass)
コード例 #13
0
ファイル: middleware.py プロジェクト: MarkTseng/django-fiber
 def __init__(self):
     self.editor_settings = import_element(EDITOR)
コード例 #14
0
 def test_import_element(self):
     """Import TestClass by name"""
     path = '.'.join([self.__module__, 'TestClass'])
     self.assertEqual(import_element(path), TestClass)
コード例 #15
0
ファイル: editor.py プロジェクト: vdboor/django-fiber
from fiber.app_settings import EDITOR
from fiber.utils.import_util import import_element


editor = import_element(EDITOR)
renderer = editor.get('renderer', None)


def get_editor_field_name(html_field_name):
    """
    Returns markup or html field name, depending on editor.
    Input is html field_name:

    get_editor_field_name('content_html')

    returns: 'content_html' or 'content_markup'
    """
    if renderer:
        return html_field_name.replace('_html', '_markup')
    else:
        return html_field_name