Ejemplo n.º 1
0
def test_boolean_config_field():
    field = BooleanConfigField(None, False)
    # check true states
    assert_true(field('1'))
    assert_true(field('yes'))
    assert_true(field('true'))
    assert_true(field('TrUe'))
    assert_true(field('on'))
    # everything that is not in the defined `True` values
    # is automatically false
    assert_false(field('some ugly thing'))
    # Everything that is not a string will be converted
    # to it's bool() value
    assert_true(field(25123))
    assert_false(field(0))
    # there are also defined false states
    assert_false(field('0'))
    assert_false(field('no'))
    assert_false(field('false'))
    assert_false(field('FaLse'))
    assert_false(field('off'))
Ejemplo n.º 2
0
    :copyright: 2010-2011 by the Inyoka Team, see AUTHORS for more details.
    :license: GNU GPL, see LICENSE for more details.
"""
import json
import urllib2
from urllib import urlencode
from markupsafe import Markup
from inyoka.core.config import TextConfigField, BooleanConfigField


RECAPTCHA_API_SERVER = 'http://api.recaptcha.net/'
RECAPTCHA_SSL_API_SERVER = 'https://api-secure.recaptcha.net/'
RECAPTCHA_VERIFY_SERVER = 'http://api-verify.recaptcha.net/verify'

#: Use SSL for ReCaptcha requests, defaults to True
recaptcha_use_ssl = BooleanConfigField('recaptcha.use_ssl', default=True)

#: ReCaptcha public key
recaptcha_public_key = TextConfigField('recaptcha.public_key',
    default=u'6Lc1LwsAAAAAAPSQ4FcfLKJVcwzicnZl8v-RmeLj')

#: ReCaptcha private key
recaptcha_private_key = TextConfigField('recaptcha.private_key',
    default=u'6Lc1LwsAAAAAAAKaGUBaEpTOfXKDWe6QjIlmMM9b')


def get_recaptcha_html(public_key=None, use_ssl=True, error=None,
                       translations=None):
    """Returns the recaptcha input HTML."""
    _ = translations and translations.ugettext or (lambda x: x)
    server = RECAPTCHA_SSL_API_SERVER if use_ssl else RECAPTCHA_API_SERVER
Ejemplo n.º 3
0
class ICoreResourceManager(IResourceManager):
    """Register core models globally."""

    #: Enable debug mode
    debug = BooleanConfigField('debug', default=False)

    #: Enable testing mode.  Set this to `True` to enable the test mode
    #: of Inyoka.  For example this activates unittest helpers that have
    #: an additional runtime cost which should not be enabled by default.
    #:
    #: This also enables some special logging so that for example our
    #: celery integration does not push forward to celery but executes
    #: tasks directly and adds them to a special container.
    testing = BooleanConfigField('testing', default=False)

    #: The path to the media folder
    media_root = TextConfigField('media_root',
                                 default=_default_media_data_path)

    #: The secret key used for hashing the cookies and other
    #: security salting.
    secret_key = TextConfigField('secret_key', default=u'CHANGEME')

    #: Base domain name
    base_domain_name = TextConfigField('base_domain_name',
                                       default=u'inyoka.local:5000')

    #: Cookie domain name
    cookie_domain_name = TextConfigField('cookie_domain_name',
                                         default=u'.inyoka.local')

    #: Tag uri base, see RFC 4151. May be changed safely. Change this to a real value!
    tag_uri_base = TextConfigField('tag_uri_base',
                                   default=u'tag:inyoka.local,1970:inyoka/')

    #: Cookie name
    cookie_name = TextConfigField('cookie_name', default=u'inyoka-session')

    #: The default timezone for all users
    default_timezone = TextConfigField('default_timezone',
                                       default=u'Europe/Berlin')

    #: The name of the anonymous user
    anonymous_name = TextConfigField('anonymous_name', default=u'anonymous')

    #: Enable or disable CSRF Protection
    enable_csrf_checks = BooleanConfigField('enable_csrf_checks', default=True)

    #: The website title to show in various places
    website_title = TextConfigField('website_title', default=u'Inyoka Portal')

    #: The mail address used for sending mails
    mail_address = TextConfigField('mail_address',
                                   default=u'*****@*****.**')

    #: The duration a permanent session is valid.  Defined in days, defaults to 30
    permanent_session_lifetime = IntegerConfigField(
        'permanent_session_lifetime', default=30)

    #: Path to the directory that includes static files.  Relative to the inyoka
    #: package path.
    static_path = TextConfigField('static_path', default=u'static')

    #: Exclude inyoka.core.tasks per default to fix the celery loader
    deactivated_components.default.append('inyoka.core.tasks')

    #: register core models
    models = [Cache, Confirm, Tag, Storage]
from celery.loaders.default import AttributeDict

from inyoka.context import ctx
from inyoka.core.config import TextConfigField, ListConfigField, IntegerConfigField, \
    BooleanConfigField

# celery broker settings
celery_result_backend = TextConfigField('celery.result_backend',
                                        default=u'database')
celery_result_dburi = TextConfigField('celery.result_dburi',
                                      default='sqlite:///celery.db')
celery_imports = ListConfigField('celery.imports',
                                 default=['inyoka.core.tasks'])
celery_task_serializer = TextConfigField('celery.task_serializer',
                                         default='pickle')
celery_send_task_error_emails = BooleanConfigField(
    'celery.send_task_error_emails', default=False)
celery_eager_propagates_exceptions = BooleanConfigField(
    'celery.eager_propagates_exceptions', default=True)
celery_track_started = BooleanConfigField('celery.track_started', default=True)

# broker settings
broker_backend = TextConfigField('broker.backend',
                                 u'sqlakombu.transport.Transport')
broker_host = TextConfigField('broker.host', 'sqlite:///kombu.db')
broker_port = IntegerConfigField('broker.port', 5672)
broker_user = TextConfigField('broker.user', u'inyoka')
broker_password = TextConfigField('broker.password', u'default')
broker_vhost = TextConfigField('broker.vhost', u'inyoka')


class CeleryLoader(BaseLoader):
Ejemplo n.º 5
0
from inyoka.i18n import _
from inyoka.context import ctx
from inyoka.core.config import TextConfigField, BooleanConfigField, \
    IntegerConfigField
from inyoka.core.forms.validators import is_valid_email, check
from inyoka.utils.urls import get_host_port_mapping, make_full_domain
from inyoka.utils.logger import logger

#: Used to split various formats of email addresses
_mail_split_re = re.compile(r'^(.*?)(?:\s+<(.+)>)?$')

#: outbox used for unittesting
outbox = []

# Configuration values
email_log_only = BooleanConfigField('email.log_only', default=False)
email_system_email = TextConfigField(
    'email.system_email',
    default=u'noreply@%s' % (ctx.cfg['base_domain_name'].split(':')[0]))

email_smtp_host = TextConfigField('email.smtp_host', default=u'localhost')
email_smtp_port = IntegerConfigField('email.smtp_port', default=25)
email_smtp_user = TextConfigField('email.smtp_user', default=u'')
email_smtp_password = TextConfigField('email.smtp_password', default=u'')
email_smtp_use_tls = BooleanConfigField('email.smtp_use_tls', default=False)


def split_email(s):
    """Split a mail address:

    >>> split_email("John Doe")
