django-mirror


Namedjango-mirror JSON
Version 0.1.6 PyPI version JSON
download
home_pagehttps://github.com/pavelsof/django-mirror
SummaryThis package marries Django with CodeMirror
upload_time2020-10-17 21:25:18
maintainer
docs_urlNone
authorpavelsof
requires_python>=3
license
keywords django codemirror
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            =============
django-mirror
=============

This package marries `Django`_ with `CodeMirror`_. It provides (1) a customisable form widget, and (2) a shorthand way to use this widget in the admin. In both cases the relevant static files (including mode/theme/addon files) are automatically included as form assets.


installation
============

This is a Python 3 package with no other dependencies apart from Django and it is offered at the `Cheese Shop`_:

.. code:: sh

    # usually inside a virtual environment
    pip install django-mirror

The CodeMirror files (version `5.58.1`_) are included in the package.


settings
========

.. code:: python

    # add 'django_mirror' to your INSTALLED_APPS if you want the package to be
    # handled by Django's collectstatic command
    INSTALLED_APPS += ['django_mirror']

    # use DJANGO_MIRROR_DEFAULTS to specify default options for your widgets
    # see the next section for more info about the options
    DJANGO_MIRROR_DEFAULTS = {
        'mode': 'rst',
        'addons': ['mode/overlay'],
        'line_wrapping': True,
    }


widget
======

Bascially this package provides a form widget called ``MirrorArea`` that extends Django's ``Textarea`` widget.

.. code:: python

    from django import forms
    from django_mirror.widgets import MirrorTextarea

    class CommentForm(forms.Form):
        text = forms.CharField(
            widget=MirrorArea(
                attrs={'rows': 20},  # the parent class' attrs still works
                mode='markdown',  # the other kwargs are forwarded to CodeMirror
            )
        )

The ``MirrorArea`` widget can be initialised with the following arguments:

- Any of CodeMirror's `config options`_. These can be specified in either camelCase or snake_case (e.g. both ``tabSize`` and ``tab_size`` would work). The css/js files associated with the ``mode``, if provided, are included as form assets.
- ``addons``, a list of CodeMirror `addons`_, e.g. ``dialog/dialog``. The css/js files associated with the addons are recursively included as form assets.
- ``attrs``, just as Django's form widgets.

The addons and config options are merged with and override ``DJANGO_MIRROR_DEFAULTS`` if the setting has been defined.


admin
=====

If you want to use the widget in the admin panel, you can subclass the ``MirrorAdmin`` mixin, which provides the ``mirror_fields`` model admin option:

.. code:: python

    from django.contrib import admin
    from django_mirror.admin import MirrorAdmin

    from weblog.models import Comment


    @admin.register(Comment)
    class CommentAdmin(MirrorAdmin, admin.ModelAdmin):
        mirror_fields = ('comment',)  # default options
        mirror_fields = (  # with custom options
            ('comment', {
                'mode': 'markdown',
                'line_wrapping': True,
            })
        )

The mixin also includes a bit of css to make CodeMirror look more like regular admin textarea fields.


similar projects
================

There are several other packages that provide customisable CodeMirror widgets:

* `django-codemirror`_
* `django-codemirror2`_
* `django-codemirror-widget`_
* `django-codemirror-widget-2`_


licence
=======

GPL. You can do what you want with this code as long as you let others do the same.


