本文整理汇总了Python中sqlalchemy.util.OrderedDict.update方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedDict.update方法的具体用法?Python OrderedDict.update怎么用?Python OrderedDict.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.util.OrderedDict
的用法示例。
在下文中一共展示了OrderedDict.update方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ModelRenderer
# 需要导入模块: from sqlalchemy.util import OrderedDict [as 别名]
# 或者: from sqlalchemy.util.OrderedDict import update [as 别名]
#.........这里部分代码省略.........
ModelRenderer.rebind(self, model, session, data)
cls = isinstance(self.model, type) and self.model or type(self.model)
try:
class_mapper(cls)
except:
# this class is not managed by SA. extract any raw Fields defined on it.
keys = cls.__dict__.keys()
keys.sort(lambda a, b: cmp(a.lower(), b.lower())) # 2.3 support
for key in keys:
field = cls.__dict__[key]
if isinstance(field, fields.Field):
if field.name and field.name != key:
raise Exception('Fields in a non-mapped class have the same name as their attribute. Do not manually give them a name.')
field.name = field.key = key
self.append(field)
if not self._fields:
raise Exception("not bound to a SA instance, and no manual Field definitions found")
else:
# SA class.
# load synonyms so we can ignore them
synonyms = set(p for p in class_mapper(cls).iterate_properties
if isinstance(p, SynonymProperty))
# attributes we're interested in
attrs = []
for p in class_mapper(cls).iterate_properties:
attr = _get_attribute(cls, p)
if ((isinstance(p, SynonymProperty) or attr.property.key not in (s.name for s in synonyms))
and not isinstance(attr.impl, DynamicAttributeImpl)):
attrs.append(attr)
# sort relations last before storing in the OrderedDict
L = [fields.AttributeField(attr, self) for attr in attrs]
L.sort(lambda a, b: cmp(a.is_relation, b.is_relation)) # note, key= not used for 2.3 support
self._fields.update((field.key, field) for field in L)
def append(self, field):
"""Append a Field to the FieldSet.
By default, this Field will be included in the rendered form or table.
"""
if not isinstance(field, fields.Field):
raise ValueError('Can only add Field objects; got %s instead' % field)
field.parent = self
_fields = self._render_fields or self._fields
_fields[field.name] = field
return self # Cascade pattern
def add(self, field):
warnings.warn(DeprecationWarning('FieldSet.add is deprecated. Use FieldSet.append instead.'))
self.append(field)
def extend(self, fields):
"""Add a list of fields. By default, each Field will be included in the
rendered form or table."""
for field in fields:
self.append(field)
return self # Cascade pattern
def insert(self, field, new_field):
"""Insert a new field before an existing field"""
fields_ = self._render_fields or self._fields
if not isinstance(new_field, fields.Field):
raise ValueError('Can only add Field objects; got %s instead' % field)
if isinstance(field, fields.AbstractField):
try:
index = fields_.keys().index(field.name)
示例2: ModelRenderer
# 需要导入模块: from sqlalchemy.util import OrderedDict [as 别名]
# 或者: from sqlalchemy.util.OrderedDict import update [as 别名]
#.........这里部分代码省略.........
except:
# this class is not managed by SA. extract any raw Fields defined on it.
keys = cls.__dict__.keys()
keys.sort(lambda a, b: cmp(a.lower(), b.lower())) # 2.3 support
for key in keys:
field = cls.__dict__[key]
if isinstance(field, fields.Field):
if field.name and field.name != key:
raise Exception('Fields in a non-mapped class have the same name as their attribute. Do not manually give them a name.')
field.name = field.key = key
self.append(field)
if not self._fields:
raise Exception("not bound to a SA instance, and no manual Field definitions found")
else:
# SA class.
# load synonyms so we can ignore them
synonyms = set(p for p in class_mapper(cls).iterate_properties
if isinstance(p, SynonymProperty))
# load discriminators so we can ignore them
discs = set(p for p in class_mapper(cls).iterate_properties
if hasattr(p, '_is_polymorphic_discriminator')
and p._is_polymorphic_discriminator)
# attributes we're interested in
attrs = []
for p in class_mapper(cls).iterate_properties:
attr = _get_attribute(cls, p)
if ((isinstance(p, SynonymProperty) or attr.property.key not in (s.name for s in synonyms))
and not isinstance(attr.impl, DynamicAttributeImpl)
and p not in discs):
attrs.append(attr)
# sort relations last before storing in the OrderedDict
L = [fields.AttributeField(attr, self) for attr in attrs]
L.sort(lambda a, b: cmp(a.is_relation, b.is_relation)) # note, key= not used for 2.3 support
self._fields.update((field.key, field) for field in L)
def append(self, field):
"""Add a form Field. By default, this Field will be included in the rendered form or table."""
if not isinstance(field, fields.Field):
raise ValueError('Can only add Field objects; got %s instead' % field)
field.parent = self
_fields = self._render_fields or self._fields
_fields[field.name] = field
def add(self, field):
warnings.warn(DeprecationWarning('FieldSet.add is deprecated. Use FieldSet.append instead. Your validator will break in FA 1.5'))
self.append(field)
def extend(self, fields):
"""Add a list of fields. By default, each Field will be included in the
rendered form or table."""
for field in fields:
self.append(field)
def insert(self, field, new_field):
"""Insert a new field *before* an existing field.
This is like the normal ``insert()`` function of ``list`` objects. It
takes the place of the previous element, and pushes the rest forward.
"""
fields_ = self._render_fields or self._fields
if not isinstance(new_field, fields.Field):
raise ValueError('Can only add Field objects; got %s instead' % field)
if isinstance(field, fields.AbstractField):
try:
index = fields_.keys().index(field.name)
except ValueError:
示例3: FieldSet
# 需要导入模块: from sqlalchemy.util import OrderedDict [as 别名]
# 或者: from sqlalchemy.util.OrderedDict import update [as 别名]
#.........这里部分代码省略.........
for key in keys:
field = cls.__dict__[key]
if isinstance(field, fields.Field):
if field.name and field.name != key:
raise Exception('Fields in a non-mapped class have the same name as their attribute. Do not manually give them a name.')
field.name = field.key = key
self.append(field)
if not self._fields:
raise Exception("not bound to a SA instance, and no manual Field definitions found")
else:
# SA class.
# load synonyms so we can ignore them
ignore_keys = set()
for p in class_mapper(cls).iterate_properties:
if isinstance(p, SynonymProperty):
#ignore_keys.add(p.name)
# Can't ignore the original, this hides synonymized relationships when the ID it points to is not also synonymed
ignore_keys.add(p.key)
elif hasattr(p, '_is_polymorphic_discriminator') and p._is_polymorphic_discriminator:
ignore_keys.add(p.key)
elif isinstance(p, CompositeProperty):
for p in p.props:
ignore_keys.add(p.key)
# attributes we're interested in
attrs = []
for p in class_mapper(cls).iterate_properties:
attr = _get_attribute(cls, p)
if attr.property.key not in ignore_keys and p.key not in ignore_keys and not isinstance(attr.impl, DynamicAttributeImpl):
attrs.append(attr)
# sort relations last before storing in the OrderedDict
L = [fields.AttributeField(attr, self) for attr in attrs]
L.sort(key=lambda a: a.is_relation)
self._fields.update((field.key, field) for field in L)
def configure(self, pk=False, focus=True, readonly=False, global_validator=None, exclude=[], include=[], options=[]):
"""
The `configure` method specifies a set of attributes to be rendered.
By default, all attributes are rendered except primary keys and
foreign keys. But, relations `based on` foreign keys `will` be
rendered. For example, if an `Order` has a `user_id` FK and a `user`
relation based on it, `user` will be rendered (as a select box of
`User`'s, by default) but `user_id` will not.
Parameters:
* `pk=False`:
set to True to include primary key columns
* `exclude=[]`:
an iterable of attributes to exclude. Other attributes will
be rendered normally
* `include=[]`:
an iterable of attributes to include. Other attributes will
not be rendered
* `options=[]`:
an iterable of modified attributes. The set of attributes to
be rendered is unaffected
* `global_validator=None`:
global_validator` should be a function that performs
validations that need to know about the entire form.
* `focus=True`:
the attribute (e.g., `fs.orders`) whose rendered input element
gets focus. Default value is True, meaning, focus the first
element. False means do not focus at all.
* `readonly=False`:
if true, the fieldset will be rendered as a table (tbody)