django-simditor2


Namedjango-simditor2 JSON
Version 0.2 PyPI version JSON
download
home_pagehttps://github.com/sai628/django-simditor2
SummaryA Django admin Simditor integration.
upload_time2024-03-28 15:19:01
maintainerNone
docs_urlNone
authorSai628
requires_pythonNone
licenseMIT License
keywords django admin simditor integration
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # django-simditor2

Installation
------------

```bash
pip install django-simditor2
```

**Add `simditor` to your `INSTALLED_APPS` setting.**

```python
from django.db import models
from simditor.fields import RichTextField


class Post(models.Model):
    content = RichTextField()
```

**emoji**

![](resources/emoji.png)

**Markdown**

![](resources/markdown.gif)

**Image upload config**

*drop image*

![](resources/dropimage.gif)

*clipboard image*

![](resources/clipboardimage.gif)


`urls.py`


```python
urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^simditor/', include('simditor.urls'))   # add this line
]
```

`settings.py`

```python
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'simditor'
]

SIMDITOR_UPLOAD_PATH = 'uploads/'
SIMDITOR_IMAGE_BACKEND = 'pillow'

SIMDITOR_TOOLBAR = [
    'title', 'bold', 'italic', 'underline', 'strikethrough', 'fontScale',
    'color', '|', 'ol', 'ul', 'blockquote', 'code', 'table', '|', 'link',
    'image', 'hr', '|', 'indent', 'outdent', 'alignment', 'fullscreen',
    'markdown', 'emoji'
]

SIMDITOR_CONFIGS = {
    'toolbar': SIMDITOR_TOOLBAR,
    'upload': {
        'url': '/simditor/upload/',
        'fileKey': 'upload',
        'image_size': 1024 * 1024 * 4   # max image size 4MB
    },
    'emoji': {
        'imagePath': '/static/simditor/images/emoji/'
    }
}
```

<br/>

#### the following settings only v0.2 support:

If you want to over the date_path format in upload_path:

```python
# settings.py file:
SIMDITOR_UPLOAD_PATH = 'uploads/%Y%m%d/'  # or whatever datetime format you want
```

<br/>

If you want to be able to have control over filename generation, you have to add a custom filename generator to your settings:

```python
# create a file: utils.py, and define a function
def get_filename(filename, request):
    return filename.upper()  # or return whatever you want
```

```python
# settings.py file:
SIMDITOR_FILENAME_GENERATOR = 'utils.get_filename'
```

<br/>

## without django admin demo

![](./resources/without_admin.gif)

```python
from django.views import generic
from django.views.decorators.csrf import csrf_exempt

from simditor.views import upload_handler


class ImageUploadView(generic.View):
    """ImageUploadView."""

    http_method_names = ['post']

    def post(self, request, **kwargs):
        """Post."""
        return upload_handler(request)


urlpatterns = [
    url(r'^$', IndexView.as_view(), name='simditor-form'),
    url(r'^simditor/upload', csrf_exempt(ImageUploadView.as_view())),
]
```

```python
# IndexView
from django import forms

from django.views import generic

from simditor.fields import RichTextFormField
try:
    from django.urls import reverse
except ImportError:  # Django < 2.0
    from django.core.urlresolvers import reverse


class SimditorForm(forms.Form):
    content = RichTextFormField()


class IndexView(generic.FormView):
    form_class = SimditorForm

    template_name = 'index.html'

    def get_success_url(self):
        return reverse('simditor-form')
```

`index.html`

```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <form method="post" action="./">
        {% csrf_token %}
        {{ form.media }}
        {{ form.as_p }}
        <p><input type="submit" value="post"></p>
    </form>
</body>
</html>
```

