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


Python fields.Str方法代码示例

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


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

示例1: user_list

# 需要导入模块: from webargs import fields [as 别名]
# 或者: from webargs.fields import Str [as 别名]
def user_list():
  args = parser.parse({
    'email': wf.Str(missing=None),
    'permissions': wf.DelimitedList(wf.Str(), delimiter=',', missing=[]),
  })
  user_dbs, cursors = model.User.get_dbs(
    email=args['email'], prev_cursor=True,
  )
  permissions = list(UserUpdateForm._permission_choices)
  permissions += args['permissions']
  return flask.render_template(
    'user/user_list.html',
    html_class='user-list',
    title='User List',
    user_dbs=user_dbs,
    next_url=util.generate_next_url(cursors['next']),
    prev_url=util.generate_next_url(cursors['prev']),
    api_url=flask.url_for('api.admin.user.list'),
    permissions=sorted(set(permissions)),
  )


###############################################################################
# User Update
############################################################################### 
开发者ID:lipis,项目名称:github-stats,代码行数:27,代码来源:user.py

示例2: get_next_url

# 需要导入模块: from webargs import fields [as 别名]
# 或者: from webargs.fields import Str [as 别名]
def get_next_url(next_url=''):
  args = parser.parse({
    'next': wf.Str(missing=None), 'next_url': wf.Str(missing=None)
  })
  next_url = next_url or args['next'] or args['next_url']
  if next_url:
    do_not_redirect_urls = [flask.url_for(u) for u in [
      'signin', 'signup', 'user_forgot', 'user_reset',
    ]]
    if any(url in next_url for url in do_not_redirect_urls):
      return flask.url_for('welcome')
    return is_trusted_url(next_url)
  return is_trusted_url(flask.request.referrer)


###############################################################################
# Model manipulations
############################################################################### 
开发者ID:lipis,项目名称:github-stats,代码行数:20,代码来源:util.py

示例3: parse_start_new_session

# 需要导入模块: from webargs import fields [as 别名]
# 或者: from webargs.fields import Str [as 别名]
def parse_start_new_session():
    args = parser.parse(
        {
            "recipe": fields.Str(),
            "session": fields.Str(),
            "user": fields.Str(),
            "code": fields.Str(required=True),
            "firm": fields.Str(),
            "machine": fields.Str(),
            "data": fields.Str(),
            "state": fields.Str(),
            "step": fields.Str(),
        },
        request,
        location="querystring",
    )

    if "recipe" in args:
        return create_new_session(args["recipe"], args)

    if "session" in args:
        return log_to_session(args["session"], args)

    # default fallthrough
    abort(500) 
开发者ID:hotzenklotz,项目名称:picobrew-server,代码行数:27,代码来源:picobrew_api.py

示例4: param

# 需要导入模块: from webargs import fields [as 别名]
# 或者: from webargs.fields import Str [as 别名]
def param(name, cast=None):
  def switch(case):
    return {
      int: wf.Int(missing=None),
      float: wf.Float(missing=None),
      bool: wf.Bool(missing=None),
      list: wf.DelimitedList(wf.Str(), delimiter=',', missing=[]),
    }.get(case)
  if cast is None or cast is ndb.Key:
    cast_ = wf.Str(missing=None)
  else:
    cast_ = switch(cast) or cast
  args = parser.parse({name: cast_})
  value = args[name]
  return ndb.Key(urlsafe=value) if cast is ndb.Key and value else value 
开发者ID:lipis,项目名称:github-stats,代码行数:17,代码来源:util.py

示例5: jsonpify

# 需要导入模块: from webargs import fields [as 别名]
# 或者: from webargs.fields import Str [as 别名]
def jsonpify(*args, **kwargs):
  params = parser.parse({'callback': wf.Str(missing=None)})
  if params['callback']:
    content = '%s(%s)' % (
      params['callback'], flask.jsonify(*args, **kwargs).data,
    )
    mimetype = 'application/javascript'
    return flask.current_app.response_class(content, mimetype=mimetype)
  return flask.jsonify(*args, **kwargs)


###############################################################################
# Helpers
############################################################################### 
开发者ID:lipis,项目名称:github-stats,代码行数:16,代码来源:util.py

示例6: get_dbs

# 需要导入模块: from webargs import fields [as 别名]
# 或者: from webargs.fields import Str [as 别名]
def get_dbs(cls, query=None, ancestor=None, order=None, limit=None, cursor=None, **kwargs):
    args = parser.parse({
      'cursor': wf.Str(missing=None),
      'limit': wf.Int(missing=None, validate=validate.Range(min=-1)),
      'order': wf.Str(missing=None),
    })
    return util.get_dbs(
      query or cls.query(ancestor=ancestor),
      limit=limit or args['limit'],
      cursor=cursor or args['cursor'],
      order=order or args['order'],
      **kwargs
    ) 
开发者ID:lipis,项目名称:github-stats,代码行数:15,代码来源:base.py

示例7: user_merge

