Ejemplo n.º 1
1
from django.core import urlresolvers
from django.conf.urls import include, url
from django.utils.translation import ugettext_lazy as _

from wagtail.wagtailcore import hooks
from wagtail.wagtailredirects import urls

from wagtail.wagtailadmin.menu import MenuItem


def register_admin_urls():
    return [
        url(r'^redirects/', include(urls)),
    ]
hooks.register('register_admin_urls', register_admin_urls)


def construct_main_menu(request, menu_items):
    # TEMPORARY: Only show if the user is a superuser
    if request.user.is_superuser:
        menu_items.append(
            MenuItem(_('Redirects'), urlresolvers.reverse('wagtailredirects_index'), classnames='icon icon-redirect', order=800)
        )
hooks.register('construct_main_menu', construct_main_menu)
Ejemplo n.º 2
0
    def register_hook(self, hook_name, fn, order=0):
        from wagtail.wagtailcore import hooks

        hooks.register(hook_name, fn, order)
        try:
            yield
        finally:
            hooks._hooks[hook_name].remove((fn, order))
Ejemplo n.º 3
0
    def register_hook(self, hook_name, fn, order=0):
        from wagtail.wagtailcore import hooks

        hooks.register(hook_name, fn, order)
        try:
            yield
        finally:
            hooks._hooks[hook_name].remove((fn, order))
Ejemplo n.º 4
0
    def register_hook(self, hook_name, fn):
        from wagtail.wagtailcore import hooks

        hooks.register(hook_name, fn)
        try:
            yield
        finally:
            hooks.get_hooks(hook_name).remove(fn)
Ejemplo n.º 5
0
def register_all_permissions():
    # Restricted to only being called once
    if not _PERMISSIONS_HOOKS:
        for cls in NEWSINDEX_MODEL_CLASSES:
            hook = _get_register_newsitem_permissions_panel(
                cls.get_newsitem_model())
            _PERMISSIONS_HOOKS.append(hook)
            hooks.register('register_group_permission_panel', hook)
Ejemplo n.º 6
0
    def register_hook(self, hook_name, fn):
        from wagtail.wagtailcore import hooks

        hooks.register(hook_name, fn)
        try:
            yield
        finally:
            hooks.get_hooks(hook_name).remove(fn)
Ejemplo n.º 7
0
        ((settings.STATIC_URL, filename) for filename in js_files)
    )

    return js_includes + format_html(
        """
        <script>
            registerHalloPlugin('editHtmlButton');
            registerHalloPlugin('answermodule');
        </script>
        """
    )


def editor_css():
    return format_html(
        '<link rel="stylesheet" href="' +
        settings.STATIC_URL +
        'css/question_tips.css">')


def whitelister_element_rules():
    return {
        'aside': attribute_rule({'class': True}),
    }

if settings.DEPLOY_ENVIRONMENT == 'build':
    hooks.register('insert_editor_js', editor_js)
    hooks.register('insert_editor_css', editor_css)
    hooks.register(
        'construct_whitelister_element_rules', whitelister_element_rules)
Ejemplo n.º 8
0
from pkg_resources import parse_version

from django.utils.html import format_html
from django.conf import settings

from wagtail.wagtailcore import hooks
from wagtail.wagtailcore import __version__ as WAGTAIL_VERSION


def import_wagtailfontawesome_stylesheet():
    elem = '<link rel="stylesheet" href="%swagtailfontawesome/css/wagtailfontawesome.css">' % settings.STATIC_URL
    return format_html(elem)


# New Wagtail versions support importing CSS throughout the admin.
# Fall back to the old hook (editor screen only) for older versions.
if parse_version(WAGTAIL_VERSION) >= parse_version('1.4'):
    admin_stylesheet_hook = 'insert_global_admin_css'
else:
    admin_stylesheet_hook = 'insert_editor_css'

hooks.register(admin_stylesheet_hook, import_wagtailfontawesome_stylesheet)
Ejemplo n.º 9
0
from wagtail.wagtailadmin.search import SearchArea
from wagtail.wagtailcore import hooks
from wagtail.wagtailcore.whitelist import allow_without_attributes, attribute_rule, check_url


# Register one hook using decorators...
@hooks.register("insert_editor_css")
def editor_css():
    return """<link rel="stylesheet" href="/path/to/my/custom.css">"""


def editor_js():
    return """<script src="/path/to/my/custom.js"></script>"""


hooks.register("insert_editor_js", editor_js)
# And the other using old-style function calls


def whitelister_element_rules():
    return {"blockquote": allow_without_attributes, "a": attribute_rule({"href": check_url, "target": True})}


hooks.register("construct_whitelister_element_rules", whitelister_element_rules)


