本文整理匯總了Python中inbox.models.Part.content_id方法的典型用法代碼示例。如果您正苦於以下問題:Python Part.content_id方法的具體用法?Python Part.content_id怎麽用?Python Part.content_id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類inbox.models.Part
的用法示例。
在下文中一共展示了Part.content_id方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: block_to_part
# 需要導入模塊: from inbox.models import Part [as 別名]
# 或者: from inbox.models.Part import content_id [as 別名]
def block_to_part(block, message, namespace):
inline_image_uri = r'cid:{}'.format(block.public_id)
is_inline = re.search(inline_image_uri, message.body) is not None
# Create a new Part object to associate to the message object.
# (You can't just set block.message, because if block is an
# attachment on an existing message, that would dissociate it from
# the existing message.)
part = Part(block=block)
part.content_id = block.public_id if is_inline else None
part.namespace_id = namespace.id
part.content_disposition = 'inline' if is_inline else 'attachment'
part.is_inboxapp_attachment = True
return part
示例2: _save_attachment
# 需要導入模塊: from inbox.models import Part [as 別名]
# 或者: from inbox.models.Part import content_id [as 別名]
def _save_attachment(self, mimepart, content_disposition, content_type,
filename, content_id, namespace_id, mid):
from inbox.models import Part, Block
block = Block()
block.namespace_id = namespace_id
block.filename = _trim_filename(filename, mid=mid)
block.content_type = content_type
part = Part(block=block, message=self)
part.content_id = content_id
part.content_disposition = content_disposition
data = mimepart.body or ''
if isinstance(data, unicode):
data = data.encode('utf-8', 'strict')
block.data = data
示例3: upgrade
# 需要導入模塊: from inbox.models import Part [as 別名]
# 或者: from inbox.models.Part import content_id [as 別名]
def upgrade():
from inbox.models.session import session_scope, Session
from inbox.ignition import engine
from inbox.models import Part, Namespace, Message, Thread
from inbox.sqlalchemy_ext.util import JSON
print "Creating table for parts..."
op.create_table(
"part",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("message_id", sa.Integer(), nullable=True),
sa.Column("walk_index", sa.Integer(), nullable=True),
sa.Column("content_disposition", sa.Enum("inline", "attachment"), nullable=True),
sa.Column("content_id", sa.String(length=255), nullable=True),
sa.Column("misc_keyval", JSON(), nullable=True),
sa.Column("is_inboxapp_attachment", sa.Boolean(), server_default=sa.sql.expression.false(), nullable=True),
sa.ForeignKeyConstraint(["id"], ["block.id"], ondelete="CASCADE"),
sa.ForeignKeyConstraint(["message_id"], ["message.id"], ondelete="CASCADE"),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("message_id", "walk_index"),
)
print "Reflecting old block table schema"
Base = declarative_base()
Base.metadata.reflect(engine)
class Block_(Base): # old schema, reflected from database table
__table__ = Base.metadata.tables["block"]
print "Adding namespace_id column to blocks ",
op.add_column(u"block", sa.Column("namespace_id", sa.Integer(), nullable=False))
print "Migrating from blocks to parts"
new_parts = []
with session_scope() as db_session:
for block in db_session.query(Block_).yield_per(chunk_size):
# Move relevant fields
p = Part()
p.size = block.size
p.data_sha256 = block.data_sha256
p.message_id = block.message_id
p.walk_index = block.walk_index
p.content_disposition = block.content_disposition
p.content_id = block.content_id
p.misc_keyval = block.misc_keyval
p.is_inboxapp_attachment
old_namespace = (
db_session.query(Namespace)
.join(Message.thread, Thread.namespace)
.filter(Message.id == block.message_id)
.one()
)
p.namespace_id = old_namespace.id
# Commit after column modifications
new_parts.append(p)
print "Deleting old blocks (now parts)... ",
db_session.query(Block_).delete()
db_session.commit()
print "Done!"
print "Removing `message_id` constraint from block"
op.drop_constraint("block_ibfk_1", "block", type_="foreignkey")
print "Creating foreign key for block -> namespace on block"
op.create_foreign_key("block_ibfk_1", "block", "namespace", ["namespace_id"], ["id"], ondelete="CASCADE")
print "Dropping old block columns which are now in part"
op.drop_column(u"block", u"walk_index")
op.drop_column(u"block", u"content_disposition")
op.drop_column(u"block", u"misc_keyval")
op.drop_column(u"block", u"content_id")
op.drop_column(u"block", u"is_inboxapp_attachment")
op.drop_constraint(u"message_id", "block", type_="unique")
op.drop_column(u"block", u"message_id")
# Note: here we use the regular database session, since the transaction
# log requires the `namespace` property on objects. We've set the
# `namespace_id` foreign key, but need to commit the object before the
# SQLalchemy reference is valid
no_tx_session = Session(autoflush=True, autocommit=False)
no_tx_session.add_all(new_parts)
no_tx_session.commit()
print "Done migration blocks to parts!"