Skip to content

Commit

Permalink
Merge branch 'release/2.0.1' into testing
Browse files Browse the repository at this point in the history
  • Loading branch information
disko committed Jan 9, 2019
2 parents 232a069 + 42bcf62 commit a334f4b
Show file tree
Hide file tree
Showing 70 changed files with 4,446 additions and 4,152 deletions.
9 changes: 8 additions & 1 deletion CHANGES.txt
@@ -1,14 +1,21 @@
Change History
==============

2.0.1 - 2019-01-09
------------------

- Reformat source code with black.

- Remove testing import from package code.

2.0.0 - 2019-01-07
------------------

- Update documentation (kotti-cookiecutter is the new scaffolding template).
See https://github.com/Kotti/kotti-cookiecutter

- Require pytest >= 4.1.0, use ``request.node.get_closest_marker`` instead of
deprecated ``request.keywords``.
deprecated ``request.keywords``.

2.0.0b2 - 2018-04-04
--------------------
Expand Down
6 changes: 3 additions & 3 deletions README.rst
Expand Up @@ -123,9 +123,9 @@ Contributions are always welcome, read our `contribution guidelines`_ and visit
.. _coveralls: https://coveralls.io/r/Kotti/Kotti
.. _high coverage: https://coveralls.io/r/Kotti/Kotti

.. |codacy| image:: https://img.shields.io/codacy/ad44331fcd904d338c074f2ca3e6a810.svg?style=flat-square
.. _codacy: https://www.codacy.com/public/disko/Kotti
.. _high quality coding standards: https://www.codacy.com/public/disko/Kotti
.. |codacy| image:: https://api.codacy.com/project/badge/Grade/fb10cbc3497148d2945d61ce6ad2e4f5
.. _codacy: https://www.codacy.com/app/disko/Kotti?utm_source=github.com&utm_medium=referral&utm_content=Kotti/Kotti&utm_campaign=Badge_Grade
.. _high quality coding standards: https://www.codacy.com/app/disko/Kotti?utm_source=github.com&utm_medium=referral&utm_content=Kotti/Kotti&utm_campaign=Badge_Grade

.. |codeclimate| image:: https://api.codeclimate.com/v1/badges/3a4a61548fcc195e4ba1/maintainability
.. _codeclimate: https://codeclimate.com/github/Kotti/Kotti/maintainability
Expand Down
256 changes: 129 additions & 127 deletions kotti/__init__.py
Expand Up @@ -22,22 +22,23 @@
Base = declarative_base(cls=KottiBase)
Base.metadata = metadata
Base.query = DBSession.query_property()
TRUE_VALUES = ('1', 'y', 'yes', 't', 'true')
FALSE_VALUES = ('0', 'n', 'no', 'f', 'false', 'none')
TRUE_VALUES = ("1", "y", "yes", "t", "true")
FALSE_VALUES = ("0", "n", "no", "f", "false", "none")


def authtkt_factory(**settings):
from kotti.security import list_groups_callback

kwargs = dict(
secret=settings['kotti.secret2'],
hashalg='sha512',
secret=settings["kotti.secret2"],
hashalg="sha512",
callback=list_groups_callback,
)
)
try:
return AuthTktAuthenticationPolicy(**kwargs)
except TypeError:
# BBB with Pyramid < 1.4
kwargs.pop('hashalg')
kwargs.pop("hashalg")
return AuthTktAuthenticationPolicy(**kwargs)


Expand All @@ -55,103 +56,106 @@ def none_factory(**kwargs): # pragma: no cover

