diff --git a/setup.py b/setup.py
index b2a512f..a966688 100644
--- a/setup.py
+++ b/setup.py
@@ -9,7 +9,7 @@
setup(
name='wagtailembedder',
- version='0.1.4',
+ version='0.1.5',
packages=['wagtailembedder'],
include_package_data=True,
license='BSD License',
diff --git a/wagtailembedder/format.py b/wagtailembedder/format.py
index e7f1d83..8be2394 100644
--- a/wagtailembedder/format.py
+++ b/wagtailembedder/format.py
@@ -1,10 +1,13 @@
from django.core.exceptions import ObjectDoesNotExist
from django.template.loader import render_to_string
+
from wagtail.wagtailsnippets.views.snippets import get_content_type_from_url_params
-# from wagtail.wagtailembedder.embeds import get_embed
def embed_to_frontend_html(id, content_type_app_name, content_type_model_name):
+ """
+ Provides the Snippet representation through the appropiate template
+ """
try:
content_type = get_content_type_from_url_params(content_type_app_name, content_type_model_name)
model = content_type.model_class()
@@ -22,6 +25,9 @@ def embed_to_frontend_html(id, content_type_app_name, content_type_model_name):
def embed_to_editor_html(id, content_type_app_name, content_type_model_name):
+ """
+ Provides the Snippet representation to display in the RichTextEditor
+ """
try:
content_type = get_content_type_from_url_params(content_type_app_name, content_type_model_name)
model = content_type.model_class()
diff --git a/wagtailembedder/helper.py b/wagtailembedder/helper.py
index 34ff748..46cc4c3 100644
--- a/wagtailembedder/helper.py
+++ b/wagtailembedder/helper.py
@@ -1,4 +1,5 @@
from wagtail.wagtailcore.rich_text import EMBED_HANDLERS
+
from wagtailembedder.format import embed_to_editor_html, embed_to_frontend_html
diff --git a/wagtailembedder/static/wagtailembedder/js/hallo-embedder.js b/wagtailembedder/static/wagtailembedder/js/hallo-embedder.js
index 38ba34c..4a03fb6 100644
--- a/wagtailembedder/static/wagtailembedder/js/hallo-embedder.js
+++ b/wagtailembedder/static/wagtailembedder/js/hallo-embedder.js
@@ -1,3 +1,20 @@
+function placeCaretAtEnd(el) {
+ el.focus();
+ if (typeof window.getSelection != "undefined" && typeof document.createRange != "undefined") {
+ var range = document.createRange();
+ range.selectNodeContents(el);
+ range.collapse(false);
+ var sel = window.getSelection();
+ sel.removeAllRanges();
+ sel.addRange(range);
+ } else if (typeof document.body.createTextRange != "undefined") {
+ var textRange = document.body.createTextRange();
+ textRange.moveToElementText(el);
+ textRange.collapse(false);
+ textRange.select();
+ }
+}
+
(function() {
(function($) {
return $.widget("IKS.halloembedder", {
diff --git a/wagtailembedder/templates/wagtailembedder/snippets/types_list.html b/wagtailembedder/templates/wagtailembedder/snippets/types_list.html
index 34b5977..354cdd8 100644
--- a/wagtailembedder/templates/wagtailembedder/snippets/types_list.html
+++ b/wagtailembedder/templates/wagtailembedder/snippets/types_list.html
@@ -10,11 +10,11 @@
- {% for name, description, content_type in snippet_types %}
+ {% for app_label, name, description in snippet_types %}
-
diff --git a/wagtailembedder/views/chooser.py b/wagtailembedder/views/chooser.py
index 96d5350..a56ba81 100644
--- a/wagtailembedder/views/chooser.py
+++ b/wagtailembedder/views/chooser.py
@@ -7,18 +7,25 @@
from wagtail.wagtailsnippets.models import get_snippet_content_types
from wagtail.wagtailsnippets.permissions import user_can_edit_snippet_type
-from wagtail.wagtailsnippets.views.snippets import get_snippet_type_description, get_snippet_type_name
from wagtail.wagtailsnippets.views.snippets import get_content_type_from_url_params
+from wagtail.wagtailsnippets.models import get_snippet_models
+
from wagtailembedder.format import embed_to_editor_html
@permission_required('wagtailadmin.access_admin')
def index(request):
- snippet_types = [(
- get_snippet_type_name(content_type)[1],
- get_snippet_type_description(content_type),
- content_type)
- for content_type in get_snippet_content_types()
+ """
+ Fetches all human-readabe names of all snippet classes and presents them
+ in a list.
+ """
+ snippet_types = [
+ (
+ content_type._meta.app_label,
+ content_type._meta.model.__name__,
+ content_type._meta.description,
+ )
+ for content_type in get_snippet_models()
if user_can_edit_snippet_type(request.user, content_type)
]
return render_modal_workflow(
@@ -32,13 +39,16 @@ def index(request):
def index_objects(request, content_type_app_name, content_type_model_name):
+ """
+ Fetch objects of related model of the given ContentType and call the template
+ to properly display them in a list.
+ """
snippet_types = get_snippet_content_types()
for content_type in snippet_types:
- name = get_snippet_type_name(content_type)[0]
- if name.lower().replace(" ", "") == content_type_model_name:
- model = content_type.model_class()
- items = model.objects.all()
- snippet_type_name, snippet_type_name_plural = get_snippet_type_name(content_type)
+ if content_type.model == content_type_model_name.lower():
+ items = content_type.model_class().objects.all()
+ snippet_type_name = content_type.model_class()._meta.verbose_name
+ snippet_type_name_plural = content_type.model_class()._meta.verbose_name_plural
return render_modal_workflow(
request,
@@ -56,6 +66,9 @@ def index_objects(request, content_type_app_name, content_type_model_name):
def choose_snippet(request, id, content_type_app_name, content_type_model_name):
+ """
+ Choose snippet and display its representation in the Hallo.js richtext field.
+ """
content_type = get_content_type_from_url_params(content_type_app_name, content_type_model_name)
if not user_can_edit_snippet_type(request.user, content_type):
raise PermissionDenied
diff --git a/wagtailembedder/wagtail_hooks.py b/wagtailembedder/wagtail_hooks.py
index 9f81f52..4a2c11c 100644
--- a/wagtailembedder/wagtail_hooks.py
+++ b/wagtailembedder/wagtail_hooks.py
@@ -2,7 +2,9 @@
from django.conf import settings
from django.utils.html import format_html, format_html_join
from django.core.urlresolvers import reverse
+
from wagtail.wagtailcore import hooks
+
from wagtailembedder import urls
from wagtailembedder.helper import add_embed_handler