How to use the trytond.config.config.get function in trytond

To help you get started, we’ve selected a few trytond 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 tryton / trytond / trytond / webdav / View on Github external
def get_webdav_url():
    if config.get('ssl', 'privatekey'):
        protocol = 'https'
        protocol = 'http'
    hostname = (config.get('webdav', 'hostname')
        or unicode(socket.getfqdn(), 'utf8'))
    hostname = '.'.join(encodings.idna.ToASCII(part) for part in
    return urlparse.urlunsplit((protocol, hostname,
            Transaction().cursor.database_name.encode('utf-8') + '/'),
            None, None))
github tryton / trytond / trytond / backend / sqlite / View on Github external
def list(self, hostname=None):
        res = []
        listdir = [':memory:']
            listdir += os.listdir(config.get('database', 'path'))
        except OSError:
        for db_file in listdir:
            if db_file.endswith('.sqlite') or db_file == ':memory:':
                if db_file == ':memory:':
                    db_name = ':memory:'
                    db_name = db_file[:-7]
                    database = Database(db_name).connect()
                except Exception:
                        'Test failed for "%s"', db_name, exc_info=True)
                if database.test(hostname=hostname):
github tryton / trytond / trytond / View on Github external
def setmany(self, data, prefix=''):
        return [self.set(d, prefix) for d in data]

    def _filename(self, id, prefix):
        path = os.path.normpath(config.get('database', 'path'))
        filename = os.path.join(path, prefix, id[0:2], id[2:4], id)
        filename = os.path.normpath(filename)
        if not filename.startswith(path):
            raise ValueError('Bad prefix')
        return filename

    def _id(self, data):
        return hashlib.md5(data).hexdigest()

if config.get('database', 'class'):
    FileStore = resolve(config.get('database', 'class'))  # noqa: F811
filestore = FileStore()
github tryton / trytond / trytond / ir / View on Github external
from trytond.transaction import Transaction
from .resource import ResourceMixin, resource_copy

__all__ = ['AttachmentCopyMixin']

def firstline(description):
        return next((x for x in description.splitlines() if x.strip()))
    except StopIteration:
        return ''

if config.getboolean('attachment', 'filestore', default=True):
    file_id = 'file_id'
    store_prefix = config.get('attachment', 'store_prefix', default=None)
    file_id = None
    store_prefix = None

class Attachment(ResourceMixin, ModelSQL, ModelView):
    __name__ = 'ir.attachment'
    name = fields.Char('Name', required=True)
    type = fields.Selection([
        ('data', 'Data'),
        ('link', 'Link'),
        ], 'Type', required=True)
    description = fields.Text('Description')
    summary = fields.Function(fields.Char('Summary'), 'on_change_with_summary')
    link = fields.Char('Link', states={
github tryton / trytond / trytond / backend / postgresql / View on Github external
def _connection_params(cls, name):
        uri = parse_uri(config.get('database', 'uri'))
        params = {
            'dbname': name,
        if uri.username:
            params['user'] = uri.username
        if uri.password:
            params['password'] = urllib.parse.unquote_plus(uri.password)
        if uri.hostname:
            params['host'] = uri.hostname
        if uri.port:
            params['port'] = uri.port
        return params
github tryton / trytond / trytond / ir / View on Github external
except ImportError:
    from http import client as HTTPStatus

from werkzeug.exceptions import abort
from werkzeug.utils import redirect
from werkzeug.wrappers import Response

from trytond.i18n import gettext
from trytond.config import config
from trytond.wsgi import app
from trytond.protocols.jsonrpc import JSONDecoder
from trytond.protocols.wrappers import with_pool, with_transaction
from import slugify
from trytond.transaction import Transaction

SOURCE = config.get(
    'html', 'src', default='')

def get_token(record):
    return str((record.write_date or record.create_date).timestamp())

def get_config(names, section='html', default=None):
    names = names[:]
    while names:
        value = config.get(section, '-'.join(names))
        if value is not None:
            return value
        names = names[:-1]
    return default
github tryton / trytond / trytond / model / View on Github external
def get_relation_fields(cls):
        if not config.get('dict', cls.__name__, default=True):
            return {}
        fields = cls._relation_fields_cache.get(cls.__name__)
        if fields is not None:
            return fields
        keys = cls.get_keys([]))
        fields = {k['name']: k for k in keys}
        cls._relation_fields_cache.set(cls.__name__, fields)
        return fields
github tryton / trytond / trytond / backend / mysql / View on Github external
def get_connection(self, autocommit=False, readonly=False):
        conv = MySQLdb.converters.conversions.copy()
        conv[float] = lambda value, _: repr(value)
        conv[MySQLdb.constants.FIELD_TYPE.TIME] = MySQLdb.times.Time_or_None
        args = {
            'sql_mode': 'traditional,postgresql',
            'use_unicode': True,
            'charset': 'utf8',
            'conv': conv,
        uri = parse_uri(config.get('database', 'uri'))
        if uri.hostname:
            args['host'] = uri.hostname
        if uri.port:
            args['port'] = uri.port
        if uri.username:
            args['user'] = uri.username
        if uri.password:
            args['passwd'] = urllib.unquote_plus(uri.password)
        conn = MySQLdb.connect(**args)
        cursor = conn.cursor()
        cursor.execute('SET time_zone = "+00:00"')
        return conn
github tryton / trytond / trytond / View on Github external
from trytond import backend
from trytond.wsgi import app
from trytond.transaction import Transaction
from trytond.protocols.jsonrpc import JSONEncoder, JSONDecoder
from trytond.config import config
from import resolve

logger = logging.getLogger(__name__)

_db_timeout = config.getint('database', 'timeout')
_cache_timeout = config.getint('bus', 'cache_timeout')
_select_timeout = config.getint('bus', 'select_timeout')
_long_polling_timeout = config.getint('bus', 'long_polling_timeout')
_allow_subscribe = config.getboolean('bus', 'allow_subscribe')
_url_host = config.get('bus', 'url_host')
_web_cache_timeout = config.getint('web', 'cache_timeout')

class _MessageQueue:

    Message = collections.namedtuple('Message', 'channel content timestamp')

    def __init__(self, timeout):
        self._lock = threading.Lock()
        self._timeout = timeout
        self._messages = []

    def append(self, channel, element):
            self.Message(channel, element, time.time()))