本文整理汇总了Python中indico.modules.users.models.links.UserLink类的典型用法代码示例。如果您正苦于以下问题:Python UserLink类的具体用法?Python UserLink怎么用?Python UserLink使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserLink类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: unlink_to
def unlink_to(self, obj, role):
"""Removes a link between the user and an object
:param obj: a legacy object
:param role: the role to use in the link
"""
return UserLink.remove_link(self, obj, role)
示例2: link_to
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)
示例3: migrate_links
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')
示例4: get_linked_objects
def get_linked_objects(self, type_, role):
"""Retrieves linked objects for the user"""
return UserLink.get_links(self, type_, role)
示例5: get_linked_roles
def get_linked_roles(self, type_):
"""Retrieves the roles the user is linked to for a given type"""
return UserLink.get_linked_roles(self, type_)