# 需要导入模块: from webargs import fields [as 别名]
# 或者: from webargs.fields import Str [as 别名]
def user_merge():
  args = parser.parse({
    'user_key': wf.Str(missing=None),
    'user_keys': wf.DelimitedList(wf.Str(), delimiter=',', required=True),
  })

  user_db_keys = [ndb.Key(urlsafe=k) for k in args['user_keys']]
  user_dbs = ndb.get_multi(user_db_keys)
  if len(user_dbs) < 2:
    flask.abort(400)

  user_dbs.sort(key=lambda user_db: user_db.created)
  merged_user_db = user_dbs[0]
  auth_ids = []
  permissions = []
  is_admin = False
  is_active = False
  for user_db in user_dbs:
    auth_ids.extend(user_db.auth_ids)
    permissions.extend(user_db.permissions)
    is_admin = is_admin or user_db.admin
    is_active = is_active or user_db.active
    if user_db.key.urlsafe() == args['user_key']:
      merged_user_db = user_db

  auth_ids = sorted(list(set(auth_ids)))
  permissions = sorted(list(set(permissions)))
  merged_user_db.permissions = permissions
  merged_user_db.admin = is_admin
  merged_user_db.active = is_active
  merged_user_db.verified = False

  form_obj = copy.deepcopy(merged_user_db)
  form_obj.user_key = merged_user_db.key.urlsafe()
  form_obj.user_keys = ','.join(args['user_keys'])

  form = UserMergeForm(obj=form_obj)
  if form.validate_on_submit():
    form.populate_obj(merged_user_db)
    merged_user_db.auth_ids = auth_ids
    merged_user_db.put()

    deprecated_keys = [k for k in user_db_keys if k != merged_user_db.key]
    merge_user_dbs(merged_user_db, deprecated_keys)
    return flask.redirect(
      flask.url_for('user_update', user_id=merged_user_db.key.id()),
    )

  return flask.render_template(
    'user/user_merge.html',
    title='Merge Users',
    html_class='user-merge',
    user_dbs=user_dbs,
    merged_user_db=merged_user_db,
    form=form,
    auth_ids=auth_ids,
    api_url=flask.url_for('api.admin.user.list'),
  ) 
开发者ID:lipis,项目名称:github-stats,代码行数:60,代码来源:user.py

示例8: index

# 需要导入模块: from webargs import fields [as 别名]
# 或者: from webargs.fields import Str [as 别名]
def index(self, request):
    try:
        # patch __log
        self.__log = self._GRest__log

        __validation_rules__ = {
            "skip": fields.Int(required=False,
                               validate=lambda skip: skip >= 0,
                               missing=0),

            "limit": fields.Int(required=False,
                                validate=lambda lim: lim >= 1 and lim <= 100,
                                missing=QUERY_LIMIT),

            "order_by": fields.Str(required=False,
                                   missing="?")
        }

        (primary, secondary) = validate_models(self)

        query_data = validate_input(__validation_rules__, request)
        skip = query_data.get("skip")
        limit = query_data.get("skip") + query_data.get("limit")
        order_by = escape(query_data.get("order_by"))

        if order_by:
            if order_by.startswith("-"):
                # select property for descending ordering
                order_by_prop = order_by[1:]
            else:
                # select property for ascending ordering
                order_by_prop = order_by

            primary_model_props = primary.model.defined_properties().keys()
            if all([order_by_prop not in primary_model_props,
                    order_by_prop != "?"]):
                raise HTTPException(msg.INVALID_ORDER_PROPERTY, 404)

        total_items = len(primary.model.nodes)

        if total_items <= 0:
            raise HTTPException(msg.NO_ITEM_EXISTS.format(
                model=primary.model_name), 404)

        if skip > total_items:
            raise HTTPException(msg.VALIDATION_FAILED, 422)

        items = primary.model.nodes.order_by(order_by)[skip:limit]

        if items:
            return serialize({pluralize(primary.model_name):
                              [item.to_dict() for item in items]})
        else:
            raise HTTPException(msg.NO_ITEM_EXISTS.format(
                model=primary.model_name), 404)
    except DoesNotExist as e:
        self.__log.exception(e)
        raise HTTPException(msg.ITEM_DOES_NOT_EXIST, 404) 
开发者ID:mostafa,项目名称:grest,代码行数:60,代码来源:index.py

示例9: validation_rules

# 需要导入模块: from webargs import fields [as 别名]
# 或者: from webargs.fields import Str [as 别名]
def validation_rules(self):
        """
        if the user has defined validation rules,
        return that, otherwise construct a set of
        predefined rules and return it.

        All internal GRest methods should use this property.
        """

        if hasattr(self, "__validation_rules__"):
            if len(self.__validation_rules__) > 0:
                # there is a set of user-defined validation rules
                return self.__validation_rules__

        model_types = [
            StringProperty, DateTimeProperty, DateProperty,
            EmailProperty, BooleanProperty, UniqueIdProperty,
            ArrayProperty, IntegerProperty, JSONProperty
        ]

        model_mapping = {
            IntegerProperty: fields.Int,
            StringProperty: fields.Str,
            BooleanProperty: fields.Bool,
            DateTimeProperty: fields.DateTime,
            DateProperty: fields.Date,
            EmailProperty: fields.Email,
            ArrayProperty: fields.List,
            JSONProperty: fields.Dict,
            UniqueIdProperty: fields.UUID
        }

        name = 0
        value = 1

        for field in self.defined_properties().items():
            if field[name] not in self.__validation_rules__:
                if type(field[value]) in model_types:
                    if isinstance(field[value], ArrayProperty):
                        if field[value].unique_index:
                            # what it contains: Array of *String*
                            container = model_mapping[
                                type(field[value].unique_index)]
                        else:
                            # defaults to Raw for untyped ArrayProperty
                            container = fields.Raw

                        self.__validation_rules__[field[name]] = model_mapping[
                            type(field[value])](container,
                                                required=field[value].required)
                    else:
                        self.__validation_rules__[field[name]] = model_mapping[
                            type(field[value])](required=field[value].required)

        return self.__validation_rules__ 
开发者ID:mostafa,项目名称:grest,代码行数:57,代码来源:models.py


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