有人能指出我支持/不支持HTML5 History API的浏览器的兼容性图表吗?
规格:http://www.w3.org/TR/html5/history.html
教程:https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history
我通过Flask.WTF扩展使用带有Flask的WTForms.不过,这个问题不是Flask特有的.
WTForms包括FieldList字段列表的字段.我想用它来制作一个用户可以添加或删除项目的表单.这将需要某种Ajax框架来动态添加小部件,但WTForms文档没有提及它.
SQLAlchemy中是否可以有多级多态?这是一个例子:
class Entity(Base):
__tablename__ = 'entities'
id = Column(Integer, primary_key=True)
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
entity_type = Column(Unicode(20), nullable=False)
__mapper_args__ = {'polymorphic_on': entity_type}
class File(Entity):
__tablename__ = 'files'
id = Column(None, ForeignKey('entities.id'), primary_key=True)
filepath = Column(Unicode(255), nullable=False)
file_type = Column(Unicode(20), nullable=False)
__mapper_args__ = {'polymorphic_identity': u'file', 'polymorphic_on': file_type)
class Image(File):
__mapper_args__ = {'polymorphic_identity': u'image'}
__tablename__ = 'images'
id = Column(None, ForeignKey('files.id'), primary_key=True)
width = Column(Integer)
height = Column(Integer)
Run Code Online (Sandbox Code Playgroud)
当我调用时Base.metadata.create_all(),SQLAlchemy会引发以下错误:
IntegrityError: (IntegrityError) entities.entity_type may not be NULL`.
Run Code Online (Sandbox Code Playgroud)
如果我删除Image模型和 …
我有一些标准的SQLAlchemy模型,我可以在项目中重复使用.像这样的东西:
from sqlalchemy import Column, Integer, String, Unicode
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Category(Base):
__tablename__ = 'category'
id = Column(Integer, primary_key=True)
slug = Column(String(250), nullable=False, unique=True)
title = Column(Unicode(250), nullable=False)
def __call__(self):
return self.title
Run Code Online (Sandbox Code Playgroud)
我想把它放在一个共享库中,然后将它导入到每个新项目中,而不是剪切和粘贴它,但我不能,因为declarative_base实例是在项目中单独定义的.如果不止一个,他们将不会分享会话.我该如何解决这个问题?
这是另一个建议使用mixin类的问题.这可行吗?SQLAlchemy会从mixin类中准确地导入外键吗?
如何预先填写Formish表格?根据文档显而易见的方法似乎并不正确.使用提供的示例之一:
import formish, schemaish
structure = schemaish.Structure()
structure.add( 'a', schemaish.String() )
structure.add( 'b', schemaish.Integer() )
schema = schemaish.Structure()
schema.add( 'myStruct', structure )
form = formish.Form(schema, 'form')
Run Code Online (Sandbox Code Playgroud)
如果我们传递一个有效的请求对象:
form.validate(request)
Run Code Online (Sandbox Code Playgroud)
输出是这样的结构:
{'myStruct': {'a': 'value', 'b': 0 }}
Run Code Online (Sandbox Code Playgroud)
但是,使用defaults此预填充表单需要:
form.defaults = {'myStruct.a': 'value', 'myStruct.b': 0}
Run Code Online (Sandbox Code Playgroud)
该dottedish包有一个DottedDict可以将嵌套的dict转换为虚线dict的对象,但这种不对称似乎并不正确.有一个更好的方法吗?
我正在尝试创建一个数据库结构,其中我有许多类型的内容实体,其中一个,一个注释,可以附加到任何其他实体.
考虑以下:
from datetime import datetime
from sqlalchemy import create_engine
from sqlalchemy import Column, ForeignKey
from sqlalchemy import Unicode, Integer, DateTime
from sqlalchemy.orm import relation, backref
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Entity(Base):
__tablename__ = 'entities'
id = Column(Integer, primary_key=True)
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
edited_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
type = Column(Unicode(20), nullable=False)
__mapper_args__ = {'polymorphic_on': type}
# <...insert some models based on Entity...>
class Comment(Entity):
__tablename__ = 'comments'
__mapper_args__ = {'polymorphic_identity': u'comment'}
id = Column(None, …Run Code Online (Sandbox Code Playgroud) 我正在编写一个Python函数来将文本拆分为单词,忽略指定的标点符号.这是一些工作代码.我不相信从列表中构造字符串(代码中的buf = [])是有效的.有没有人建议更好的方法来做到这一点?
def getwords(text, splitchars=' \t|!?.;:"'):
"""
Generator to get words in text by splitting text along specified splitchars
and stripping out the splitchars::
>>> list(getwords('this is some text.'))
['this', 'is', 'some', 'text']
>>> list(getwords('and/or'))
['and', 'or']
>>> list(getwords('one||two'))
['one', 'two']
>>> list(getwords(u'hola unicode!'))
[u'hola', u'unicode']
"""
splitchars = set(splitchars)
buf = []
for char in text:
if char not in splitchars:
buf.append(char)
else:
if buf:
yield ''.join(buf)
buf = []
# All done. Yield last word.
if buf: …Run Code Online (Sandbox Code Playgroud)