Пример #1
0
def datamodel_data_from_ini(id, inifile):
    def _parse_order(value):
        value = (value or '').strip()
        if not value:
            return None
        return [x for x in [x.strip() for x in value.strip().split(',')] if x]

    return dict(
        filename=inifile.filename,
        id=id,
        parent=inifile.get('model.inherits'),
        name_i18n=get_i18n_block(inifile, 'model.name'),
        label_i18n=get_i18n_block(inifile, 'model.label'),
        primary_field=inifile.get('model.primary_field'),
        hidden=inifile.get_bool('model.hidden', default=None),
        protected=inifile.get_bool('model.protected', default=None),
        child_config=dict(
            enabled=inifile.get_bool('children.enabled', default=None),
            slug_format=inifile.get('children.slug_format'),
            model=inifile.get('children.model'),
            order_by=_parse_order(inifile.get('children.order_by')),
            replaced_with=inifile.get('children.replaced_with'),
        ),
        attachment_config=dict(
            enabled=inifile.get_bool('attachments.enabled', default=None),
            model=inifile.get('attachments.model'),
            order_by=_parse_order(inifile.get('attachments.order_by')),
        ),
        pagination_config=dict(
            enabled=inifile.get_bool('pagination.enabled', default=None),
            per_page=inifile.get_int('pagination.per_page'),
            url_suffix=inifile.get('pagination.url_suffix'),
        ),
        fields=fielddata_from_ini(inifile),
    )
Пример #2
0
def datamodel_data_from_ini(id, inifile):
    def _parse_order(value):
        value = (value or '').strip()
        if not value:
            return None
        return [x for x in [x.strip() for x in value.strip().split(',')] if x]

    return dict(
        filename=inifile.filename,
        id=id,
        parent=inifile.get('model.inherits'),
        name_i18n=get_i18n_block(inifile, 'model.name'),
        label_i18n=get_i18n_block(inifile, 'model.label'),
        primary_field=inifile.get('model.primary_field'),
        hidden=inifile.get_bool('model.hidden', default=None),
        protected=inifile.get_bool('model.protected', default=None),
        child_config=dict(
            enabled=inifile.get_bool('children.enabled', default=None),
            slug_format=inifile.get('children.slug_format'),
            model=inifile.get('children.model'),
            order_by=_parse_order(inifile.get('children.order_by')),
            replaced_with=inifile.get('children.replaced_with'),
        ),
        attachment_config=dict(
            enabled=inifile.get_bool('attachments.enabled', default=None),
            model=inifile.get('attachments.model'),
            order_by=_parse_order(inifile.get('attachments.order_by')),
        ),
        pagination_config=dict(
            enabled=inifile.get_bool('pagination.enabled', default=None),
            per_page=inifile.get_int('pagination.per_page'),
            url_suffix=inifile.get('pagination.url_suffix'),
        ),
        fields=fielddata_from_ini(inifile),
    )
Пример #3
0
 def __init__(self, env, name, type=None, options=None):
     if type is None:
         type = env.types['string']
     if options is None:
         options = {}
     self.options = options
     self.name = name
     label_i18n = get_i18n_block(options, 'label')
     if not label_i18n:
         label_i18n = {'en': name.replace('_', ' ').strip().capitalize()}
     self.label_i18n = label_i18n
     self.description_i18n = get_i18n_block(options, 'description') or None
     self.default = options.get('default')
     self.type = type(env, options)
Пример #4
0
 def __init__(self, env, name, type=None, options=None):
     if type is None:
         type = env.types["string"]
     if options is None:
         options = {}
     self.options = options
     self.name = name
     label_i18n = get_i18n_block(options, "label")
     if not label_i18n:
         label_i18n = {"en": name.replace("_", " ").strip().capitalize()}
     self.label_i18n = label_i18n
     self.description_i18n = get_i18n_block(options, "description") or None
     self.default = options.get("default")
     self.type = type(env, options)
Пример #5
0
def _parse_choices(options):
    s = options.get('choices')
    if not s:
        return None

    choices = []
    items = s.split(',')
    user_labels = get_i18n_block(options, 'choice_labels')
    implied_labels = []

    for item in items:
        if '=' in item:
            choice, value = item.split('=', 1)
            choice = choice.strip()
            if choice.isdigit():
                choice = int(choice)
            implied_labels.append(value.strip())
            choices.append(choice)
        else:
            choices.append(item.strip())
            implied_labels.append(item.strip())

    if user_labels:
        rv = list(zip(choices, _reflow_and_split_labels(user_labels)))
    else:
        rv = [(key, {
            'en': label
        }) for key, label in zip(choices, implied_labels)]

    return rv
