コード例 #1
0
ファイル: factory.py プロジェクト: GMcD/django-dash
def plugin_factory(base_class, plugin_uid_prefix, sizes=[]):
    """
    Plugin factory.

    :param dash.base.BaseDashboardWidget base_class: Subclass of.
    :param string layout_uid:
    :param string placeholder_uid:
    :param string plugin_uid_prefix:
    :param iterable sizes: Iterable of tuples.

    :example:
    >>> from dash.contrib.plugins.image.dash_plugins import BaseImagePlugin
    >>> plugin_factory(BaseImagePlugin, 'image', zip(range(6, 10), range(6, 10)))

    The example above will update the plugin registry with the following dictionary:
    >>> {
    >>>     'image_6x6': dash.factory.Plugin,
    >>>     'image_7x7': dash.factory.Plugin,
    >>>     'image_8x8': dash.factory.Plugin,
    >>>     'image_9x9': dash.factory.Plugin,
    >>> }

    The generated class (one of them), would look as follows:

    >>> class Plugin(BaseImagePlugin):
    >>>     uid = 'image_6x6'

    The ``uid`` property is generated automatically.
    """
    for cols, rows in sizes:

        plugin_uid = "{plugin_uid_prefix}_{cols}x{rows}".format(
            plugin_uid_prefix = plugin_uid_prefix,
            cols = cols,
            rows = rows
            )

        class PluginMeta(type):
            """
            Dynamically created plugin plugin meta class.
            """
            def __new__(cls, name, bases, props):
                props['uid'] = plugin_uid
                return type.__new__(cls, name, bases, props)

        class Plugin(with_metaclass(PluginMeta, base_class)):
            """
            Dynamically created plugin class.
            """

        plugin_registry.register(Plugin)
コード例 #2
0
def plugin_factory(base_class, plugin_uid_prefix, sizes=[]):
    """
    Plugin factory.

    :param dash.base.BaseDashboardWidget base_class: Subclass of.
    :param string layout_uid:
    :param string placeholder_uid:
    :param string plugin_uid_prefix:
    :param iterable sizes: Iterable of tuples.

    :example:
    >>> from dash.contrib.plugins.image.dash_plugins import BaseImagePlugin
    >>> plugin_factory(BaseImagePlugin, 'image', zip(range(6, 10), range(6, 10)))

    The example above will update the plugin registry with the following dictionary:
    >>> {
    >>>     'image_6x6': dash.factory.Plugin,
    >>>     'image_7x7': dash.factory.Plugin,
    >>>     'image_8x8': dash.factory.Plugin,
    >>>     'image_9x9': dash.factory.Plugin,
    >>> }

    The generated class (one of them), would look as follows:

    >>> class Plugin(BaseImagePlugin):
    >>>     uid = 'image_6x6'

    The ``uid`` property is generated automatically.
    """
    for cols, rows in sizes:

        plugin_uid = "{plugin_uid_prefix}_{cols}x{rows}".format(
            plugin_uid_prefix=plugin_uid_prefix, cols=cols, rows=rows)

        class PluginMeta(type):
            """
            Dynamically created plugin plugin meta class.
            """
            def __new__(cls, name, bases, props):
                props['uid'] = plugin_uid
                return type.__new__(cls, name, bases, props)

        class Plugin(with_metaclass(PluginMeta, base_class)):
            """
            Dynamically created plugin class.
            """

        plugin_registry.register(Plugin)
コード例 #3
0
__author__ = 'Artur Barseghyan <*****@*****.**>'
__copyright__ = '2013-2018 Artur Barseghyan'
__license__ = 'GPL 2.0/LGPL 2.1'

# ******************************************************
# ******************Extended plugins *******************
# ******************************************************


class Image3x8Plugin(BaseImagePlugin):
    """Image3x8 dashboard plugin."""

    uid = 'image_3x8'


plugin_registry.register(Image3x8Plugin)


class Image8x1Plugin(BaseImagePlugin):
    """Image3x8 dashboard plugin."""

    uid = 'image_8x1'


plugin_registry.register(Image8x1Plugin)

# ******************************************************
# ***************** Registering widgets ****************
# ******************************************************

# Registering dummy plugin widgets
コード例 #4
0
ファイル: dash_plugins.py プロジェクト: ykkwon/django-dash
# **************************************************************************


