当前位置: 首页>>代码示例>>Python>>正文


Python settings.asbool方法代码示例

本文整理汇总了Python中pyramid.settings.asbool方法的典型用法代码示例。如果您正苦于以下问题:Python settings.asbool方法的具体用法?Python settings.asbool怎么用?Python settings.asbool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyramid.settings的用法示例。


在下文中一共展示了settings.asbool方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: error

# 需要导入模块: from pyramid import settings [as 别名]
# 或者: from pyramid.settings import asbool [as 别名]
def error(exc, request):
        """Error method to return jsonapi compliant errors."""
        request.response.content_type = 'application/vnd.api+json'
        request.response.status_code = exc.code
        errors = {
            'errors': [
                {
                    'code': str(exc.code),
                    'detail': exc.detail,
                    'title': exc.title,
                }
            ]
        }
        if asbool(request.registry.settings.get('pyramid_jsonapi.debug_traceback', False)):
            errors['traceback'] = traceback.format_exc()
        return errors 
开发者ID:colinhiggs,项目名称:pyramid-jsonapi,代码行数:18,代码来源:__init__.py

示例2: load_settings

# 需要导入模块: from pyramid import settings [as 别名]
# 或者: from pyramid.settings import asbool [as 别名]
def load_settings(registry):
    return Settings(
        swagger12_handler=build_swagger12_handler(
            registry.settings.get('pyramid_swagger.schema12')),
        swagger20_handler=build_swagger20_handler(),
        validate_request=asbool(registry.settings.get(
            'pyramid_swagger.enable_request_validation',
            True,
        )),
        validate_response=asbool(registry.settings.get(
            'pyramid_swagger.enable_response_validation',
            True,
        )),
        validate_path=asbool(registry.settings.get(
            'pyramid_swagger.enable_path_validation',
            True,
        )),
        exclude_paths=get_exclude_paths(registry),
        exclude_routes=set(aslist(registry.settings.get(
            'pyramid_swagger.exclude_routes',
        ) or [])),
        prefer_20_routes=set(aslist(registry.settings.get(
            'pyramid_swagger.prefer_20_routes') or [])),
    ) 
开发者ID:striglia,项目名称:pyramid_swagger,代码行数:26,代码来源:tween.py

示例3: ificlaims_download_handler

# 需要导入模块: from pyramid import settings [as 别名]
# 或者: from pyramid.settings import asbool [as 别名]
def ificlaims_download_handler(request):
    """Download resources from IFI CLAIMS Direct"""

    resource = request.matchdict['resource']
    format   = request.matchdict['format'].lower()
    pretty   = asbool(request.params.get('pretty'))
    seq      = int(request.params.get('seq', 1))
    options = {'pretty': pretty, 'seq': seq}

    try:
        response = ificlaims_download(resource, format, options)

    except IFIClaimsException, ex:
        if type(ex) is IFIClaimsFormatException:
            raise HTTPNotFound(ex)
        else:
            raise HTTPBadRequest(ex) 
开发者ID:ip-tools,项目名称:patzilla,代码行数:19,代码来源:ificlaims.py

示例4: build_panel

# 需要导入模块: from pyramid import settings [as 别名]
# 或者: from pyramid.settings import asbool [as 别名]
def build_panel(self, panel, measurement):

        self.panel_id += 1

        try:
            legend_right_side = asbool(self.channel.settings.graphing_legend_right_side)
        except AttributeError:
            legend_right_side = False

        data_panel = {
            'id': self.panel_id,
            'datasource': self.datasource,
            'panel_title': panel.get('title', 'default'),
            'left_log_base': panel.get('scale', 1),
            'label_y': panel.get('label', ''),
            'format_y': panel.get('format', 'none'),
            'legend_right_side': json.dumps(legend_right_side),
        }

        # Build targets list from fieldnames
        targets_list = []
        for fieldname in panel['fieldnames']:
            data_target = self.get_target(panel, measurement, fieldname)
            target_json = self.build_target(data_target)
            targets_list.append(target_json)

        targets_json = ',\n'.join(targets_list)
        panel_json = self.tpl_panel.render(data_panel, targets=targets_json)
        #print 'panel_json:', panel_json
        try:
            return json.loads(panel_json)
        except Exception:
            log.failure(u'Failed building valid JSON for Grafana panel. data={data}, json={json}',
                data=data_panel, json=panel_json) 
开发者ID:daq-tools,项目名称:kotori,代码行数:36,代码来源:dashboard.py

示例5: get_vendors

# 需要导入模块: from pyramid import settings [as 别名]
# 或者: from pyramid.settings import asbool [as 别名]
def get_vendors(self):
        for name, config_object in self.settings.iteritems():
            if 'type' in config_object and config_object.type == 'vendor':
                if 'enable' not in config_object or asbool(config_object['enable']):
                    yield name 
开发者ID:daq-tools,项目名称:kotori,代码行数:7,代码来源:core.py