# All of these can be set by passing them in the Paste Deploy settings:
conf_defaults = {
'kotti.alembic_dirs': 'kotti:alembic',
'kotti.asset_overrides': '',
'kotti.authn_policy_factory': 'kotti.authtkt_factory',
'kotti.authz_policy_factory': 'kotti.acl_factory',
'kotti.available_types': ' '.join([
'kotti.resources.Document',
'kotti.resources.File',
]),
'kotti.base_includes': ' '.join([
'kotti',
'kotti.traversal',
'kotti.filedepot',
'kotti.events',
'kotti.sanitizers',
'kotti.views',
'kotti.views.cache',
'kotti.views.view',
'kotti.views.edit',
'kotti.views.edit.actions',
'kotti.views.edit.content',
'kotti.views.edit.default_views',
'kotti.views.edit.upload',
'kotti.views.file',
'kotti.views.login',
'kotti.views.navigation',
'kotti.views.users',
]),
'kotti.caching_policy_chooser': (
'kotti.views.cache.default_caching_policy_chooser'),
'kotti.configurators': '',
'kotti.date_format': 'medium',
'kotti.datetime_format': 'medium',
'kotti.depot_mountpoint': '/depot',
'kotti.depot_replace_wsgi_file_wrapper': False,
'kotti.depot.0.backend': 'kotti.filedepot.DBFileStorage',
'kotti.depot.0.name': 'dbfiles',
'kotti.fanstatic.edit_needed': 'kotti.fanstatic.edit_needed',
'kotti.fanstatic.view_needed': 'kotti.fanstatic.view_needed',
'kotti.login_success_callback': 'kotti.views.login.login_success_callback',
'kotti.max_file_size': '10',
'kotti.modification_date_excludes': ' '.join([
'kotti.resources.Node.position',
]),
'kotti.populators': 'kotti.populate.populate',
'kotti.principals_factory': 'kotti.security.principals_factory',
'kotti.register': 'False',
'kotti.register.group': '',
'kotti.register.role': '',
'kotti.request_factory': 'kotti.request.Request',
'kotti.reset_password_callback': 'kotti.views.login.reset_password_callback', # noqa
'kotti.root_factory': 'kotti.resources.default_get_root',
'kotti.sanitizers': ' '.join([
'xss_protection:kotti.sanitizers.xss_protection',
'minimal_html:kotti.sanitizers.minimal_html',
'no_html:kotti.sanitizers.no_html',
]),
'kotti.sanitize_on_write': ' '.join([
'kotti.resources.Document.body:xss_protection',
'kotti.resources.Content.title:no_html',
'kotti.resources.Content.description:no_html',
]),
'kotti.search_content': 'kotti.views.util.default_search_content',
'kotti.session_factory': 'kotti.beaker_session_factory',
'kotti.static.edit_needed': '', # BBB
'kotti.static.view_needed': '', # BBB
'kotti.templates.api': 'kotti.views.util.TemplateAPI',
'kotti.time_format': 'medium',
'kotti.url_normalizer': 'kotti.url_normalizer.url_normalizer',
'kotti.url_normalizer.map_non_ascii_characters': True,
'kotti.use_tables': '',
'kotti.use_workflow': 'kotti:workflow.zcml',
'kotti.zcml_includes': ' '.join([
]),
'pyramid.includes': '',
'pyramid_deform.template_search_path': 'kotti:templates/deform',
}
"kotti.alembic_dirs": "kotti:alembic",
"kotti.asset_overrides": "",
"kotti.authn_policy_factory": "kotti.authtkt_factory",
"kotti.authz_policy_factory": "kotti.acl_factory",
"kotti.available_types": " ".join(
["kotti.resources.Document", "kotti.resources.File"]
),
"kotti.base_includes": " ".join(
[
"kotti",
"kotti.traversal",
"kotti.filedepot",
"kotti.events",
"kotti.sanitizers",
"kotti.views",
"kotti.views.cache",
"kotti.views.view",
"kotti.views.edit",
"kotti.views.edit.actions",
"kotti.views.edit.content",
"kotti.views.edit.default_views",
"kotti.views.edit.upload",
"kotti.views.file",
"kotti.views.login",
"kotti.views.navigation",
"kotti.views.users",
]
),
"kotti.caching_policy_chooser": (
"kotti.views.cache.default_caching_policy_chooser"
),
"kotti.configurators": "",
"kotti.date_format": "medium",
"kotti.datetime_format": "medium",
"kotti.depot_mountpoint": "/depot",
"kotti.depot_replace_wsgi_file_wrapper": False,
"kotti.depot.0.backend": "kotti.filedepot.DBFileStorage",
"kotti.depot.0.name": "dbfiles",
"kotti.fanstatic.edit_needed": "kotti.fanstatic.edit_needed",
"kotti.fanstatic.view_needed": "kotti.fanstatic.view_needed",
"kotti.login_success_callback": "kotti.views.login.login_success_callback",
"kotti.max_file_size": "10",
"kotti.modification_date_excludes": " ".join(["kotti.resources.Node.position"]),
"kotti.populators": "kotti.populate.populate",
"kotti.principals_factory": "kotti.security.principals_factory",
"kotti.register": "False",
"kotti.register.group": "",
"kotti.register.role": "",
"kotti.request_factory": "kotti.request.Request",
"kotti.reset_password_callback": "kotti.views.login.reset_password_callback", # noqa
"kotti.root_factory": "kotti.resources.default_get_root",
"kotti.sanitizers": " ".join(
[
"xss_protection:kotti.sanitizers.xss_protection",
"minimal_html:kotti.sanitizers.minimal_html",
"no_html:kotti.sanitizers.no_html",
]
),
"kotti.sanitize_on_write": " ".join(
[
"kotti.resources.Document.body:xss_protection",
"kotti.resources.Content.title:no_html",
"kotti.resources.Content.description:no_html",
]
),
"kotti.search_content": "kotti.views.util.default_search_content",
"kotti.session_factory": "kotti.beaker_session_factory",
"kotti.static.edit_needed": "", # BBB
"kotti.static.view_needed": "", # BBB
"kotti.templates.api": "kotti.views.util.TemplateAPI",
"kotti.time_format": "medium",
"kotti.url_normalizer": "kotti.url_normalizer.url_normalizer",
"kotti.url_normalizer.map_non_ascii_characters": True,
"kotti.use_tables": "",
"kotti.use_workflow": "kotti:workflow.zcml",
"kotti.zcml_includes": " ".join([]),
"pyramid.includes": "",
"pyramid_deform.template_search_path": "kotti:templates/deform",
}