class URLBootstrapTwo1x1Plugin(BaseURLPlugin):
    """
    URL dashboard plugin. The original `URLPlugin`, as well as the main
    dash.css, relies on presence of wonderful "Font awesome". Although a lot
    of icon names are common between Bootstrap 2 and Font awesome, there are
    some specific icons, that are not present in both. Thus, the original
    `URLPlugin` is extended to address those differences.
    """
    uid = 'url_bootstrap_two_1x1'
    form = URLBootstrapTwoForm


plugin_registry.register(URLBootstrapTwo1x1Plugin)


class URLBootstrapTwo2x2Plugin(URLBootstrapTwo1x1Plugin):
    """
    URL dashboard plugin.
    """
    uid = 'url_bootstrap_two_2x2'


plugin_registry.register(URLBootstrapTwo2x2Plugin)

# **************************************************************************
# **************************************************************************
# ************************** Registering the widgets ***********************
# **************************************************************************
コード例 #5
0
# ******************************* Read RSS feed plugin **********************
# ***************************************************************************


class ReadRSSFeed2x3Plugin(BaseDashboardPlugin):
    """
    Read RSS feed into HTML plugin.
    """

    uid = "read_rss_feed_2x3"
    name = _("Read RSS feed")
    form = ReadRSSFeedForm
    group = _("Internet")


plugin_registry.register(ReadRSSFeed2x3Plugin)

# ***************************************************************************
# ******************************* Read RSS feed plugin **********************
# ***************************************************************************


class ReadRSSFeed3x3Plugin(ReadRSSFeed2x3Plugin):
    """
    Big read RSS feed into HTML plugin.
    """

    uid = "read_rss_feed_3x3"
    name = _("Read RSS feed")

コード例 #6
0
ファイル: dash_plugins.py プロジェクト: danrue/django-dash
class Video2x2Plugin(BaseDashboardPlugin):
    """
    Video dashboard plugin.
    """
    uid = 'video_2x2'
    name = _("Video")
    group = _("Internet")
    form = VideoForm
    html_classes = ['video']

    def post_processor(self):
        self.data.embed_code = render_video(self.data.url)


plugin_registry.register(Video2x2Plugin)


# *************************************************************************
# ******************************* Big video plugin ************************
# *************************************************************************

class Video3x3Plugin(Video2x2Plugin):
    """
    Video dashboard plugin.
    """
    uid = 'video_3x3'
    name = _("Video")