示例6: get_applications

# 需要导入模块: from pyramid import settings [as 别名]
# 或者: from pyramid.settings import asbool [as 别名]
def get_applications(self):
        for name, config_object in self.settings.iteritems():
            if 'type' in config_object and config_object.type == 'application':
                if 'enable' not in config_object or asbool(config_object['enable']):
                    yield name 
开发者ID:daq-tools,项目名称:kotori,代码行数:7,代码来源:core.py

示例7: get_data_uri

# 需要导入模块: from pyramid import settings [as 别名]
# 或者: from pyramid.settings import asbool [as 别名]
def get_data_uri(bucket, sibling=None, more_params=None):
    """
    Compute uri to data source as sibling to the current path.
    Add "from" and "to" query parameters from bucket.
    """

    more_params = more_params or {}

    forward_parameters = [u'from', u'to', u'exclude', u'include', u'pad', u'backfill', u'interpolate']

    request = bucket.request

    # Honor X-Forwarded-Proto request header if behind SSL-terminating HTTP proxy
    twisted_honor_reverse_proxy(request)

    url = URL()
    for param in forward_parameters:
        if param in bucket.tdata:
            url = url.add(unicode(param), unicode(bucket.tdata[param]))

    for param, value in more_params.iteritems():

        # Special rule: Don't add any of "pad" or "backfill", if "interpolate" is true
        do_interpolate = 'interpolate' in bucket.tdata and asbool(bucket.tdata.interpolate)
        if do_interpolate and param in ['pad', 'backfill']:
            continue

        url = url.add(unicode(param), unicode(value))

    data_uri = str(request.URLPath().sibling(sibling).click(url.asText()))
    return data_uri 
开发者ID:daq-tools,项目名称:kotori,代码行数:33,代码来源:util.py

示例8: get_jsmain

# 需要导入模块: from pyramid import settings [as 别名]
# 或者: from pyramid.settings import asbool [as 别名]
def get_jsmain():
    debug = asbool(get_settings().get("load_from_webpack_dev_server", False))
    if debug:
        return "http://localhost:3000/static/js/bundle.js"
    else:
        modpath = os.path.dirname(sys.modules[__name__].__file__)

        buildpath = os.path.join(modpath, "build")
        with open(os.path.join(buildpath, "asset-manifest.json"), "r") as f:
            manifest = json.load(f)
            return "/admin/jsstatic/"+lstrip_word(manifest["main.js"], "static/")

        return None 
开发者ID:ActiDoo,项目名称:gamification-engine,代码行数:15,代码来源:__init__.py

示例9: get_cssmain

# 需要导入模块: from pyramid import settings [as 别名]
# 或者: from pyramid.settings import asbool [as 别名]
def get_cssmain():
    debug = asbool(get_settings().get("load_from_webpack_dev_server", False))
    if debug:
        return "http://localhost:3000/static/css/bundle.css"
    else:
        modpath = os.path.dirname(sys.modules[__name__].__file__)

        buildpath = os.path.join(modpath, "build")
        with open(os.path.join(buildpath, "asset-manifest.json"), "r") as f:
            manifest = json.load(f)
            return "/admin/jsstatic/"+lstrip_word(manifest["main.css"],"static/")

        return None 
开发者ID:ActiDoo,项目名称:gamification-engine,代码行数:15,代码来源:__init__.py

示例10: delete_subject

# 需要导入模块: from pyramid import settings [as 别名]
# 或者: from pyramid.settings import asbool [as 别名]
def delete_subject(request):
    """delete a subject completely"""
    subject_id = int(request.matchdict["subject_id"])

    if asbool(get_settings().get("enable_user_authentication", False)):
        # ensure that the subject exists and we have the permission to update it
        may_delete = request.has_perm(perm_global_delete_subject) or request.has_perm(perm_own_delete_subject) and request.subject.id == subject_id
        if not may_delete:
            raise APIError(403, "forbidden", "You may not delete this subject.")

    Subject.delete_subject(subject_id)
    return {"status": "OK"} 
开发者ID:ActiDoo,项目名称:gamification-engine,代码行数:14,代码来源:views.py

示例11: register_device

# 需要导入模块: from pyramid import settings [as 别名]
# 或者: from pyramid.settings import asbool [as 别名]
def register_device(request):
    try:
        doc = request.json_body
    except:
        raise APIError(400, "invalid_json", "no valid json body")

    subject_id = int(request.matchdict["subject_id"])

    device_id = doc.get("device_id")
    push_id = doc.get("push_id")
    device_os = doc.get("device_os")
    app_version = doc.get("app_version")

    if not device_id \
            or not push_id \
            or not subject_id \
            or not device_os \
            or not app_version:
        raise APIError(400, "register_device.required_fields",
                       "Required fields: device_id, push_id, device_os, app_version")

    if asbool(get_settings().get("enable_user_authentication", False)):
        may_register = request.has_perm(perm_global_register_device) or request.has_perm(
            perm_own_register_device) and str(request.subject.id) == str(subject_id)
        if not may_register:
            raise APIError(403, "forbidden", "You may not register devices for this subject.")

    if not exists_by_expr(t_subjects, t_subjects.c.id==subject_id):
        raise APIError(404, "register_device.subject_not_found",
                       "There is no subject with this id.")

    SubjectDevice.add_or_update_device(subject_id = subject_id, device_id = device_id, push_id = push_id, device_os = device_os, app_version = app_version)

    return {
        "status" : "ok"
    } 