Пример #6
0
def _parse_choices(options):
    s = options.get('choices')
    if not s:
        return None

    choices = []
    items = s.split(',')
    user_labels = get_i18n_block(options, 'choice_labels')
    implied_labels = []

    for item in items:
        if '=' in item:
            choice, value = item.split('=', 1)
            choice = choice.strip()
            if choice.isdigit():
                choice = int(choice)
            implied_labels.append(value.strip())
            choices.append(choice)
        else:
            choices.append(item.strip())
            implied_labels.append(item.strip())

    if user_labels:
        rv = list(zip(choices, _reflow_and_split_labels(user_labels)))
    else:
        rv = [(key, {'en': label}) for key, label in
              zip(choices, implied_labels)]

    return rv
Пример #7
0
def update_config_from_ini(config, inifile):
    def set_simple(target, source_path):
        rv = config.get(source_path)
        if rv is not None:
            config[target] = rv

    set_simple(target='IMAGEMAGICK_EXECUTABLE',
               source_path='env.imagemagick_executable')
    set_simple(target='LESSC_EXECUTABLE', source_path='env.lessc_executable')

    for section_name in ('ATTACHMENT_TYPES', 'PROJECT', 'PACKAGES'):
        section_config = inifile.section_as_dict(section_name.lower())
        config[section_name].update(section_config)

    for sect in inifile.sections():
        if sect.startswith('servers.'):
            server_id = sect.split('.')[1]
            config['SERVERS'][server_id] = inifile.section_as_dict(sect)
        elif sect.startswith('alternatives.'):
            alt = sect.split('.')[1]
            config['ALTERNATIVES'][alt] = {
                'name': get_i18n_block(inifile, 'alternatives.%s.name' % alt),
                'url_prefix': inifile.get('alternatives.%s.url_prefix' % alt),
                'url_suffix': inifile.get('alternatives.%s.url_suffix' % alt),
                'primary': inifile.get_bool('alternatives.%s.primary' % alt),
                'locale': inifile.get('alternatives.%s.locale' % alt, 'en_US'),
            }

    for alt, alt_data in iteritems(config['ALTERNATIVES']):
        if alt_data['primary']:
            config['PRIMARY_ALTERNATIVE'] = alt
            break
    else:
        if config['ALTERNATIVES']:
            raise RuntimeError('Alternatives defined but no primary set.')
Пример #8
0
def flowblock_data_from_ini(id, inifile):
    return dict(
        filename=inifile.filename,
        id=id,
        name_i18n=get_i18n_block(inifile, 'block.name'),
        fields=fielddata_from_ini(inifile),
        order=inifile.get_int('block.order'),
        button_label=inifile.get('block.button_label'),
    )
Пример #9
0
def datamodel_data_from_ini(id, inifile):
    def _parse_order(value):
        value = (value or "").strip()
        if not value:
            return None
        return [x for x in [x.strip() for x in value.strip().split(",")] if x]

    return dict(
        filename=inifile.filename,
        id=id,
        parent=inifile.get("model.inherits"),
        name_i18n=get_i18n_block(inifile, "model.name"),
        label_i18n=get_i18n_block(inifile, "model.label"),
        primary_field=inifile.get("model.primary_field"),
        hidden=inifile.get_bool("model.hidden", default=None),
        protected=inifile.get_bool("model.protected", default=None),
        child_config=dict(
            enabled=inifile.get_bool("children.enabled", default=None),
            slug_format=inifile.get("children.slug_format"),
            model=inifile.get("children.model"),
            order_by=_parse_order(inifile.get("children.order_by")),
            replaced_with=inifile.get("children.replaced_with"),
            hidden=inifile.get_bool("children.hidden", default=None),
        ),
        attachment_config=dict(
            enabled=inifile.get_bool("attachments.enabled", default=None),
            model=inifile.get("attachments.model"),
            order_by=_parse_order(inifile.get("attachments.order_by")),
            hidden=inifile.get_bool("attachments.hidden", default=None),
        ),
        pagination_config=dict(
            enabled=inifile.get_bool("pagination.enabled", default=None),
            per_page=inifile.get_int("pagination.per_page"),
            url_suffix=inifile.get("pagination.url_suffix"),
            items=inifile.get("pagination.items"),
        ),
        fields=fielddata_from_ini(inifile),
    )
Пример #10
0
 def get_server(self, name, public=False):
     """Looks up a server info by name."""
     info = self.values['SERVERS'].get(name)
     if info is None:
         return None
     target = info.get('target')
     if target is None:
         return None
     if public:
         target = secure_url(target)
     return ServerInfo(id=name,
                       name_i18n=get_i18n_block(info, 'name'),
                       target=target,
                       enabled=bool_from_string(info.get('enabled'), True),
                       default=bool_from_string(info.get('default'), False))