plugin_registry.register(Video3x3Plugin)
コード例 #7
0
    URL dashboard plugin.
    """
    uid = 'url_1x1'
    name = _("URL")
    group = _("URLs")
    form = URLForm

    @property
    def html_class(self):
        """
        If plugin has an image, we add a class `iconic` to it.
        """
        html_class = super(URL1x1Plugin, self).html_class
        if self.data.image:
            html_class += ' iconic-url'
        return html_class

plugin_registry.register(URL1x1Plugin)

# *************************************************************************
# ****************** Registering the widgets for URL plugin ***************
# *************************************************************************

# Registering the Android widgets for URL plugin.
plugin_widget_registry.register(URL1x1AndroidMainWidget)
plugin_widget_registry.register(URL1x1AndroidShortcutWidget)

# Registering the Windows8widgets for URL plugin.
plugin_widget_registry.register(URL1x1Windows8MainWidget)
plugin_widget_registry.register(URL1x1Windows8SidebarWidget)
コード例 #8
0
# **************************************************************************
# ******************************* MemoPlugin *******************************
# **************************************************************************

class Memo2x2Plugin(BaseDashboardPlugin):
    """
    Memo dashboard plugin.
    """
    uid = 'memo_2x2'
    name = _("Memo")
    group = _("Memo")
    form = MemoForm


plugin_registry.register(Memo2x2Plugin)

# **************************************************************************
# ******************************* Memo1x1 Plugin ***************************
# **************************************************************************

class Memo1x1Plugin(Memo2x2Plugin):
    """
    Memo1x1 dashboard plugin.
    """
    uid = 'memo_1x1'

plugin_registry.register(Memo1x1Plugin)

# **************************************************************************
# ******************************* Big memo plugin **************************
コード例 #9
0
ファイル: dash_plugins.py プロジェクト: danrue/django-dash
# ******************************************************
# ******************* Custom plugins *******************
# ******************************************************

class URLBootstrapTwo1x1Plugin(URL1x1Plugin):
    """
    URL dashboard plugin. The original `URLPlugin`, as well as the main dash.css, relies on presence of
    wonderful "Font awesome". Although a lot of icon names are common between Bootstrap 2 and Font awesome,
    there are some specific icons, that are not present in both. Thus, the original `URLPlugin` is
    extended to address those differences.
    """
    uid = 'url_bootstrap_two_1x1'
    form = URLBootstrapTwoForm


plugin_registry.register(URLBootstrapTwo1x1Plugin)


class URLBootstrapTwo2x2Plugin(URLBootstrapTwo1x1Plugin):
    """
    URL dashboard plugin.
    """
    uid = 'url_bootstrap_two_2x2'


plugin_registry.register(URLBootstrapTwo2x2Plugin)

# ******************************************************
# ***************** Registering widgets ****************
# ******************************************************
コード例 #10
0
ファイル: dash_plugins.py プロジェクト: danrue/django-dash
                self.data.temp_min_c = weather['tempMinC']
                self.data.windspeed_kmph = weather['windspeedKmph']
                self.data.wind_dir_16_point = weather['winddir16Point']

                try:
                    self.data.weather_desc = weather['weatherDesc'][0]['value']
                except Exception as e:
                    pass

                try:
                    self.data.weather_icon_url = weather['weatherIconUrl'][0]['value']
                except Exception as e:
                    pass


plugin_registry.register(Weather2x2Plugin)

# ********************************************************************************
# ******************************* Big weather plugin *****************************
# ********************************************************************************

class Weather3x3Plugin(Weather2x2Plugin):
    """
    Big weather dashboard plugin.
    """
    uid = 'weather_3x3'
    name = _("Weather")
    group = _("Weather")


plugin_registry.register(Weather3x3Plugin)
コード例 #11
0
ファイル: dash_plugins.py プロジェクト: danrue/django-dash
    def post_processor(self):
        """
        Getting news items for the current active language.
        """
        results_kwargs = {}

        language = get_language_from_request(self.request)
        if language is not None:
            results_kwargs.update({'language': language})

        self.data.news_items = NewsItem._default_manager.filter(**results_kwargs) \
                                       .order_by('-date_published')[:self.data.max_items]


plugin_registry.register(News2x5Plugin)

# ***************************************************************************
# ******************************* Huge news plugin **************************
# ***************************************************************************

class News4x5Plugin(BaseDashboardPlugin):
    """
    News plugin.
    """
    uid = 'news_4x5'
    name = _("News")
    form = NewsForm
    group = _("News")

コード例 #12
0
    def get_form(self):
        if 'sidebar' == self.placeholder:
            return DummyShortcutsForm
        else:
            return DummyForm

    def post_processor(self):
        """
        If no text available, use dummy.
        """
        if not self.data.text:
            self.data.text = 'Dummy content'


plugin_registry.register(Dummy1x1Plugin)

# ********************************************************************************
# ******************************* Large dummy plugin *****************************
# ********************************************************************************

class Dummy2x1Plugin(Dummy1x1Plugin):
    """
    (Large) dummy2x1 dashboard plugin.
    """
    uid = 'dummy_2x1'
    name = _("Dummy")
    group = _("Dummy")


plugin_registry.register(Dummy2x1Plugin)
コード例 #13
0
ファイル: dash_plugins.py プロジェクト: danrue/django-dash
    Image1x1 dashboard plugin.
    """
    uid = 'image_1x1'
    name = _("Image")
    group = _("Image")
    form = ImageForm
    html_classes = ['pictonic']

    def delete_plugin_data(self):
        """
        Deletes uploaded file.
        """
        delete_file(self.data.image)


plugin_registry.register(Image1x1Plugin)

# *************************************************************************
# ***************************** Image2x2 plugin ***************************
# *************************************************************************

class Image2x2Plugin(Image1x1Plugin):
    """
    Image2x2 dashboard plugin.
    """
    uid = 'image_2x2'

plugin_registry.register(Image2x2Plugin)

# *************************************************************************
# ***************************** Image2x3 plugin ***************************
コード例 #14
0
    def html_class(self):
        """
        If plugin has an image, we add a class `pictonic` to it.
        """
        html_class = super(Image1x1Plugin, self).html_class
        html_class += ' pictonic'
        return html_class

    def delete_plugin_data(self):
        """
        Deletes uploaded file.
        """
        delete_file(self.data.image)


plugin_registry.register(Image1x1Plugin)

# *************************************************************************
# ***************************** Image2x2 plugin ***************************
# *************************************************************************

class Image2x2Plugin(Image1x1Plugin):
    """
    Image2x2 dashboard plugin.
    """
    uid = 'image_2x2'

plugin_registry.register(Image2x2Plugin)

# *************************************************************************
# ***************************** Image3x3 plugin ***************************