> more detail you can check simditor_demo

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/sai628/django-simditor2",
    "name": "django-simditor2",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "Django admin Simditor integration",
    "author": "Sai628",
    "author_email": "sai100628@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/37/da/58e5d3ac9b0419b2c7b5a42840668f37b6b50df4ac7f5914fc9d49bc6660/django-simditor2-0.2.tar.gz",
    "platform": null,
    "description": "# django-simditor2\n\nInstallation\n------------\n\n```bash\npip install django-simditor2\n```\n\n**Add `simditor` to your `INSTALLED_APPS` setting.**\n\n```python\nfrom django.db import models\nfrom simditor.fields import RichTextField\n\n\nclass Post(models.Model):\n    content = RichTextField()\n```\n\n**emoji**\n\n![](resources/emoji.png)\n\n**Markdown**\n\n![](resources/markdown.gif)\n\n**Image upload config**\n\n*drop image*\n\n![](resources/dropimage.gif)\n\n*clipboard image*\n\n![](resources/clipboardimage.gif)\n\n\n`urls.py`\n\n\n```python\nurlpatterns = [\n    url(r'^admin/', admin.site.urls),\n    url(r'^simditor/', include('simditor.urls'))   # add this line\n]\n```\n\n`settings.py`\n\n```python\nINSTALLED_APPS = [\n    'django.contrib.admin',\n    'django.contrib.auth',\n    'django.contrib.contenttypes',\n    'django.contrib.sessions',\n    'django.contrib.messages',\n    'django.contrib.staticfiles',\n\n    'simditor'\n]\n\nSIMDITOR_UPLOAD_PATH = 'uploads/'\nSIMDITOR_IMAGE_BACKEND = 'pillow'\n\nSIMDITOR_TOOLBAR = [\n    'title', 'bold', 'italic', 'underline', 'strikethrough', 'fontScale',\n    'color', '|', 'ol', 'ul', 'blockquote', 'code', 'table', '|', 'link',\n    'image', 'hr', '|', 'indent', 'outdent', 'alignment', 'fullscreen',\n    'markdown', 'emoji'\n]\n\nSIMDITOR_CONFIGS = {\n    'toolbar': SIMDITOR_TOOLBAR,\n    'upload': {\n        'url': '/simditor/upload/',\n        'fileKey': 'upload',\n        'image_size': 1024 * 1024 * 4   # max image size 4MB\n    },\n    'emoji': {\n        'imagePath': '/static/simditor/images/emoji/'\n    }\n}\n```\n\n<br/>\n\n#### the following settings only v0.2 support:\n\nIf you want to over the date_path format in upload_path:\n\n```python\n# settings.py file:\nSIMDITOR_UPLOAD_PATH = 'uploads/%Y%m%d/'  # or whatever datetime format you want\n```\n\n<br/>\n\nIf you want to be able to have control over filename generation, you have to add a custom filename generator to your settings:\n\n```python\n# create a file: utils.py, and define a function\ndef get_filename(filename, request):\n    return filename.upper()  # or return whatever you want\n```\n\n```python\n# settings.py file:\nSIMDITOR_FILENAME_GENERATOR = 'utils.get_filename'\n```\n\n<br/>\n\n## without django admin demo\n\n![](./resources/without_admin.gif)\n\n```python\nfrom django.views import generic\nfrom django.views.decorators.csrf import csrf_exempt\n\nfrom simditor.views import upload_handler\n\n\nclass ImageUploadView(generic.View):\n    \"\"\"ImageUploadView.\"\"\"\n\n    http_method_names = ['post']\n\n    def post(self, request, **kwargs):\n        \"\"\"Post.\"\"\"\n        return upload_handler(request)\n\n\nurlpatterns = [\n    url(r'^$', IndexView.as_view(), name='simditor-form'),\n    url(r'^simditor/upload', csrf_exempt(ImageUploadView.as_view())),\n]\n```\n\n```python\n# IndexView\nfrom django import forms\n\nfrom django.views import generic\n\nfrom simditor.fields import RichTextFormField\ntry:\n    from django.urls import reverse\nexcept ImportError:  # Django < 2.0\n    from django.core.urlresolvers import reverse\n\n\nclass SimditorForm(forms.Form):\n    content = RichTextFormField()\n\n\nclass IndexView(generic.FormView):\n    form_class = SimditorForm\n\n    template_name = 'index.html'\n\n    def get_success_url(self):\n        return reverse('simditor-form')\n```\n\n`index.html`\n\n```html\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <title>Document</title>\n</head>\n<body>\n    <form method=\"post\" action=\"./\">\n        {% csrf_token %}\n        {{ form.media }}\n        {{ form.as_p }}\n        <p><input type=\"submit\" value=\"post\"></p>\n    </form>\n</body>\n</html>\n```\n\n> more detail you can check simditor_demo\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "A Django admin Simditor integration.",
    "version": "0.2",
    "project_urls": {
        "Homepage": "https://github.com/sai628/django-simditor2"
    },
    "split_keywords": [
        "django",
        "admin",
        "simditor",
        "integration"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "00bfe254e0c1d2587cf0a5c4895cc051156021a4e949c6d4d7fdb9f157d3b67e",
                "md5": "ed4e215840190be6f28218fe0f5c28a0",
                "sha256": "123244a061c24d418ce92fd3cfb9ce864be63a407cea196972cc84ece14b0a8f"
            },
            "downloads": -1,
            "filename": "django_simditor2-0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ed4e215840190be6f28218fe0f5c28a0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4386291,
            "upload_time": "2024-03-28T15:18:57",
            "upload_time_iso_8601": "2024-03-28T15:18:57.627531Z",
            "url": "https://files.pythonhosted.org/packages/00/bf/e254e0c1d2587cf0a5c4895cc051156021a4e949c6d4d7fdb9f157d3b67e/django_simditor2-0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "37da58e5d3ac9b0419b2c7b5a42840668f37b6b50df4ac7f5914fc9d49bc6660",
                "md5": "d50dd8c93b757cb030a578608ee0cb72",
                "sha256": "fd8a99d9df93ccee15f2d75ed5ccd209c19fe272e2122605795b30a71bf4b0d3"
            },
            "downloads": -1,
            "filename": "django-simditor2-0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "d50dd8c93b757cb030a578608ee0cb72",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4157367,
            "upload_time": "2024-03-28T15:19:01",
            "upload_time_iso_8601": "2024-03-28T15:19:01.127549Z",
            "url": "https://files.pythonhosted.org/packages/37/da/58e5d3ac9b0419b2c7b5a42840668f37b6b50df4ac7f5914fc9d49bc6660/django-simditor2-0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-28 15:19:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sai628",
    "github_project": "django-simditor2",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "django-simditor2"
}
        
Elapsed time: 0.45332s