def block_googlebot(page, request, serve_args, serve_kwargs):
    if request.META.get("HTTP_USER_AGENT") == "GoogleBot":
        return HttpResponse("<h1>bad googlebot no cookie</h1>")

Ejemplo n.º 10
0
from wagtail.wagtailadmin.menu import MenuItem
from wagtail.wagtailadmin import widgets as wagtailadmin_widgets

from django.core.urlresolvers import reverse
from django.contrib.contenttypes.models import ContentType
from django.shortcuts import redirect
from django.conf import settings
from django.conf.urls import url

from .models import RcaNowPage
from . import admin_views


def editor_css():
    return """<link rel="stylesheet" type="text/x-scss" href="%srca/css/richtext.scss" />""" % settings.STATIC_URL
hooks.register('insert_editor_css', editor_css)


def user_is_student(user):
    return [group.name for group in user.groups.all()] == ['Students']


def construct_main_menu(request, menu_items):
    if user_is_student(request.user):
        # remove Explorer and Search items from the menu.
        # assigning menu_items[:] will modify the list passed in
        menu_items[:] = [item for item in menu_items if item.name not in ('explorer', 'search')]

        # insert student page and RCA Now items in place
        menu_items.append(
            MenuItem('Profile', reverse('student_page_editor_index'), classnames='icon icon-user', order=100)
Ejemplo n.º 11
0
from django.conf import settings
from django.conf.urls import include, url
from django.core import urlresolvers
from django.utils.html import format_html

from wagtail.wagtailcore import hooks
from wagtail.wagtailembeds import urls


def register_admin_urls():
    return [
        url(r'^embeds/', include(urls)),
    ]


hooks.register('register_admin_urls', register_admin_urls)


def editor_js():
    return format_html(
        """
            <script src="{0}{1}"></script>
            <script>
                window.chooserUrls.embedsChooser = '{2}';
                registerHalloPlugin('hallowagtailembeds');
            </script>
        """, settings.STATIC_URL,
        'wagtailembeds/js/hallo-plugins/hallo-wagtailembeds.js',
        urlresolvers.reverse('wagtailembeds_chooser'))

Ejemplo n.º 12
0
from pkg_resources import parse_version

from django.utils.html import format_html
from django.conf import settings

from wagtail.wagtailcore import hooks
from wagtail.wagtailcore import __version__ as WAGTAIL_VERSION


def import_wagtailfontawesome_stylesheet():
    elem = '<link rel="stylesheet" href="%swagtailfontawesome/css/wagtailfontawesome.css">' % settings.STATIC_URL
    return format_html(elem)

# New Wagtail versions support importing CSS throughout the admin.
# Fall back to the old hook (editor screen only) for older versions.
if parse_version(WAGTAIL_VERSION) >= parse_version('1.4'):
    admin_stylesheet_hook = 'insert_global_admin_css'
else:
    admin_stylesheet_hook = 'insert_editor_css'

hooks.register(admin_stylesheet_hook, import_wagtailfontawesome_stylesheet)
Ejemplo n.º 13
0
 def setUpClass(cls):
     hooks.register('test_hook_name', test_hook)
 def setUpClass(cls):
     hooks.register('test_hook_name', test_hook)
Ejemplo n.º 15
0
from django.http import HttpResponse

from wagtail.wagtailcore import hooks
from wagtail.wagtailcore.whitelist import attribute_rule, check_url, allow_without_attributes
from wagtail.wagtailadmin.menu import MenuItem


# Register one hook using decorators...
@hooks.register('insert_editor_css')
def editor_css():
    return """<link rel="stylesheet" href="/path/to/my/custom.css">"""


def editor_js():
    return """<script src="/path/to/my/custom.js"></script>"""
hooks.register('insert_editor_js', editor_js)
# And the other using old-style function calls


def whitelister_element_rules():
    return {
        'blockquote': allow_without_attributes,
        'a': attribute_rule({'href': check_url, 'target': True}),
    }
hooks.register('construct_whitelister_element_rules', whitelister_element_rules)


def block_googlebot(page, request, serve_args, serve_kwargs):
    if request.META.get('HTTP_USER_AGENT') == 'GoogleBot':
        return HttpResponse("<h1>bad googlebot no cookie</h1>")
hooks.register('before_serve_page', block_googlebot)
Ejemplo n.º 16
0
from django.conf import settings

from wagtail.wagtailcore import hooks

@hooks.register('insert_editor_js')
def editor_js():
  js_files = [
    'website/js/hallo-edit-html.js',
  ]
  js_includes = format_html_join('\n', '<script src="{0}{1}"></script>',
    ((settings.STATIC_URL, filename) for filename in js_files)
  )
  return js_includes + format_html(
    """
    <script>
        registerHalloPlugin('editHtmlButton');
    </script>
    """
  )

def allow_all_attributes(tag):
    pass

def whitelister_element_rules():
      tags=["a","abbr","acronym","address","area","b","base","bdo","big","blockquote","body","br","button","caption","cite","code","col","colgroup","dd","del","dfn","div","dl","D\
OCTYPE","dt","em","fieldset","form","h1","h2","h3","h4","h5","h6","head","html","hr","i","img","input","ins","kbd","label","legend","li","link","map","meta","noscript","object","\
ol","optgroup","option","p","param","pre","q","samp","script","select","small","span","strong","style","sub","sup","table","tbody","td","textarea","tfoot","th","thead","title","t\
r","tt","ul","var"]
      return dict((tag, allow_all_attributes) for tag in tags)
hooks.register('construct_whitelister_element_rules', whitelister_element_rules)
Ejemplo n.º 17
0
        'wagtailsite/js/vendor/hallo-code.js',
    ]
    js_includes = format_html_join('\n', '<script src="{0}{1}"></script>',
        ((settings.STATIC_URL, filename) for filename in js_files)
    )
  
    return js_includes + format_html(
        """
        <script>
            registerHalloPlugin('halloheadings');
            registerHalloPlugin('hallocode');
        </script>
        """
    )
  
