예제 #1
0
    def get_format(self, format_name, lang=None, handler=None):
        """
        Get format by name from global settings.
        """
        if lang is None and handler is None:
            raise RuntimeError("One of parameters 'lang' or 'handler' is mandatory")

        format_name = smart_text(format_name)

        if lang is None:
            lang = locale_to_code(handler.locale)

        # At the moment only get formats from settings
        # In near future i go to implement full locale depenen
        # format module.

        return getattr(handler.conf, format_name)
예제 #2
0
    def get_format(self, format_name, lang=None, handler=None):
        """
        Get format by name from global settings.
        """
        if lang is None and handler is None:
            raise RuntimeError(
                "One of parameters 'lang' or 'handler' is mandatory")

        format_name = smart_text(format_name)

        if lang is None:
            lang = locale_to_code(handler.locale)

        # At the moment only get formats from settings
        # In near future i go to implement full locale depenen
        # format module.

        return getattr(handler.conf, format_name)
예제 #3
0
    def test_smart_text_2(self):
        from webtools.utils.encoding import smart_text

        res = smart_text(2)
        self.assertIsInstance(res, str)
        self.assertEqual(res, "2")
예제 #4
0
    def test_smart_text_1(self):
        from webtools.utils.encoding import smart_text

        res = smart_text(b"Foo")
        self.assertIsInstance(res, str)