本文整理汇总了Python中app.models.Comment.submitter方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.submitter方法的具体用法?Python Comment.submitter怎么用?Python Comment.submitter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.Comment
的用法示例。
在下文中一共展示了Comment.submitter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_mail
# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import submitter [as 别名]
def import_mail(mail):
# some basic sanity checks
if 'From' not in mail:
return 0
if 'Subject' not in mail:
return 0
if 'Message-Id' not in mail:
return 0
hint = mail.get('X-Patchwork-Hint', '').lower()
if hint == 'ignore':
return 0
header_parser = HeaderParser(mail)
submitter = Submitter.get_or_create(name=header_parser.from_name,
email=header_parser.from_email)
project = find_project(header_parser.project_name)
if project is None:
print 'No project for %s found' % header_parser.project_name
dump_mail(mail, header_parser.message_id)
return 0
try:
content_parser = ContentParser(project, mail)
except:
print 'Email %s is not parsable' % (header_parser.message_id)
dump_mail(mail, header_parser.message_id)
return 0
patch = None
if content_parser.pull_url or content_parser.patch:
subject_parser = SubjectParser(mail.get('Subject'),
[project.linkname])
name = subject_parser.name
tags = find_or_create_tags(subject_parser.tags)
patch = Patch(name=name, pull_url=content_parser.pull_url,
content=content_parser.patch, date=mail_date(mail),
headers=mail_headers(mail), tags=tags)
match = gitsendemail_re.match(header_parser.message_id)
if match:
(uid, num, email) = match.groups()
series = Series.get_or_create(uid)
else:
series = Series.get_or_create(header_parser.message_id)
series.patches.append(patch)
db.session.add(series)
patch.submitter = submitter
patch.msgid = header_parser.message_id
patch.project = project
ancestor = find_ancestor(project, mail, patch)
if ancestor:
patch.ancestors.append(ancestor)
if patch is None:
patch = find_patch_for_mail(project, mail)
if patch is not None:
patch.state = PatchState.comments
comment = None
if content_parser.comment:
if patch is not None:
comment = Comment(patch=patch, date=mail_date(mail),
content=content_parser.comment,
headers=mail_headers(mail))
if patch is not None:
# we delay the saving until we know we have a patch.
db.session.add(patch)
if comment is not None:
# looks like the original constructor for Comment takes the pk
# when the Comment is created. reset it here.
if patch:
comment.patch = patch
comment.submitter = submitter
comment.msgid = header_parser.message_id
db.session.add(comment)
db.session.commit()
return 0
示例2: import_mail
# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import submitter [as 别名]
def import_mail(mail, project_name=None):
# some basic sanity checks
if 'From' not in mail:
return 0
if 'Subject' not in mail:
return 0
if 'Message-Id' not in mail:
return 0
message_id = mail.get('Message-Id').strip()
if Patch.query.filter_by(msgid=message_id).count() or \
Comment.query.filter_by(msgid=message_id).count():
print('We have already imported a message with id "%s"' % message_id)
return
hint = mail.get('X-Patchwork-Hint', '').lower()
if hint == 'ignore':
return 0
header_parser = HeaderParser(mail)
submitter = Submitter.get_or_create(name=header_parser.from_name,
email=header_parser.from_email)
if not project_name:
project_name = header_parser.project_name
project = find_project(project_name)
if project is None:
print 'No project for %s found' % project_name
dump_mail(mail, header_parser.message_id)
return 0
try:
content_parser = ContentParser(project, mail)
except:
print 'Email %s is not parsable' % (header_parser.message_id)
dump_mail(mail, header_parser.message_id)
return 0
patch = None
if content_parser.pull_url or content_parser.patch:
subject_parser = SubjectParser(mail.get('Subject'),
[project.linkname])
name = subject_parser.name
tags = find_or_create_tags(subject_parser.tags)
patch = Patch(name=name, pull_url=content_parser.pull_url,
content=content_parser.patch, date=mail_date(mail),
headers=mail_headers(mail), tags=tags)
match = gitsendemail_re.match(header_parser.message_id)
if match:
(uid, num, email) = match.groups()
series = Series.get_or_create(uid)
else:
series = Series.get_or_create(header_parser.message_id)
series.patches.append(patch)
db.session.add(series)
patch.submitter = submitter
patch.msgid = header_parser.message_id
patch.project = project
ancestor = find_ancestor(project, mail, patch)
if ancestor:
patch.ancestors.append(ancestor)
if patch is None:
patch = find_patch_for_mail(project, mail)
if patch is not None:
patch.state = PatchState.comments
if patch is not None:
db.session.add(patch)
if content_parser.comment and patch is not None:
comment = Comment(patch=patch, date=mail_date(mail),
content=content_parser.comment,
headers=mail_headers(mail))
comment.submitter = submitter
comment.msgid = header_parser.message_id
db.session.add(comment)
db.session.commit()
return 0