conf_dotted = {
'kotti.authn_policy_factory',
'kotti.authz_policy_factory',
'kotti.available_types',
'kotti.base_includes',
'kotti.caching_policy_chooser',
'kotti.configurators',
'kotti.fanstatic.edit_needed',
'kotti.fanstatic.view_needed',
'kotti.login_success_callback',
'kotti.modification_date_excludes',
'kotti.populators',
'kotti.principals_factory',
'kotti.request_factory',
'kotti.reset_password_callback',
'kotti.root_factory',
'kotti.search_content',
'kotti.session_factory',
'kotti.templates.api',
'kotti.url_normalizer',
"kotti.authn_policy_factory",
"kotti.authz_policy_factory",
"kotti.available_types",
"kotti.base_includes",
"kotti.caching_policy_chooser",
"kotti.configurators",
"kotti.fanstatic.edit_needed",
"kotti.fanstatic.view_needed",
"kotti.login_success_callback",
"kotti.modification_date_excludes",
"kotti.populators",
"kotti.principals_factory",
"kotti.request_factory",
"kotti.reset_password_callback",
"kotti.root_factory",
"kotti.search_content",
"kotti.session_factory",
"kotti.templates.api",
"kotti.url_normalizer",
}


Expand Down Expand Up @@ -184,6 +188,7 @@ def main(global_config, **settings):
# application.

from kotti.resources import initialize_sql

config = base_configure(global_config, **settings)
engine = engine_from_config(config.registry.settings)
initialize_sql(engine)
Expand All @@ -200,37 +205,37 @@ def base_configure(global_config, **settings):
settings.setdefault(key, value)

for key, value in settings.items():
if key.startswith('kotti') and isinstance(value, binary_type):
settings[key] = value.decode('utf8')
if key.startswith("kotti") and isinstance(value, binary_type):
settings[key] = value.decode("utf8")

# Allow extending packages to change 'settings' w/ Python:
k = 'kotti.configurators'
k = "kotti.configurators"
for func in _resolve_dotted(settings, keys=(k,))[k]:
func(settings)

settings = _resolve_dotted(settings)
secret1 = settings['kotti.secret']
settings.setdefault('kotti.secret2', secret1)
secret1 = settings["kotti.secret"]
settings.setdefault("kotti.secret2", secret1)

# We'll process ``pyramid_includes`` later by hand, to allow
# overrides of configuration from ``kotti.base_includes``:
pyramid_includes = settings.pop('pyramid.includes', '')
pyramid_includes = settings.pop("pyramid.includes", "")

config = Configurator(
request_factory=settings['kotti.request_factory'][0],
settings=settings)
request_factory=settings["kotti.request_factory"][0], settings=settings
)
config.begin()

config.hook_zca()
config.include('pyramid_zcml')
config.include("pyramid_zcml")

# Chameleon bindings were removed from Pyramid core since pyramid>=1.5a2
config.include('pyramid_chameleon')
config.include("pyramid_chameleon")

config.registry.settings['pyramid.includes'] = pyramid_includes
config.registry.settings["pyramid.includes"] = pyramid_includes

# Include modules listed in 'kotti.base_includes':
for module in settings['kotti.base_includes']:
for module in settings["kotti.base_includes"]:
config.include(module)
config.commit()

Expand All @@ -240,7 +245,7 @@ def base_configure(global_config, **settings):
for module in pyramid_includes.split():
config.include(module)

for name in settings['kotti.zcml_includes'].strip().split():
for name in settings["kotti.zcml_includes"].strip().split():
config.load_zcml(name)

config.commit()
Expand All @@ -261,28 +266,25 @@ def includeme(config):

settings = config.get_settings()

authentication_policy = settings[
'kotti.authn_policy_factory'][0](**settings)
authorization_policy = settings[
'kotti.authz_policy_factory'][0](**settings)
session_factory = settings['kotti.session_factory'][0](**settings)
authentication_policy = settings["kotti.authn_policy_factory"][0](**settings)
authorization_policy = settings["kotti.authz_policy_factory"][0](**settings)
session_factory = settings["kotti.session_factory"][0](**settings)
if authentication_policy:
config.set_authentication_policy(authentication_policy)
if authorization_policy:
config.set_authorization_policy(authorization_policy)
config.set_session_factory(session_factory)

config.add_subscriber(
kotti.views.util.add_renderer_globals, BeforeRender)
config.add_subscriber(kotti.views.util.add_renderer_globals, BeforeRender)

for override in [a.strip()
for a in settings['kotti.asset_overrides'].split()
if a.strip()]:
config.override_asset(to_override='kotti', override_with=override)
for override in [
a.strip() for a in settings["kotti.asset_overrides"].split() if a.strip()
]:
config.override_asset(to_override="kotti", override_with=override)

config.add_translation_dirs('kotti:locale')
config.add_translation_dirs("kotti:locale")

workflow = settings['kotti.use_workflow']
workflow = settings["kotti.use_workflow"]
if workflow.lower() not in FALSE_VALUES:
config.load_zcml(workflow)

Expand Down

0 comments on commit a334f4b

Please sign in to comment.