Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

made module compatible with django 2.1, python 3.6 #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class MyModel(models.Model):
content2 = RichTextField(config='basic')
```


If you want to support image uploads, your admin needs to extend from `quill.admin.QuillAdmin`:

```python
Expand All @@ -49,6 +50,20 @@ class MyAdmin(QuillAdmin):
pass
```

If you don't want to touch your models and enable the editor for all text fields in the admin page,
you can do as well:

```python
from quill.widgets import QuillEditorWidget
from quill.admin import QuillAdmin


class MyAdmin(admin.ModelAdmin):
formfield_overrides = {
models.TextField: {'widget': QuillEditorWidget},
}
```

### Customizing

To customize this app, extend ``apps.QuillConfig`` and modify whatever you need. For example, to add a new toolbar:
Expand Down
7 changes: 3 additions & 4 deletions quill/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json

from django.conf.urls import patterns, url
from django.conf.urls import url
from django.contrib import admin
from django.core.files.storage import default_storage
from django.http import Http404, HttpResponse, HttpResponseBadRequest
Expand All @@ -14,10 +14,9 @@ class QuillAdmin(admin.ModelAdmin):

def get_urls(self):
"""Add URLs needed to handle image uploads."""
urls = patterns(
'',
urls = [
url(r'^upload/$', self.admin_site.admin_view(self.handle_upload), name='quill-file-upload'),
)
]
return urls + super(QuillAdmin, self).get_urls()

def handle_upload(self, request):
Expand Down
4 changes: 2 additions & 2 deletions quill/templatetags/quill_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def render_toolbar(context, config):
"""Render the toolbar for the given config."""
quill_config = getattr(quill_app, config)
t = template.loader.get_template(quill_config['toolbar_template'])
return t.render(context)
return t.render(context.flatten())


@register.simple_tag(takes_context=True)
def render_editor(context, config):
"""Render the editor for the given config."""
quill_config = getattr(quill_app, config)
t = template.loader.get_template(quill_config['editor_template'])
return t.render(context)
return t.render(context.flatten())
6 changes: 3 additions & 3 deletions quill/widgets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django import forms
from django.apps import apps
from django.forms.util import flatatt
from django.forms.utils import flatatt
from django.template.loader import render_to_string
from django.templatetags.static import static
from django.utils.safestring import mark_safe
Expand Down Expand Up @@ -32,11 +32,11 @@ def __init__(self, config='default', *args, **kwargs):
self.config = config
super(QuillEditorWidget, self).__init__(*args, **kwargs)

def render(self, name, value, attrs={}):
def render(self, name, value, attrs=None, renderer=None):
"""Render the Quill WYSIWYG."""
if value is None:
value = ''
final_attrs = self.build_attrs(attrs, name=name)
final_attrs = self.build_attrs(attrs, {'name': name})
quill_app = apps.get_app_config('quill')
quill_config = getattr(quill_app, self.config)

Expand Down