hooks.register('insert_editor_js', editor_js)
  
  
def editor_css():
    return format_html('<link rel="stylesheet" href="'+ settings.STATIC_URL + 'wagtailsite/css/vendor/font-awesome.min.css">')
  
hooks.register('insert_editor_css', editor_css)


@hooks.register('construct_whitelister_element_rules')
def whitelister_element_rules():
    return {
        'blockquote': allow_without_attributes,
        'pre': allow_without_attributes,
        'code': allow_without_attributes,
    }
Ejemplo n.º 18
0
        'hallo', 'superscriptformat',
        HalloPlugin(
            name='superscriptformat',
            js=[static('js/hallo-custombuttons.js')],
        ))
    features.default_features.append('superscriptformat')
    features.register_editor_plugin(
        'hallo', 'endnoteanchorbutton',
        HalloPlugin(
            name='endnoteanchorbutton',
            js=[static('js/hallo-custombuttons.js')],
        ))
    features.default_features.append('endnoteanchorbutton')


hooks.register('register_rich_text_feature', register_custom_buttons)


def editor_js():
    js_files = [
        'js/hallo-custombuttons.js',
    ]
    js_includes = format_html_join('\n', '<script src="{0}{1}"></script>',
                                   ((settings.STATIC_URL, filename)
                                    for filename in js_files))

    return js_includes + format_html("""
        <script>
            registerHalloPlugin('superscriptformat');
            registerHalloPlugin('endnoteanchorbutton');
        </script>
Ejemplo n.º 19
0
        attribute_rule({'class': True}),
        'iframe':
        attribute_rule({
            'id': True,
            'class': True,
            'src': True,
            'style': True,
            'frameborder': True,
            'allowfullscreen': True,
            'width': True,
            'height': True
        }),
    }


hooks.register('construct_whitelister_element_rules',
               whitelister_element_rules)


def editor_css():
    return format_html(
        """
                       <link href="{0}{1}" rel="stylesheet"
                       type="text/x-scss">
                       """, settings.STATIC_URL,
        'vendor/font-awesome/scss/font-awesome.scss')


hooks.register('insert_editor_css', editor_css)


def editor_js():
Ejemplo n.º 20
0
from django.core.urlresolvers import reverse
from django.contrib.contenttypes.models import ContentType
from django.shortcuts import redirect
from django.conf import settings
from django.conf.urls import url

from .models import RcaNowPage
from . import admin_views


def editor_css():
    return """<link rel="stylesheet" type="text/x-scss" href="%srca/css/richtext.scss" />""" % settings.STATIC_URL


hooks.register('insert_editor_css', editor_css)


def user_is_student(user):
    return [group.name for group in user.groups.all()] == ['Students']


def construct_main_menu(request, menu_items):
    if user_is_student(request.user):
        # remove Explorer and Search items from the menu.
        # assigning menu_items[:] will modify the list passed in
        menu_items[:] = [
            item for item in menu_items
            if item.name not in ('explorer', 'search')
        ]
Ejemplo n.º 21
0
from wagtail.wagtailcore import hooks
from wagtail.wagtailcore.whitelist import attribute_rule, check_url, allow_without_attributes
from wagtail.wagtailadmin.menu import MenuItem


# Register one hook using decorators...
@hooks.register('insert_editor_css')
def editor_css():
    return """<link rel="stylesheet" href="/path/to/my/custom.css">"""


def editor_js():
    return """<script src="/path/to/my/custom.js"></script>"""


hooks.register('insert_editor_js', editor_js)
# And the other using old-style function calls


def whitelister_element_rules():
    return {
        'blockquote': allow_without_attributes,
        'a': attribute_rule({
            'href': check_url,
            'target': True
        }),
    }


hooks.register('construct_whitelister_element_rules',
               whitelister_element_rules)
Ejemplo n.º 22
0
from django.conf.urls import include, url
from django.core import urlresolvers
from django.utils.translation import ugettext_lazy as _

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

from wagtail.wagtailusers import urls


def register_admin_urls():
    return [
        url(r'^users/', include(urls)),
    ]


hooks.register('register_admin_urls', register_admin_urls)


def construct_main_menu(request, menu_items):
    if request.user.has_module_perms('auth'):
        menu_items.append(
            MenuItem(_('Users'),
                     urlresolvers.reverse('wagtailusers_index'),
                     classnames='icon icon-user',
                     order=600))


hooks.register('construct_main_menu', construct_main_menu)
Ejemplo n.º 23
0
from django.core.urlresolvers import reverse

from wagtail.wagtailcore import hooks

def check_view_restrictions(page, request, serve_args, serve_kwargs):
    """
    Check whether there are any view restrictions on this page which are
    not fulfilled by the given request object. If there are, return an
    HttpResponse that will notify the user of that restriction (and possibly
    include a password / login form that will allow them to proceed). If
    there are no such restrictions, return None
    """
    restrictions = page.get_view_restrictions()

    if restrictions:
        passed_restrictions = request.session.get('passed_page_view_restrictions', [])
        for restriction in restrictions:
            if restriction.id not in passed_restrictions:
                from wagtail.wagtailcore.forms import PasswordPageViewRestrictionForm
                form = PasswordPageViewRestrictionForm(instance=restriction,
                    initial={'return_url': request.get_full_path()})
                action_url = reverse('wagtailcore_authenticate_with_password', args=[restriction.id, page.id])
                return page.serve_password_required_response(request, form, action_url)

hooks.register('before_serve_page', check_view_restrictions)
Ejemplo n.º 24
0
        'wagtailsite/js/vendor/hallo-code.js',
    ]
    js_includes = format_html_join('\n', '<script src="{0}{1}"></script>',
        ((settings.STATIC_URL, filename) for filename in js_files)
    )

    return js_includes + format_html(
        """
        <script>
            registerHalloPlugin('halloheadings');
            registerHalloPlugin('hallocode');
        </script>
        """
    )

hooks.register('insert_editor_js', editor_js)


def editor_css():
    return format_html('<link rel="stylesheet" href="' + settings.STATIC_URL + 'wagtailsite/css/vendor/font-awesome.min.css">')

hooks.register('insert_editor_css', editor_css)


@hooks.register('construct_whitelister_element_rules')
def whitelister_element_rules():
    return {
        'blockquote': allow_without_attributes,
        'pre': allow_without_attributes,
        'code': allow_without_attributes,
    }
Ejemplo n.º 25
0
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 wagtail.wagtailcore import hooks
from wagtail.wagtailadmin.menu import MenuItem

from wagtail.wagtaildocs import admin_urls


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


def construct_main_menu(request, menu_items):
    if request.user.has_perm('wagtaildocs.add_document'):
        menu_items.append(
            MenuItem(_('Documents'), urlresolvers.reverse('wagtaildocs_index'), classnames='icon icon-doc-full-inverse', order=400)
        )
hooks.register('construct_main_menu', construct_main_menu)


def editor_js():
    js_files = [
        'wagtaildocs/js/hallo-plugins/hallo-wagtaildoclink.js',
        'wagtaildocs/js/document-chooser.js',
    ]
Ejemplo n.º 26
0
from django.conf import settings
from django.conf.urls import include, url
from django.core import urlresolvers
from django.utils.html import format_html

from wagtail.wagtailcore import hooks
from wagtail.wagtailembeds import urls


def register_admin_urls():
    return [
        url(r'^embeds/', include(urls)),
    ]
hooks.register('register_admin_urls', register_admin_urls)


def editor_js():
    return format_html("""
            <script src="{0}{1}"></script>
            <script>
                window.chooserUrls.embedsChooser = '{2}';
                registerHalloPlugin('hallowagtailembeds');
            </script>
        """,
        settings.STATIC_URL,
        'wagtailembeds/js/hallo-plugins/hallo-wagtailembeds.js',
        urlresolvers.reverse('wagtailembeds_chooser')
    )
hooks.register('insert_editor_js', editor_js)