Beispiel #1
0
    def test_link_selected_no_view_markers(self):
        from kotti.util import Link
        from kotti.testing import DummyRequest
        from mock import Mock

        req = DummyRequest()
        root = Mock(__name__=None)
        manage = Mock(__name__='manage',
                      __parent__=Mock(__name__=None))

        req.url = "http://example.com/manage"
        assert Link('manage').selected(root, req)

        req.url = "http://example.com/manage/"
        assert not Link('manage').selected(root, req)

        req.url = "http://example.com/"
        assert Link('').selected(root, req)

        req.url = "http://example.com/manage/"
        link = Link('')
        assert link.selected(manage, req)

        req.url = "http://example.com/manage"
        assert not link.selected(manage, req)

        req.url = "http://example.com/"
        assert link.selected(root, req)

        req.url = "http://example.com"
        assert link.selected(root, req)
Beispiel #2
0
    def test_link_selected(self):
        from kotti.util import Link
        from kotti.testing import DummyRequest

        req = DummyRequest()
        req.url = "http://example.com/@@manage"

        assert Link('manage').selected(Mock(__name__=None), req)

        req.url = "http://example.com/@@manage_cats"
        assert not Link('manage').selected(Mock(__name__=None), req)
Beispiel #3
0
    def test_link_selected(self):
        from kotti.util import Link
        from kotti.testing import DummyRequest

        req = DummyRequest()
        req.view_name = "manage"

        assert Link('manage').selected(Mock(__name__=None), req)

        req.view_name = 'manage_cats'
        assert not Link('manage').selected(Mock(__name__=None), req)

        req.view_name = ''
        assert Link('').selected(Mock(__name__=None), req)
    def view(self):
        setting_id = self.request.params.get("setting_id")
        if not setting_id:
            settings_form_views = []
            for settings in SETTINGS.values():
                settings_form_views.append(settings)
            return {
                "settings": settings_form_views,
                "UCP_LINKS": CONTROL_PANEL_LINKS
            }
        settings = SETTINGS.get(setting_id)
        if not settings:
            return httpexc.HTTPNotFound()
        args = {
            'title': settings.title,
            'description': settings.description,
            'name': settings.name,
            'schema_factory': settings.schema_factory,
            'settings': settings,
            'success_message': settings.success_message,
            'active': True,
        }
        View = type(str(setting_id), (SettingsFormView, ), args)
        view = View(self.context, self.request)
        form = view()
        form["view"] = view
        links = util.get_links(setting_id)

        link1 = Link('controlpanel', title=_(u'Control Panel'))
        if link1 not in links:
            links.append(link1)
        if self.request.has_permission("admin"):
            link2 = Link("controlpanel-dump", title=_(u'All Settings'))
            if link2 not in links:
                links.append(link2)

        template = (settings.template
                    or 'kotti_controlpanel:templates/settings.pt')
        return render_to_response(template, {
            "settings": settings,
            "settings_form": form,
            "cp_links": links,
            "UCP_LINKS": CONTROL_PANEL_LINKS
        },
                                  request=self.request)
Beispiel #5
0
    def test_edit_links(self, config, db_session):
        from kotti import views
        from kotti.views.edit import actions, content, default_views
        from kotti.views import users
        from kotti.util import Link

        api = self.make()
        config.include(views)
        config.include(actions)
        config.include(content)
        config.include(default_views)
        config.include(users)

        assert (api.edit_links[:3] == [
            Link('contents', u'Contents'),
            Link('edit', u'Edit'),
            Link('share', u'Share'),
        ])

        # Edit links are controlled through
        # 'root.type_info.edit_links' and the permissions that guard
        # these:
        class MyLink(Link):
            permit = True

            def permitted(self, context, request):
                return self.permit

        open_link = MyLink('open')
        secure_link = MyLink('secure')
        secure_link.permit = False

        root = api.root
        root.type_info = root.type_info.copy(
            edit_links=[open_link, secure_link])
        api = self.make()
        assert api.edit_links == [open_link]
def kotti_configure(settings):
    """ Add a line like this to you .ini file::

            kotti.configurators =
                kotti_controlpanel.kotti_configure

        to enable the ``kotti_controlpanel`` add-on.

    :param settings: Kotti configuration dictionary.
    :type settings: dict
    """

    settings['pyramid.includes'] += ' kotti_controlpanel'
    settings['kotti.alembic_dirs'] += ' kotti_controlpanel:alembic'
    settings['kotti.fanstatic.view_needed'] += (
        ' kotti_controlpanel.fanstatic.css_and_js')

    cp = Link('controlpanel', title=_(u'Control Panel'))
    KOTTI_CP_LINKS.append(cp)
