How to use the kotti.get_settings function in Kotti

To help you get started, we’ve selected a few Kotti examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Kotti / Kotti / kotti / tests.py View on Github external
def contents_addable():
    # Allow Nodes to be added to documents:
    save_node_type_info = Content.type_info.copy()
    Content.type_info.addable_to = [u'Document']
    Content.type_info.add_view = u'add_document'
    get_settings()['kotti.available_types'].append(Content)
    try:
        yield
    finally:
        get_settings()['kotti.available_types'].pop()
        Content.type_info = save_node_type_info
github Kotti / Kotti / kotti / tests.py View on Github external
def test_persistent_settings(self):
        from kotti import get_version
        from kotti.resources import Settings
        session = DBSession()
        [settings] = session.query(Settings).all()
        self.assertEqual(settings.data, {'kotti.db_version': get_version()})
        self.assertEqual(get_settings()['kotti.db_version'], get_version())
        settings.data['foo.bar'] = u'baz'
        self.assertEqual(get_settings()['foo.bar'], u'baz')
github Kotti / Kotti / kotti / testing.py View on Github external
def _init_testing_db():
    from sqlalchemy import create_engine
    from kotti import get_settings
    from kotti.resources import initialize_sql

    database_url = testing_db_url()
    get_settings()["sqlalchemy.url"] = database_url
    session = initialize_sql(create_engine(database_url), drop_all=True)
    return session
github Kotti / Kotti / kotti / url_normalizer.py View on Github external
def url_normalizer(text, locale=None, max_length=MAX_URL_LENGTH):

    key = "kotti.url_normalizer.map_non_ascii_characters"
    map_non_ascii = asbool(get_settings()[key])
    if map_non_ascii:
        text = unidecode(text)

    # lowercase text
    base = text.lower()
    ext = ""

    m = FILENAME_REGEX.match(base)
    if m is not None:
        base = m.groups()[0]
        ext = m.groups()[1]

    base = base.replace(" ", "-")
    base = IGNORE_REGEX.sub("", base)
    base = URL_DANGEROUS_CHARS_REGEX.sub("-", base)
    base = EXTRA_DASHES_REGEX.sub("", base)
github Kotti / Kotti / kotti / sanitizers.py View on Github external
def sanitize(html: str, sanitizer: str) -> str:
    """ Sanitize HTML

    :param html: HTML to be sanitized
    :type html: basestring

    :param sanitizer: name of the sanitizer to use
    :type sanitizer: str

    :result: sanitized HTML
    :rtype: str
    """

    sanitized = get_settings()["kotti.sanitizers"][sanitizer](html)

    return sanitized
github Kotti / Kotti / kotti / views / util.py View on Github external
def template_api(context, request, **kwargs):
    return get_settings()["kotti.templates.api"][0](context, request, **kwargs)
github Kotti / Kotti / kotti / resources.py View on Github external
def get_root(request: Optional[Request] = None) -> Node:
    """Call the function defined by the ``kotti.root_factory`` setting and
       return its result.

    :param request: current request (optional)
    :type request: :class:`kotti.request.Request`

    :result: a node in the node tree
    :rtype: :class:`~kotti.resources.Node` or descendant;
    """
    return get_settings()["kotti.root_factory"][0](request)
github Kotti / Kotti / kotti / views / form.py View on Github external
You can configure the maximum size by setting the kotti.max_file_size
    option to the maximum number of bytes that you want to allow.
    """
    try:
        fp = value.get("fp", None)
    except AttributeError:
        fp = getattr(value, "fp", None)
    if not fp:
        return

    fp.seek(0, 2)
    size = fp.tell()
    fp.seek(0)
    # unit for ``kotti.max_file_size`` is MB
    max_mb = get_settings()["kotti.max_file_size"]
    max_size = int(max_mb) * 1024 * 1024
    if size > max_size:
        msg = _("Maximum file size: ${size}MB", mapping={"size": max_mb})
        raise colander.Invalid(node, msg)
github Kotti / Kotti / kotti / populate.py View on Github external
def populate_users():
    """
    Create the admin user with the password from the ``kotti.secret`` option
    if there is no user with name 'admin' yet.
    """

    principals = get_principals()
    if "admin" not in principals:
        principals["admin"] = {
            "name": "admin",
            "password": get_settings()["kotti.secret"],
            "title": "Administrator",
            "groups": ["role:admin"],
        }