Ejemplo n.º 6
0
    IntegerConfigField
from itertools import imap
from itertools import ifilter
from io import open

_engine = None
_engine_lock = Lock()
_ending_numbers = re.compile(r'([^\d]+)(\d+)$')

#: The database URL.  For more information about database settings
#: consult the Inyoka docs.
database_url = TextConfigField('database.url', default=u'sqlite:///dev.db')

#: Set database debug.  If enabled the database will collect the SQL
#: statements and add them to the bottom of the page for easier debugging.
database_debug = BooleanConfigField('database.debug', default=False)

#: Set database echo.  If enabled the database will echo all submitted
#: statements to the default logger.  That defaults to stdout.
database_echo = BooleanConfigField('database.echo', default=False)

#: Set database pool recycle.  If set to non -1, used as number of seconds
#: between connection recycling.  If this timeout is surpassed, the connection
#: will be closed and replaced with a newly opened connection.
database_pool_recycle = IntegerConfigField('database.pool_recycle',
                                           default=-1,
                                           min_value=-1)

#: Set database pool timeout.  The number of seconds to wait before giving
#: up on a returning connection.  This will not be used if the used database
#: is one of SQLite, Access or Informix as those don't support
Ejemplo n.º 7
0
from inyoka.core.cache import cache as inyoka_cache
from inyoka.core.config import TextConfigField, BooleanConfigField


#! This signal is raised if a template is rendered.  Use it to catch context variables
#! and such stuff.
template_rendered = signals.signal('template-rendered')

#: The default templates path
_default_templates_path = os.path.join(os.environ['INYOKA_MODULE'], 'templates')

#: Custom template path which is searched before the default path
templates_path = TextConfigField('templates.path', default=_default_templates_path)

#: Auto reload template files if they changed
templates_auto_reload = BooleanConfigField('templates.auto_reload', default=True)

#: Use either ’memory’, ’filesystem’, or ’memcached’ bytecode caches
templates_use_cache = BooleanConfigField('templates.use_cache', default=False)

#: Use memcached for bytecode caching
templates_use_memcached_cache = BooleanConfigField('templates.use_memcached_cache', default=False)

#: Use filesystem for bytecode caching
templates_use_filesystem_cache = BooleanConfigField('templates.use_filesystem_cache', default=False)


def populate_context_defaults(context):
    """Fill in context defaults."""
    try:
        context.update({