.. _`5.58.1`: https://github.com/codemirror/CodeMirror/releases/tag/5.58.1
.. _`addons`: https://codemirror.net/doc/manual.html#addons
.. _`Cheese Shop`: https://pypi.python.org/pypi/django-mirror
.. _`CodeMirror`: https://codemirror.net/
.. _`config options`: https://codemirror.net/doc/manual.html#config
.. _`Django`: https://www.djangoproject.com/
.. _`django-codemirror`: https://pypi.org/project/django-codemirror/
.. _`django-codemirror2`: https://pypi.org/project/django-codemirror2/
.. _`django-codemirror-widget`: https://pypi.org/project/django-codemirror-widget/
.. _`django-codemirror-widget-2`: https://pypi.org/project/django-codemirror-widget-2/



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pavelsof/django-mirror",
    "name": "django-mirror",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3",
    "maintainer_email": "",
    "keywords": "django codemirror",
    "author": "pavelsof",
    "author_email": "mail@pavelsof.com",
    "download_url": "https://files.pythonhosted.org/packages/bc/89/85e47dbe5ea2dee454794c4126f9709c9ba45f8399a033b47c1a655ab1ef/django-mirror-0.1.6.tar.gz",
    "platform": "",
    "description": "=============\ndjango-mirror\n=============\n\nThis package marries `Django`_ with `CodeMirror`_. It provides (1) a customisable form widget, and (2) a shorthand way to use this widget in the admin. In both cases the relevant static files (including mode/theme/addon files) are automatically included as form assets.\n\n\ninstallation\n============\n\nThis is a Python 3 package with no other dependencies apart from Django and it is offered at the `Cheese Shop`_:\n\n.. code:: sh\n\n    # usually inside a virtual environment\n    pip install django-mirror\n\nThe CodeMirror files (version `5.58.1`_) are included in the package.\n\n\nsettings\n========\n\n.. code:: python\n\n    # add 'django_mirror' to your INSTALLED_APPS if you want the package to be\n    # handled by Django's collectstatic command\n    INSTALLED_APPS += ['django_mirror']\n\n    # use DJANGO_MIRROR_DEFAULTS to specify default options for your widgets\n    # see the next section for more info about the options\n    DJANGO_MIRROR_DEFAULTS = {\n        'mode': 'rst',\n        'addons': ['mode/overlay'],\n        'line_wrapping': True,\n    }\n\n\nwidget\n======\n\nBascially this package provides a form widget called ``MirrorArea`` that extends Django's ``Textarea`` widget.\n\n.. code:: python\n\n    from django import forms\n    from django_mirror.widgets import MirrorTextarea\n\n    class CommentForm(forms.Form):\n        text = forms.CharField(\n            widget=MirrorArea(\n                attrs={'rows': 20},  # the parent class' attrs still works\n                mode='markdown',  # the other kwargs are forwarded to CodeMirror\n            )\n        )\n\nThe ``MirrorArea`` widget can be initialised with the following arguments:\n\n- Any of CodeMirror's `config options`_. These can be specified in either camelCase or snake_case (e.g. both ``tabSize`` and ``tab_size`` would work). The css/js files associated with the ``mode``, if provided, are included as form assets.\n- ``addons``, a list of CodeMirror `addons`_, e.g. ``dialog/dialog``. The css/js files associated with the addons are recursively included as form assets.\n- ``attrs``, just as Django's form widgets.\n\nThe addons and config options are merged with and override ``DJANGO_MIRROR_DEFAULTS`` if the setting has been defined.\n\n\nadmin\n=====\n\nIf you want to use the widget in the admin panel, you can subclass the ``MirrorAdmin`` mixin, which provides the ``mirror_fields`` model admin option:\n\n.. code:: python\n\n    from django.contrib import admin\n    from django_mirror.admin import MirrorAdmin\n\n    from weblog.models import Comment\n\n\n    @admin.register(Comment)\n    class CommentAdmin(MirrorAdmin, admin.ModelAdmin):\n        mirror_fields = ('comment',)  # default options\n        mirror_fields = (  # with custom options\n            ('comment', {\n                'mode': 'markdown',\n                'line_wrapping': True,\n            })\n        )\n\nThe mixin also includes a bit of css to make CodeMirror look more like regular admin textarea fields.\n\n\nsimilar projects\n================\n\nThere are several other packages that provide customisable CodeMirror widgets:\n\n* `django-codemirror`_\n* `django-codemirror2`_\n* `django-codemirror-widget`_\n* `django-codemirror-widget-2`_\n\n\nlicence\n=======\n\nGPL. You can do what you want with this code as long as you let others do the same.\n\n\n.. _`5.58.1`: https://github.com/codemirror/CodeMirror/releases/tag/5.58.1\n.. _`addons`: https://codemirror.net/doc/manual.html#addons\n.. _`Cheese Shop`: https://pypi.python.org/pypi/django-mirror\n.. _`CodeMirror`: https://codemirror.net/\n.. _`config options`: https://codemirror.net/doc/manual.html#config\n.. _`Django`: https://www.djangoproject.com/\n.. _`django-codemirror`: https://pypi.org/project/django-codemirror/\n.. _`django-codemirror2`: https://pypi.org/project/django-codemirror2/\n.. _`django-codemirror-widget`: https://pypi.org/project/django-codemirror-widget/\n.. _`django-codemirror-widget-2`: https://pypi.org/project/django-codemirror-widget-2/\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "This package marries Django with CodeMirror",
    "version": "0.1.6",
    "split_keywords": [
        "django",
        "codemirror"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "9da6be7a6fd800c385fc5cc667df0117",
                "sha256": "1c3694c1de31670cfcc5b30600607aaa58c719e2ada9f1074671048e1073d2c8"
            },
            "downloads": -1,
            "filename": "django_mirror-0.1.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9da6be7a6fd800c385fc5cc667df0117",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3",
            "size": 758538,
            "upload_time": "2020-10-17T21:25:14",
            "upload_time_iso_8601": "2020-10-17T21:25:14.939404Z",
            "url": "https://files.pythonhosted.org/packages/f8/c0/ae3f120b50ec96bfd7d149936bb2c6550b5a7f70de9e10a8db6d71d72870/django_mirror-0.1.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "7e8bc474be8e30b2e0477785c58d6a8b",
                "sha256": "f2d6b6f7e214e0baddeed60ecb78b538b9f9f03532bf4a1dce44f2f1fad18b6d"
            },
            "downloads": -1,
            "filename": "django-mirror-0.1.6.tar.gz",
            "has_sig": false,
            "md5_digest": "7e8bc474be8e30b2e0477785c58d6a8b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3",
            "size": 573608,
            "upload_time": "2020-10-17T21:25:18",
            "upload_time_iso_8601": "2020-10-17T21:25:18.594274Z",
            "url": "https://files.pythonhosted.org/packages/bc/89/85e47dbe5ea2dee454794c4126f9709c9ba45f8399a033b47c1a655ab1ef/django-mirror-0.1.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-10-17 21:25:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": null,
    "github_project": "pavelsof",
    "error": "Could not fetch GitHub repository",
    "lcname": "django-mirror"
}
        
Elapsed time: 0.21912s