Alternative link dialog for ckeditor 4, using django modeladmin forms.
Reason this release was yanked:
should be 0.5.2...
Project description
django-ckeditor-link
Build status fails sometimes - selenium and iframes and ... sleep. Passes with local tox, believe me.
link plugin for ckeditor, based on django modelforms/modeladmin, allowing direct linking to your models, or to whatever your want.
Table of contents
Installation
To get the latest stable release from PyPi
pip install django-ckeditor-link
Add ckeditor_link
to your INSTALLED_APPS
INSTALLED_APPS = (
...,
'ckeditor_link',
)
ckeditor_link does not need it's own database tables, so no need to migrate.
If you want an out of the box solution for linking, you can add ckeditor_link.link_model
to your
INSTALLED_APPS
. Warning, EXPERIMENTAL feature.
Usage / Examples
Have a look at ckeditor_link/tests/test_app/settings_test.py
for a complete example.
Following steps are needed.
-
Define a link model. Proposed way: Create an abstract base model, that you can extend from for example when having a teaser model. And a CKLink model, whose purpose is only to provide a modelform and validation. No data is ever written to that table, if used with DjangoLinkAdmin.
# your_app/models.py @python_2_unicode_compatible class LinkModelBase(models.Model): target = models.CharField(max_length=255, blank=True, default='', ) external_url = models.CharField(max_length=255, blank=True, default='',) email = models.EmailField(blank=True, default='',) testmodel = models.ForeignKey(TestModel, null=True, default=None, blank=True) class Meta: abstract = True def __str__(self): # do it better return "LINK! %s" % self.target def get_link(self): # return link value, based on fields. return "http://www.dynamic.com" class LinkModel(LinkModelBase): pass class Teaser(LinkModelBase): image = models.ImageField() title = models.CharField() text = models.TextField()
For your convinience, we provide a basic abstract link model, and a django-cms / django-filer compatible version, under
ckeditor_link.link_model.models
. They are namedLinkBase
andCMSFilerLinkBase
, and thought to inherit from. To use them, you would need to addckeditor_link.link_model
toINSTALLED_APPS
in your settings. To use the cms / filer version, you'll need to setCKEDITOR_LINK_USE_CMS_FILER
to True in your settings. You can provide your own LINK_TYPE_CHOICES, if you add some more fields, withsettings.CKEDITOR_LINK_TYPE_CHOICES
. -
Register your model with DjangoLinkAdmin.
# your_app/admin.py ... from ckeditor_link.admin import DjangoLinkAdmin class LinkModelAdmin(DjangoLinkAdmin): pass admin.site.register(LinkModel, LinkModelAdmin)
-
Configure your django-ckeditor (or whatever ck you use).
# config for django-ckeditor CKEDITOR_LINK_MODEL = 'my_app.models.LinkModel' CKEDITOR_LINK_IFRAME_URL = reverse_lazy('admin:my_app_linkmodel_add') CKEDITOR_LINK_VERIFY_URL = reverse_lazy('admin:my_app_linkmodel_verify') CKEDITOR_CONFIGS = { 'default': { 'djangolinkIframeURL': CKEDITOR_LINK_IFRAME_URL, 'djangolinkVerifyURL': CKEDITOR_LINK_VERIFY_URL, 'djangolinkFallbackField': 'external', 'extraPlugins': ','.join( [ # your extra plugins here 'djangolink', ]), 'toolbar': 'Custom', 'toolbar_Custom': [ ['Bold', 'Underline'], ['DjangoLink', 'Unlink'], ] } }
If you have existing content with normal
<a href="">
style links, you can migrate them into ckeditor-link mode: In the ckeditor configs, specify your model field asdjangolinkFallbackField
(see above), existing href values will show up in that field (and stay there). -
In your template, use the django-ckeditor-link templatetag. This adds
lxml
andcssselect
as dependencies - you must install those yourself.{% load ckeditor_link_tags %} {% object.html_field|ckeditor_link_add_link %}
If your linkmodel has a multi widget (as the django-cms's PageField), you can use the
CKEDITOR_LINK_ATTR_MODIFIERS
setting, to modify attributes as you like. Example:
```
# a default, working with the provided contrib link_model and django-cms
CKEDITOR_LINK_ATTR_MODIFIERS = getattr(
settings,
'CKEDITOR_LINK_ATTR_MODIFIERS', {
'cms_page': '{cms_page_2}'
}
)
```
The actual value of cms_page
will be formatted with the python format(**kwargs)
function, where kwargs are the link's
data attributes and it's values (without data-
).
Settings
CKEDITOR_LINK_MODEL (default: None
)
# needed when using the ckeditor_link_add_links template filter, otherwise not
CKEDITOR_LINK_MODEL = 'my_app.models.LinkModel'
CKEDITOR_LINK_USE_CMS_FILER (default: True
if django-cms and django-filer in INSTALLED_APPS)
# when using the ckeditor_link.link_model app, enable cms and filer integration
CKEDITOR_LINK_MODEL_USE_FILER_ADDONS (default: False
)
# when using filer integration, use django-filer-addons.filer_gui admin field
CKEDITOR_LINK_ATTR_MODIFIERS (default: {'cms_page': '{cms_page_2}'}
)
# needed when using the ckeditor_link_add_links template filter
# used to combine multi widgets values, to be in a valid form.
# django-cms own "PageField" needs this
CKEDITOR_LINK_ATTR_MODIFIERS = {
'multi_widget_field': '{multi_widget_field_1}--{multi_widget_field_whatever}'
'cms_page': '{cms_page_2}'
}
Django Compatibility
Please refer to the CHANGELOG.txt for current supported django versions.
Contribute
Fork and code. Quickstart:
pip install -r test_requirements.txt
./manage.py migrate # create local sqlite db
./manage.py createsuperuser # you want that
./manage.py loaddata test_app # same data that is used for running tests
./manage.py runserver # goto localhost:8000/admin/ or localhost:8000/testmodel/2/
Testing
Either run tox
for complete tests, or `python manage.py test
geckodriver install
- visit https://github.com/mozilla/geckodriver/releases
- download the latest version of "geckodriver-vX.XX.X-linux64.tar.gz"
- unarchive the tarball (tar -xvzf geckodriver-vX.XX.X-linux64.tar.gz)
- give executable permissions to geckodriver (chmod +x geckodriver)
- move the geckodriver binary to /usr/local/bin or any location on your system PATH.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_ckeditor_link-0.5.3.dev0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d1f92a65024980099c0e105e9386d5a8ae3c83e31c7ebc3b4463f981b93732c |
|
MD5 | e3b35c15c9a20a14b1db7cce270910be |
|
BLAKE2b-256 | 1e527d417b550cbbb3845205e25fd8921130a61d7cd41c467a6abe8a6503e0be |
Hashes for django_ckeditor_link-0.5.3.dev0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eeb72342205bcdeaebea84328dd4ecf940d611beaadc4240f523a9e3a443556c |
|
MD5 | 6bcb3b26ac582581c966e9ad537e932f |
|
BLAKE2b-256 | e2086613156fe4b2b06159dcbc37bf007c35559bc2352ad5ea36e12029032859 |