Example #1
0
    def get(self, layout_name):
        def _verify_statics(static_file):
            user_tiles_path = os.path.join(
                os.path.expanduser('~'), '.tipboard/custom_tiles'
            )
            tipboard_tiles_path = os.path.join(settings.TIPBOARD_PATH, 'tiles')
            found = False
            for path in user_tiles_path, tipboard_tiles_path:
                if os.path.exists(os.path.join(path, static_file)):
                    found = True
                    break
            return found

        def _tile_path(tile_name):
            """
            Searches for tile's html file (in user's 'custom_tiles' folder,
            and then in app's 'tiles' folder) and returns full path of
            the tile, or raises exception if html file is not present in none
            of those locations.
            """
            user_tiles_path = os.path.join(
                os.path.expanduser('~'), '.tipboard/custom_tiles'
            )
            tipboard_tiles_path = os.path.join(settings.TIPBOARD_PATH, 'tiles')
            tile_html = '.'.join((tile_name, 'html'))
            for path in user_tiles_path, tipboard_tiles_path:
                tile_path = os.path.join(path, tile_html)
                if os.path.exists(tile_path):
                    return tile_path
            raise UserWarning('No such tile: %s' % tile_name)

        try:
            config = process_layout_config(layout_name or 'layout_config')
        except IOError as e:
            msg = '<br>'.join([
                '<div style="color: red">',
                'No config file found for dashboard: {}'.format(layout_name),
                'Make sure that file: "{}" exists.'.format(e.filename),
                '</div>',
            ])
            self.write(msg)
            return

        tiles_js = ['.'.join((name, 'js')) for name in config['tiles_names']]
        tiles_js = filter(_verify_statics, tiles_js)
        tiles_css = ['.'.join((name, 'css')) for name in config['tiles_names']]
        tiles_css = filter(_verify_statics, tiles_css)
        self.render(
            'layout.html',
            details=config['details'],
            layout=config['layout'],
            tipboard_css=settings.TIPBOARD_CSS_STYLES,
            tipboard_js=settings.TIPBOARD_JAVASCRIPTS,
            tiles_css=tiles_css,
            tiles_js=tiles_js,
            tile_path=_tile_path,
        )
Example #2
0
    def get(self, layout_name):
        def _verify_statics(static_file):
            user_tiles_path = os.path.join(
                os.path.expanduser('~'), '.tipboard/custom_tiles'
            )
            tipboard_tiles_path = os.path.join(settings.TIPBOARD_PATH, 'tiles')
            found = False
            for path in user_tiles_path, tipboard_tiles_path:
                if os.path.exists(os.path.join(path, static_file)):
                    found = True
                    break
            return found

        def _tile_path(tile_name):
            """
            Searches for tile's html file (in user's 'custom_tiles' folder,
            and then in app's 'tiles' folder) and returns full path of
            the tile, or raises exception if html file is not present in none
            of those locations.
            """
            user_tiles_path = os.path.join(
                os.path.expanduser('~'), '.tipboard/custom_tiles'
            )
            tipboard_tiles_path = os.path.join(settings.TIPBOARD_PATH, 'tiles')
            tile_html = '.'.join((tile_name, 'html'))
            for path in user_tiles_path, tipboard_tiles_path:
                tile_path = os.path.join(path, tile_html)
                if os.path.exists(tile_path):
                    return tile_path
            raise UserWarning('No such tile: %s' % tile_name)

        try:
            config = process_layout_config(layout_name or 'layout_config')
        except IOError as e:
            msg = '<br>'.join([
                '<div style="color: red">',
                'No config file found for dashboard: {}'.format(layout_name),
                'Make sure that file: "{}" exists.'.format(e.filename),
                '</div>',
            ])
            self.write(msg)
            return

        tiles_js = ['.'.join((name, 'js')) for name in config['tiles_names']]
        tiles_js = filter(_verify_statics, tiles_js)
        tiles_css = ['.'.join((name, 'css')) for name in config['tiles_names']]
        tiles_css = filter(_verify_statics, tiles_css)
        self.render(
            'layout.html',
            details=config['details'],
            layout=config['layout'],
            tipboard_css=settings.TIPBOARD_CSS_STYLES,
            tipboard_js=settings.TIPBOARD_JAVASCRIPTS,
            tiles_css=tiles_css,
            tiles_js=tiles_js,
            tile_path=_tile_path,
        )
Example #3
0
 def test_get_rows(self):
     """simple call of get_rows method and check rows count"""
     EXPECTED = 2
     config_file = parser.process_layout_config(DEFAULT_CONFIG_NAME)
     found_rows = parser._get_rows(config_file['layout'])
     rows_count = len(found_rows)
     msg = u'Found {} rows instead of expected {}'.format(
         rows_count, EXPECTED)
     self.assertEqual(rows_count, EXPECTED, msg)
Example #4
0
 def test_get_rows(self):
     """simple call of get_rows method and check rows count"""
     EXPECTED = 2
     config_file = parser.process_layout_config(DEFAULT_CONFIG_NAME)
     found_rows = parser._get_rows(config_file['layout'])
     rows_count = len(found_rows)
     msg = u'Found {} rows instead of expected {}'.format(
         rows_count, EXPECTED
     )
     self.assertEqual(rows_count, EXPECTED, msg)
Example #5
0
 def get_flipboard_title(self):
     """
     Returns title to display as a html title.
     """
     title = ""
     config_names = self._get_config_names()
     if len(config_names) == 1:
         config = process_layout_config(config_names[0])
         try:
             title = config["details"]["page_title"]
         except KeyError:
             msg = "config {} has no key: details/page_title".format(config_names[0])
             log.error(msg)
     elif len(config_names) > 1:
         # TODO: put here more suitable title?
         title = "Flipboard Mode"
     return title
Example #6
0
 def get_flipboard_title(self):
     """
     Returns title to display as a html title.
     """
     title = ''
     config_names = self._get_config_names()
     if len(config_names) == 1:
         config = process_layout_config(config_names[0])
         try:
             title = config['details']['page_title']
         except KeyError:
             msg = 'config {} has no key: details/page_title'.format(
                 config_names[0])
             log.error(msg)
     elif len(config_names) > 1:
         # TODO: put here more suitable title?
         title = 'Flipboard Mode'
     return title
Example #7
0
 def test_get_rows_cols_validator(self):
     """
     negative test: checks if parser's get_rows method find wrong rows count
     """
     config_file = parser.process_layout_config(DEFAULT_CONFIG_NAME)
     broken_layout = config_file['layout'][:]
     popped_row = broken_layout.pop()
     row_class, cols_data = popped_row.items()[0]
     broken_key = row_class.replace('1', '5')
     broken_row = {
         broken_key: cols_data,
     }
     broken_layout.append(broken_row)
     try:
         parser._get_rows(broken_layout)
     except parser.WrongSumOfRows:
         # test passed
         pass
     else:
         raise Exception("Parser's get_rows method skipped layout error")
Example #8
0
 def test_get_rows_cols_validator(self):
     """
     negative test: checks if parser's get_rows method find wrong rows count
     """
     config_file = parser.process_layout_config(DEFAULT_CONFIG_NAME)
     broken_layout = config_file['layout'][:]
     popped_row = broken_layout.pop()
     row_class, cols_data = popped_row.items()[0]
     broken_key = row_class.replace('1', '5')
     broken_row = {
         broken_key: cols_data,
     }
     broken_layout.append(broken_row)
     try:
         parser._get_rows(broken_layout)
     except parser.WrongSumOfRows:
         # test passed
         pass
     else:
         raise Exception("Parser's get_rows method skipped layout error")