Пример #11
0
 def get_server(self, name, public=False):
     """Looks up a server info by name."""
     info = self.values['SERVERS'].get(name)
     if info is None:
         return None
     target = info.get('target')
     if target is None:
         return None
     if public:
         target = secure_url(target)
     return ServerInfo(
         id=name,
         name_i18n=get_i18n_block(info, 'name'),
         target=target,
         enabled=info.get('enabled', 'true').lower() in ('true', 'yes', '1'),
     )
Пример #12
0
 def get_server(self, name, public=False):
     """Looks up a server info by name."""
     info = self.values['SERVERS'].get(name)
     if info is None or 'target' not in info:
         return None
     info = info.copy()
     target = info.pop('target')
     if public:
         target = secure_url(target)
     return ServerInfo(
         id=name,
         name_i18n=get_i18n_block(info, 'name', pop=True),
         target=target,
         enabled=bool_from_string(info.pop('enabled', None), True),
         default=bool_from_string(info.pop('default', None), False),
         extra=info
     )
Пример #13
0
 def get_server(self, name, public=False):
     """Looks up a server info by name."""
     info = self.values['SERVERS'].get(name)
     if info is None or 'target' not in info:
         return None
     info = info.copy()
     target = info.pop('target')
     if public:
         target = secure_url(target)
     return ServerInfo(id=name,
                       name_i18n=get_i18n_block(info, 'name', pop=True),
                       target=target,
                       enabled=bool_from_string(info.pop('enabled', None),
                                                True),
                       default=bool_from_string(info.pop('default', None),
                                                False),
                       extra=info)
Пример #14
0
 def get_server(self, name, public=False):
     """Looks up a server info by name."""
     info = self.values["SERVERS"].get(name)
     if info is None or "target" not in info:
         return None
     info = info.copy()
     target = info.pop("target")
     if public:
         target = secure_url(target)
     return ServerInfo(
         id=name,
         name_i18n=get_i18n_block(info, "name", pop=True),
         target=target,
         enabled=bool_from_string(info.pop("enabled", None), True),
         default=bool_from_string(info.pop("default", None), False),
         extra=info,
     )
Пример #15
0
 def get_server(self, name, public=False):
     """Looks up a server info by name."""
     info = self.values['SERVERS'].get(name)
     if info is None:
         return None
     target = info.get('target')
     if target is None:
         return None
     if public:
         target = secure_url(target)
     return ServerInfo(
         id=name,
         name_i18n=get_i18n_block(info, 'name'),
         target=target,
         enabled=bool_from_string(info.get('enabled'), True),
         default=bool_from_string(info.get('default'), False)
     )
Пример #16
0
 def get_server(self, name, public=False):
     """Looks up a server info by name."""
     info = self.values["SERVERS"].get(name)
     if info is None or "target" not in info:
         return None
     info = info.copy()
     target = info.pop("target")
     if public:
         target = secure_url(target)
     return ServerInfo(
         id=name,
         name_i18n=get_i18n_block(info, "name", pop=True),
         target=target,
         enabled=bool_from_string(info.pop("enabled", None), True),
         default=bool_from_string(info.pop("default", None), False),
         extra=info,
     )
Пример #17
0
def update_config_from_ini(config, inifile):
    def set_simple(target, source_path):
        rv = config.get(source_path)
        if rv is not None:
            config[target] = rv

    set_simple(target='IMAGEMAGICK_EXECUTABLE',
               source_path='env.imagemagick_executable')
    set_simple(target='LESSC_EXECUTABLE',
               source_path='env.lessc_executable')

    config['ATTACHMENT_TYPES'].update(
        (k.encode('ascii', 'replace'), v.encode('ascii', 'replace'))
        for k, v in inifile.section_as_dict('attachment_types'))

    config['PROJECT'].update(inifile.section_as_dict('project'))
    config['PACKAGES'].update(inifile.section_as_dict('packages'))

    for sect in inifile.sections():
        if sect.startswith('servers.'):
            server_id = sect.split('.')[1]
            config['SERVERS'][server_id] = inifile.section_as_dict(sect)
        elif sect.startswith('alternatives.'):
            alt = sect.split('.')[1]
            config['ALTERNATIVES'][alt] = {
                'name': get_i18n_block(inifile, 'alternatives.%s.name' % alt),
                'url_prefix': inifile.get('alternatives.%s.url_prefix' % alt),
                'url_suffix': inifile.get('alternatives.%s.url_suffix' % alt),
                'primary': inifile.get_bool('alternatives.%s.primary' % alt),
                'locale': inifile.get('alternatives.%s.locale' % alt, 'en_US'),
            }

    for alt, alt_data in config['ALTERNATIVES'].iteritems():
        if alt_data['primary']:
            config['PRIMARY_ALTERNATIVE'] = alt
            break
    else:
        if config['ALTERNATIVES']:
            raise RuntimeError('Alternatives defined but no primary set.')