Beispiel #7
0
        :rtype: :class:`~kotti.resources.TagsToContents`
        """

        with DBSession.no_autoflush:
            tag = DBSession.query(Tag).filter_by(title=title).first()
        if tag is None:
            tag = Tag(title=title)
        return cls(tag=tag)


def _not_root(context, request):
    return context is not get_root()


default_actions = [
    Link('copy', title=_(u'Copy')),
    Link('cut', title=_(u'Cut'), predicate=_not_root),
    Link('paste', title=_(u'Paste'), predicate=get_paste_items),
    Link('rename', title=_(u'Rename'), predicate=_not_root),
    Link('delete', title=_(u'Delete'), predicate=_not_root),
    LinkRenderer('default-view-selector'),
]

default_type_info = TypeInfo(
    name=u'Content',
    title=u'type_info title missing',  # BBB
    add_view=None,
    addable_to=[],
    edit_links=[
        Link('contents', title=_(u'Contents')),
        Link('edit', title=_(u'Edit')),
Beispiel #8
0
 def test_link_target(self):
     from kotti.util import Link
     assert Link('').target is None
     assert Link('', target='_blank').target == '_blank'
Beispiel #9
0
        """

        with DBSession.no_autoflush:
            tag = DBSession.query(Tag).filter_by(title=title).first()
        if tag is None:
            tag = Tag(title=title)
        return cls(tag=tag)


# noinspection PyUnusedLocal
def _not_root(context: Node, request: Request) -> bool:
    return context is not get_root()


default_actions = [
    Link("copy", title=_("Copy")),
    Link("cut", title=_("Cut"), predicate=_not_root),
    Link("paste", title=_("Paste"), predicate=get_paste_items),
    Link("rename", title=_("Rename"), predicate=_not_root),
    Link("delete", title=_("Delete"), predicate=_not_root),
    LinkRenderer("default-view-selector"),
]

default_type_info = TypeInfo(
    name="Content",
    title="type_info title missing",  # BBB
    add_view=None,
    addable_to=[],
    edit_links=[
        Link("contents", title=_("Contents")),
        Link("edit", title=_("Edit")),
Beispiel #10
0
# -*- coding: utf-8 -*-

from kotti.util import Link
from kotti.util import _

CONTROL_PANEL_LINKS = [
    Link('setup-users', title=_('User Management')),
]
Beispiel #11
0
    def test_default_actions(self):
        from kotti.resources import default_actions, Document
        from kotti.util import Link

        default_actions.append(Link('test', u'Test'))
        assert Document().type_info.edit_links[-1].children[-1].name == 'test'
Beispiel #12
0
    def test_link_target(self):
        from kotti.util import Link

        assert Link("").target is None
        assert Link("", target="_blank").target == "_blank"
Beispiel #13
0
from kotti.util import Link
from kotti.util import _

CONTROL_PANEL_LINKS = [Link("setup-users", title=_("User Management"))]
Beispiel #14
0
Created on 2016-06-18
:author: Oshane Bailey ([email protected])
"""

from kotti.util import Link
from kotti.resources import File
from kotti.views.slots import assign_slot
from pyramid.i18n import TranslationStringFactory
from kotti_controlpanel.util import get_setting, set_setting

controlpanel_id = 'kotti_google_analytics'

_ = TranslationStringFactory(controlpanel_id)

CONTROL_PANEL_LINKS = [
    Link('analytics-report', title=_(u"Google Analytics Report")),
    Link('analytics-setup', title=_(u"Setup Google Analytics"))
]


class AnalyticsDefault(object):
    property_id = None
    send_user_id = False


def kotti_configure(settings):
    """ Add a line like this to you .ini file::

            kotti.configurators =
                kotti_google_analytics.kotti_configure
# -*- coding: utf-8 -*-
"""
Created on 2016-06-15
:author: Oshane Bailey ([email protected])
"""

from pyramid.i18n import TranslationStringFactory
from kotti.util import Link
from kotti.views.site_setup import CONTROL_PANEL_LINKS as KOTTI_CP_LINKS

_ = TranslationStringFactory('kotti_controlpanel')

CONTROL_PANEL_LINKS = [Link('setup-users', 'User Management')]


def kotti_configure(settings):
    """ Add a line like this to you .ini file::

            kotti.configurators =
                kotti_controlpanel.kotti_configure

        to enable the ``kotti_controlpanel`` add-on.

    :param settings: Kotti configuration dictionary.
    :type settings: dict
    """

    settings['pyramid.includes'] += ' kotti_controlpanel'
    settings['kotti.alembic_dirs'] += ' kotti_controlpanel:alembic'
    settings['kotti.fanstatic.view_needed'] += (
        ' kotti_controlpanel.fanstatic.css_and_js')