本文整理汇总了Python中inbox.models.Folder.create方法的典型用法代码示例。如果您正苦于以下问题:Python Folder.create方法的具体用法?Python Folder.create怎么用?Python Folder.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inbox.models.Folder
的用法示例。
在下文中一共展示了Folder.create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_folder_names
# 需要导入模块: from inbox.models import Folder [as 别名]
# 或者: from inbox.models.Folder import create [as 别名]
def save_folder_names(log, account, folder_names, db_session):
"""
Create Folder objects & map special folder names on Account objects.
Folders that belong to an account and no longer exist in `folder_names`
ARE DELETED.
"""
# NOTE: We don't do anything like canonicalizing to lowercase because
# different backends may be case-sensitive or not. Code that references
# saved folder names should canonicalize if needed when doing comparisons.
assert 'inbox' in folder_names, 'Account {} has no detected inbox folder'\
.format(account.email_address)
folders = {f.name.lower(): f for f in
db_session.query(Folder).filter_by(account=account)}
for canonical_name in ['inbox', 'drafts', 'sent', 'spam', 'trash',
'starred', 'important', 'archive', 'all']:
if canonical_name in folder_names:
backend_folder_name = folder_names[canonical_name].lower()
if backend_folder_name not in folders:
folder = Folder.create(account, folder_names[canonical_name],
db_session,
canonical_name)
attr_name = '{}_folder'.format(canonical_name)
setattr(account, attr_name, verify_folder_name(
account.id, getattr(account, attr_name), folder))
else:
del folders[backend_folder_name]
# Gmail labels, user-created IMAP/EAS folders, etc.
if 'extra' in folder_names:
for name in folder_names['extra']:
name = name[:MAX_FOLDER_NAME_LENGTH]
if name.lower() not in folders:
folder = Folder.create(account, name, db_session)
db_session.add(folder)
if name.lower() in folders:
del folders[name.lower()]
# This may cascade to FolderItems and ImapUid (ONLY), which is what we
# want--doing the update here short-circuits us syncing that change later.
log.info("Folders were deleted from the remote: {}".format(folders.keys()))
for folder in folders.values():
db_session.delete(folder)
# TODO(emfree) delete associated tag
# Create associated tags for any new folders.
for folder in account.folders:
folder.get_associated_tag(db_session)
db_session.commit()
示例2: save_folder_names
# 需要导入模块: from inbox.models import Folder [as 别名]
# 或者: from inbox.models.Folder import create [as 别名]
def save_folder_names(log, account_id, folder_names, db_session):
"""
Create Folder objects & map special folder names on Account objects.
Folders that belong to an account and no longer exist in `folder_names`
ARE DELETED, unless they are "dangling" (do not have a 'name' set).
We don't canonicalizing folder names to lowercase when saving
because different backends may be case-sensitive or not. Code that
references saved folder names should canonicalize if needed when doing
comparisons.
"""
account = db_session.query(Account).get(account_id)
assert 'inbox' in folder_names, 'Account {} has no detected inbox folder'\
.format(account.email_address)
all_folders = db_session.query(Folder).filter_by(
account_id=account.id).all()
# dangled_folders don't map to upstream account folders (may be used for
# keeping track of e.g. special Gmail labels which are exposed as IMAP
# flags but not folders)
folder_for = {f.name.lower(): f for f in all_folders if f.name is not None}
dangled_folder_for = {f.canonical_name: f for f in all_folders
if f.name is None}
canonical_names = {'inbox', 'drafts', 'sent', 'spam', 'trash',
'starred', 'important', 'archive', 'all'}
for canonical_name in canonical_names:
if canonical_name in folder_names:
backend_folder_name = folder_names[canonical_name].lower()
if backend_folder_name not in folder_for:
# Reconcile dangled folders which now exist on the remote
if canonical_name in dangled_folder_for:
folder = dangled_folder_for[canonical_name]
folder.name = folder_names[canonical_name]
del dangled_folder_for[canonical_name]
else:
folder = Folder.create(account,
folder_names[canonical_name],
db_session, canonical_name)
folder.get_associated_tag(db_session)
attr_name = '{}_folder'.format(canonical_name)
setattr(account, attr_name, verify_folder_name(
account.id, getattr(account, attr_name), folder))
else:
del folder_for[backend_folder_name]
# Gmail labels, user-created IMAP/EAS folders, etc.
if 'extra' in folder_names:
for name in folder_names['extra']:
name = name[:MAX_FOLDER_NAME_LENGTH]
if name.lower() not in folder_for:
# Folder.create() takes care of adding to the session
folder = Folder.create(account, name, db_session)
folder.get_associated_tag(db_session)
if name.lower() in folder_for:
del folder_for[name.lower()]
# This may cascade to FolderItems and ImapUid (ONLY), which is what we
# want--doing the update here short-circuits us syncing that change later.
log.info("folders deleted from remote", folders=folder_for.keys())
for name, folder in folder_for.iteritems():
db_session.delete(folder)
# TODO(emfree) delete associated tag
db_session.commit()
示例3: save_folder_names
# 需要导入模块: from inbox.models import Folder [as 别名]
# 或者: from inbox.models.Folder import create [as 别名]
def save_folder_names(log, account_id, folder_names, db_session):
"""
Create Folder objects & map special folder names on Account objects.
Folders that belong to an account and no longer exist in `folder_names`
ARE DELETED, unless they are "dangling" (do not have a 'name' set).
We don't canonicalizing folder names to lowercase when saving
because different backends may be case-sensitive or not. Code that
references saved folder names should canonicalize if needed when doing
comparisons.
"""
account = db_session.query(Account).get(account_id)
assert "inbox" in folder_names, "Account {} has no detected inbox folder".format(account.email_address)
all_folders = db_session.query(Folder).filter_by(account_id=account.id).all()
# dangled_folders don't map to upstream account folders (may be used for
# keeping track of e.g. special Gmail labels which are exposed as IMAP
# flags but not folders)
folder_for = {f.name: f for f in all_folders if f.name is not None}
dangled_folder_for = {f.canonical_name: f for f in all_folders if f.name is None}
canonical_names = {"inbox", "drafts", "sent", "spam", "trash", "starred", "important", "archive", "all"}
for canonical_name in canonical_names:
if canonical_name in folder_names:
backend_folder_name = folder_names[canonical_name]
if backend_folder_name not in folder_for:
# Reconcile dangled folders which now exist on the remote
if canonical_name in dangled_folder_for:
folder = dangled_folder_for[canonical_name]
folder.name = folder_names[canonical_name]
del dangled_folder_for[canonical_name]
else:
folder = Folder.find_or_create(db_session, account, None, canonical_name)
if folder.name != folder_names[canonical_name]:
if folder.name is not None:
del folder_for[folder.name]
folder.name = folder_names[canonical_name]
folder.get_associated_tag(db_session)
attr_name = "{}_folder".format(canonical_name)
id_attr_name = "{}_folder_id".format(canonical_name)
if getattr(account, id_attr_name) != folder.id:
# NOTE: updating the relationship (i.e., attr_name) also
# updates the associated foreign key (i.e., id_attr_name)
setattr(account, attr_name, folder)
else:
del folder_for[backend_folder_name]
# Gmail labels, user-created IMAP/EAS folders, etc.
if "extra" in folder_names:
for name in folder_names["extra"]:
name = name[:MAX_FOLDER_NAME_LENGTH]
if name not in folder_for:
# Folder.create() takes care of adding to the session
folder = Folder.create(account, name, db_session)
folder.get_associated_tag(db_session)
else:
del folder_for[name]
# This may cascade to FolderItems and ImapUid (ONLY), which is what we
# want--doing the update here short-circuits us syncing that change later.
if len(folder_for):
log.info("folders deleted from remote", folders=folder_for.keys())
for name, folder in folder_for.iteritems():
db_session.delete(folder)
# TODO(emfree) delete associated tag
db_session.commit()