开发者ID:ActiDoo,项目名称:gamification-engine,代码行数:38,代码来源:views.py

示例12: get_messages

# 需要导入模块: from pyramid import settings [as 别名]
# 或者: from pyramid.settings import asbool [as 别名]
def get_messages(request):
    try:
        subject_id = int(request.matchdict["subject_id"])
    except:
        subject_id = None

    try:
        offset = int(request.GET.get("offset",0))
    except:
        offset = 0

    limit = 100

    if asbool(get_settings().get("enable_user_authentication", False)):
        may_read_messages = request.has_perm(perm_global_read_messages) or request.has_perm(
            perm_own_read_messages) and str(request.subject.id) == str(subject_id)
        if not may_read_messages:
            raise APIError(403, "forbidden", "You may not read the messages of this subject.")

    if not exists_by_expr(t_subjects, t_subjects.c.id == subject_id):
        raise APIError(404, "get_messages.subject_not_found",
                       "There is no subject with this id.")

    q = t_subject_messages.select().where(t_subject_messages.c.subject_id==subject_id).order_by(t_subject_messages.c.created_at.desc()).limit(limit).offset(offset)
    rows = DBSession.execute(q).fetchall()

    return {
        "messages" : [{
            "id" : message["id"],
            "text" : SubjectMessage.get_text(message),
            "is_read" : message["is_read"],
            "created_at" : message["created_at"]
        } for message in rows]
    } 
开发者ID:ActiDoo,项目名称:gamification-engine,代码行数:36,代码来源:views.py

示例13: set_messages_read

# 需要导入模块: from pyramid import settings [as 别名]
# 或者: from pyramid.settings import asbool [as 别名]
def set_messages_read(request):
    try:
        doc = request.json_body
    except:
        raise APIError(400, "invalid_json", "no valid json body")

    subject_id = int(request.matchdict["subject_id"])

    if asbool(get_settings().get("enable_user_authentication", False)):
        may_read_messages = request.has_perm(perm_global_read_messages) or request.has_perm(
            perm_own_read_messages) and str(request.subject.id) == str(subject_id)
        if not may_read_messages:
            raise APIError(403, "forbidden", "You may not read the messages of this subject.")

    if not exists_by_expr(t_subjects, t_subjects.c.id == subject_id):
        raise APIError(404, "set_messages_read.subject_not_found", "There is no subject with this id.")

    message_id = doc.get("message_id")
    q = select([t_subject_messages.c.id,
        t_subject_messages.c.created_at], from_obj=t_subject_messages).where(and_(t_subject_messages.c.id==message_id,
                                                                       t_subject_messages.c.subject_id==subject_id))
    msg = DBSession.execute(q).fetchone()
    if not msg:
        raise APIError(404, "set_messages_read.message_not_found", "There is no message with this id.")

    uS = update_connection()
    uS.execute(t_subject_messages.update().values({
        "is_read" : True
    }).where(and_(
        t_subject_messages.c.subject_id == subject_id,
        t_subject_messages.c.created_at <= msg["created_at"]
    )))

    return {
        "status" : "ok"
    } 
开发者ID:ActiDoo,项目名称:gamification-engine,代码行数:38,代码来源:views.py

示例14: may_increase

# 需要导入模块: from pyramid import settings [as 别名]
# 或者: from pyramid.settings import asbool [as 别名]
def may_increase(cls, variable_row, request, subject_id):
        if not asbool(get_settings().get("enable_user_authentication", False)):
            #Authentication deactivated
            return True
        if request.has_perm(perm_global_increase_value):
            # I'm the global admin
            return True
        if variable_row["increase_permission"] == "own" and request.subject and str(request.subject.id) == str(subject_id):
            #The variable may be updated for myself
            return True
        return False 
开发者ID:ActiDoo,项目名称:gamification-engine,代码行数:13,代码来源:model.py

示例15: asbool

# 需要导入模块: from pyramid import settings [as 别名]
# 或者: from pyramid.settings import asbool [as 别名]
def asbool(self, name, default=False, _set=False, pop=False):
        val = asbool(self.get(name, default))
        if _set:
            self[name] = val

        if pop:
            self.pop(name, None)

        return val 
开发者ID:ramses-tech,项目名称:nefertari,代码行数:11,代码来源:dictset.py


注:本文中的pyramid.settings.asbool方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。