本文整理汇总了Python中sqlalchemy.util.OrderedDict.keys方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedDict.keys方法的具体用法?Python OrderedDict.keys怎么用?Python OrderedDict.keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.util.OrderedDict
的用法示例。
在下文中一共展示了OrderedDict.keys方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ModelRenderer
# 需要导入模块: from sqlalchemy.util import OrderedDict [as 别名]
# 或者: from sqlalchemy.util.OrderedDict import keys [as 别名]
#.........这里部分代码省略.........
>>> fs2 = fs.bind(user)
>>> html = fs2.render()
The `render_fields` attribute is an OrderedDict of all the `Field`'s
that have been configured, keyed by name. The order of the fields
is the order in `include`, or the order they were declared
in the SQLAlchemy model class if no `include` is specified.
The `_fields` attribute is an OrderedDict of all the `Field`'s
the ModelRenderer knows about, keyed by name, in their
unconfigured state. You should not normally need to access
`_fields` directly.
(Note that although equivalent `Field`'s (fields referring to
the same attribute on the SQLAlchemy model) will equate with
the == operator, they are NOT necessarily the same `Field`
instance. Stick to referencing `Field`'s from their parent
`FieldSet` to always get the "right" instance.)
"""
self._fields = OrderedDict()
self._render_fields = OrderedDict()
self.model = self.session = None
self.prefix = prefix
if not model:
raise Exception('model parameter may not be None')
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.
"""
示例2: CospreadDataRecords
# 需要导入模块: from sqlalchemy.util import OrderedDict [as 别名]
# 或者: from sqlalchemy.util.OrderedDict import keys [as 别名]
class CospreadDataRecords(SpreadsheetDataRecords):
def __init__(self, data, generate_names=False):
self.generate_names = generate_names
# cospread uses a list of alternative essential_titles
essential_titles = ["Package name", "Abstract"]
self.title_normaliser = (
# ('Normalised title', 'regex of variations'),
("Package name", "(Package name|Identifier)$"),
("Title", "Title$"),
("CO Identifier", "CO (Identifier|Reference)$"),
("Notes", "Notes|Abstract$"),
("Date released", "Date released$"),
("Date updated", "Date updated$"),
("Date update future", "Date to be published$"),
("Update frequency", "Update frequency$"),
("Geographical Granularity - Standard", "Geographical Granularity - Standard$"),
("Geographical Granularity - Other", "Geographical Granularity - Other$"),
("Geographic coverage - England", "Geographic coverage - England$"),
("Geographic coverage - N. Ireland", "Geographic coverage - N. Ireland$"),
("Geographic coverage - Scotland", "Geographic coverage - Scotland$"),
("Geographic coverage - Wales", "Geographic coverage - Wales$"),
("Geographic coverage - Overseas", "Geographic coverage - Overseas$"),
("Geographic coverage - Global", "Geographic coverage - Global$"),
("Temporal Granularity - Standard", "Temporal Granularity - Standard$"),
("Temporal Granularity - Other", "Temporal Granularity - Other$"),
("Temporal Coverage - To", "Temporal Coverage - To"),
("Temporal Coverage - From", "Temporal Coverage - From$"),
("Categories", "Categories$"),
("National Statistic", "National Statistic$"),
("Precision", "Precision$"),
("URL", "URL$"),
("Download URL", "(Download URL|Resources - URL)$"),
("File format", "(Download |Resources - )?file format$"),
("Download Description", "(Resources -|Download) Description$"),
("Taxonomy URL", "Taxonomy URL$"),
("Department", "Department$"),
("Agency responsible", "Agency responsible$"),
("Published by", "Published by$"),
("Published via", "Published via$"),
("Contact - Permanent contact point", "(Contact|Author) - Permanent contact point"),
("Contact - E-mail address.", "(Contact|Author) - E-mail address.$"),
("Maintainer - ", "Maintainer - (Blank unless not the author\.)?$"),
("Maintainer - E-mail address", "Maintainer - E-mail address"),
("Licence", "Licence$"),
("Tags", "Tags$"),
("Mandate", "Mandate$"),
)
# compile regexes
self.title_normaliser = [(norm_title, re.compile(regex, re.I)) for norm_title, regex in self.title_normaliser]
self.optional_columns = [
u"Temporal Coverage - To",
u"Temporal Coverage - From",
u"Download Description",
u"National Statistic",
u"Maintainer - E-mail address",
u"Maintainer - ",
u"Categories",
]
self.column_spreading_titles = [
"Geographical Granularity",
"Geographic coverage",
"Temporal Granularity",
"Temporal Coverage",
"Author",
"Maintainer",
"Contact",
]
self.standard_or_other_columns = ["Geographical Granularity", "Temporal Granularity"]
self.resource_keys = ["Download URL", "File format", "Download Description"]
super(CospreadDataRecords, self).__init__(data, essential_titles)
def find_titles(self, essential_titles):
row_index = 0
titles = []
assert isinstance(essential_titles, (list, tuple))
essential_title_set = set(essential_titles + [title.lower() for title in essential_titles])
while True:
if row_index >= self._data.get_num_rows():
raise ImportException("Could not find title row")
row = self._data.get_row(row_index)
if essential_title_set & set(row):
next_row = self._data.get_row(row_index + 1)
last_title = None
for col_index, row_val in enumerate(row):
if not row_val:
title = None
if last_title in self.column_spreading_titles:
title = "%s - %s" % (last_title, next_row[col_index])
else:
title = row_val.strip().replace(" ", " ")
last_title = title
if title in self.column_spreading_titles:
title = "%s - %s" % (title, next_row[col_index])
titles.append(title)
return (titles, row_index + 1)
row_index += 1
def create_title_mapping(self):
"""Creates a mapping between the spreadsheet\'s actual column
titles and the normalised versions.
#.........这里部分代码省略.........