from django.conf import settings
from django.conf.urls import include, url
from django.core import urlresolvers
from django.utils.html import format_html, format_html_join
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType

from wagtail.wagtailcore import hooks
from wagtail.wagtailadmin.menu import MenuItem

from wagtail_embed_videos import admin_urls


@hooks.register('register_admin_urls')
def register_admin_urls():
    return [
        url(r'^embed_videos/', include(admin_urls)),
    ]


@hooks.register('construct_main_menu')
def construct_main_menu(request, menu_items):
    pass


class EmbedVideosMenuItem(MenuItem):
    def is_shown(self, request):
        return request.user.has_perm('wagtail_embed_videos.add_video')

@hooks.register('register_admin_menu_item')
def register_embed_videos_menu_item():
    return EmbedVideosMenuItem(_('Embed Videos'), urlresolvers.reverse('wagtail_embed_videos_index'), classnames='icon icon-media', order=301)

@hooks.register('register_permissions')
def register_permissions():
    embed_video_content_type = ContentType.objects.get(app_label='wagtail_embed_videos', model='embedvideo')
    embed_video_permissions = Permission.objects.filter(content_type = embed_video_content_type)
    return embed_video_permissions

@@ -703,42 +703,122 @@
 s%0A%0A%0A
-class E
+%0A@hooks.register('register_admin_menu_item')%0Adef register_e
 mbed
-V
+_v
 ideos
-MenuI
+_menu_i
 tem(
+):%0A    return EmbedVideos
 MenuItem
 ):%0A 
@@ -817,343 +817,656 @@
 Item
-):
+(
 %0A    
-def is_shown(self, request):%0A        return request.user.has_perm('wagtail_embed_videos.add_video')%0A%0A@hooks.register('register_admin_menu_item')%0Adef register_embed_videos_menu_item():%0A    return EmbedVideosMenuItem(_('E
+    _('Embed Videos'),%0A        urlresolvers.reverse('wagtail_embed_videos_index'),%0A        classnames='icon icon-media', order=301)%0A%0A%0A@hooks.register('insert_editor_js')%0Adef editor_js():%0A    js_files = %5B%0A        'wagtail_embed_videos/js/embed-video-chooser.js',%0A    %5D%0A    js_includes = format_html_join('%5Cn', '%3Cscript src=%22%7B0%7D%7B1%7D%22%3E%3C/script%3E', (%0A        (settings.STATIC_URL, filename) for filename in js_files)%0A    )%0A    return js_includes + format_html(%0A        %22%22%22%0A        %3Cscript%3E%0A            window.chooserUrls.e
 mbed
- 
 Video
-s'), urlresolvers.reverse('wagtail_embed_videos_index'), classnames='icon icon-media', order=301
+Chooser = '%7B0%7D';%0A        %3C/script%3E%0A        %22%22%22,%0A        urlresolvers.reverse('wagtail_embed_videos_chooser')%0A    
 )%0A%0A
+%0A
 @hoo
@@ -1584,16 +1584,25 @@
 cts.get(
+%0A        
 app_labe
@@ -1703,16 +1703,25 @@
 .filter(
+%0A        
 content_
@@ -1724,19 +1724,17 @@
 ent_type
- = 
+=
 embed_vi

Update wagtail_hooks.py