本文整理汇总了Python中indico.modules.users.models.links.UserLink.create_link方法的典型用法代码示例。如果您正苦于以下问题:Python UserLink.create_link方法的具体用法?Python UserLink.create_link怎么用?Python UserLink.create_link使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类indico.modules.users.models.links.UserLink
的用法示例。
在下文中一共展示了UserLink.create_link方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: link_to
# 需要导入模块: from indico.modules.users.models.links import UserLink [as 别名]
# 或者: from indico.modules.users.models.links.UserLink import create_link [as 别名]
def link_to(self, obj, role):
"""Adds a link between the user and an object
:param obj: a legacy object
:param role: the role to use in the link
"""
return UserLink.create_link(self, obj, role)
示例2: migrate_links
# 需要导入模块: from indico.modules.users.models.links import UserLink [as 别名]
# 或者: from indico.modules.users.models.links.UserLink import create_link [as 别名]
def migrate_links(self):
print cformat('%{white!}migrating links')
for avatars in grouper(self._iter_avatars(), 2500, skip_missing=True):
avatars = {int(a.id): a for a in avatars}
users = ((u, avatars[u.id]) for u in User.find(User.id.in_(avatars)))
for user, avatar in committing_iterator(self.flushing_iterator(users, 250), 2500):
registrants = set()
user_shown = False
for type_, entries in avatar.linkedTo.iteritems():
# store registrant roles, in order to avoid duplication below
for role, objects in entries.iteritems():
if (type_ == 'category' and role == 'favorite') or type_ == 'group':
continue
if not objects:
continue
if type_ == 'registration' and role == 'registrant':
registrants |= set(objects)
if not user_shown:
print cformat('%{green}+++%{reset} '
'%{white!}{:6d}%{reset} %{cyan}{}%{reset}').format(user.id, user.full_name)
user_shown = True
print cformat('%{blue!}<->%{reset} '
'%{yellow!}{:4d}%{reset}x %{green!}{:12} %{cyan!}{}%{reset}').format(
len(objects), type_, role)
for obj in objects:
try:
UserLink.create_link(user, obj, role, type_)
except Exception as e:
print cformat('%{red!}!!!%{reset} '
'%{red!}linking failed%{reset} (%{yellow!}{}%{reset}): '
'{}').format(unicode(e), obj)
# add old "registrant" entries to registration/registrant
for reg in getattr(avatar, 'registrants', {}).itervalues():
if reg.getConference().getOwner() and reg not in registrants:
UserLink.create_link(user, reg, 'registrant', 'registration')
print cformat('%{cyan!}<->%{reset} '
'%{yellow!} 1%{reset}x %{green!}{:12} %{cyan!}{}%{reset}').format(
'registration', 'registrant')