Пример #18
0
def update_config_from_ini(config, inifile):
    def set_simple(target, source_path):
        rv = config.get(source_path)
        if rv is not None:
            config[target] = rv

    set_simple(target="IMAGEMAGICK_EXECUTABLE", source_path="env.imagemagick_executable")
    set_simple(target="LESSC_EXECUTABLE", source_path="env.lessc_executable")

    config["ATTACHMENT_TYPES"].update(
        (k.encode("ascii", "replace"), v.encode("ascii", "replace"))
        for k, v in inifile.section_as_dict("attachment_types")
    )

    config["PROJECT"].update(inifile.section_as_dict("project"))
    config["PACKAGES"].update(inifile.section_as_dict("packages"))

    for sect in inifile.sections():
        if sect.startswith("servers."):
            server_id = sect.split(".")[1]
            config["SERVERS"][server_id] = inifile.section_as_dict(sect)
        elif sect.startswith("alternatives."):
            alt = sect.split(".")[1]
            config["ALTERNATIVES"][alt] = {
                "name": get_i18n_block(inifile, "alternatives.%s.name" % alt),
                "url_prefix": inifile.get("alternatives.%s.url_prefix" % alt),
                "url_suffix": inifile.get("alternatives.%s.url_suffix" % alt),
                "primary": inifile.get_bool("alternatives.%s.primary" % alt),
                "locale": inifile.get("alternatives.%s.locale" % alt, "en_US"),
            }

    for alt, alt_data in iteritems(config["ALTERNATIVES"]):
        if alt_data["primary"]:
            config["PRIMARY_ALTERNATIVE"] = alt
            break
    else:
        if config["ALTERNATIVES"]:
            raise RuntimeError("Alternatives defined but no primary set.")
Пример #19
0
def update_config_from_ini(config, inifile):
    def set_simple(target, source_path):
        rv = config.get(source_path)
        if rv is not None:
            config[target] = rv

    set_simple(target="IMAGEMAGICK_EXECUTABLE",
               source_path="env.imagemagick_executable")
    set_simple(target="LESSC_EXECUTABLE", source_path="env.lessc_executable")

    for section_name in ("ATTACHMENT_TYPES", "PROJECT", "PACKAGES",
                         "THEME_SETTINGS"):
        section_config = inifile.section_as_dict(section_name.lower())
        config[section_name].update(section_config)

    for sect in inifile.sections():
        if sect.startswith("servers."):
            server_id = sect.split(".")[1]
            config["SERVERS"][server_id] = inifile.section_as_dict(sect)
        elif sect.startswith("alternatives."):
            alt = sect.split(".")[1]
            config["ALTERNATIVES"][alt] = {
                "name": get_i18n_block(inifile, "alternatives.%s.name" % alt),
                "url_prefix": inifile.get("alternatives.%s.url_prefix" % alt),
                "url_suffix": inifile.get("alternatives.%s.url_suffix" % alt),
                "primary": inifile.get_bool("alternatives.%s.primary" % alt),
                "locale": inifile.get("alternatives.%s.locale" % alt, "en_US"),
            }

    for alt, alt_data in config["ALTERNATIVES"].items():
        if alt_data["primary"]:
            config["PRIMARY_ALTERNATIVE"] = alt
            break
    else:
        if config["ALTERNATIVES"]:
            raise RuntimeError("Alternatives defined but no primary set.")
Пример #20
0
 def to_json(self, pad, record=None, alt=PRIMARY_ALT):
     rv = Type.to_json(self, pad, record, alt)
     rv['checkbox_label_i18n'] = get_i18n_block(
         self.options, 'checkbox_label')
     return rv
Пример #21
0
 def to_json(self, pad, record=None, alt=PRIMARY_ALT):
     rv = Type.to_json(self, pad, record, alt)
     rv['addon_label_i18n'] = get_i18n_block(
         self.options, 'addon_label') or None
     return rv
Пример #22
0
 def to_json(self, pad, record=None, alt=PRIMARY_ALT):
     rv = FakeType.to_json(self, pad, record, alt)
     rv["heading_i18n"] = get_i18n_block(self.options, "heading")
     return rv
Пример #23
0
 def to_json(self, pad, record=None, alt=PRIMARY_ALT):
     rv = FakeType.to_json(self, pad, record, alt)
     rv['heading_i18n'] = get_i18n_block(self.options, 'heading')
     return rv